diff options
Diffstat (limited to 'kamon-core/src/main/scala/kamon/ContextPropagation.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/ContextPropagation.scala | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/kamon-core/src/main/scala/kamon/ContextPropagation.scala b/kamon-core/src/main/scala/kamon/ContextPropagation.scala index bfcfbf7e..8f2ed8e4 100644 --- a/kamon-core/src/main/scala/kamon/ContextPropagation.scala +++ b/kamon-core/src/main/scala/kamon/ContextPropagation.scala @@ -1,11 +1,14 @@ package kamon import com.typesafe.config.Config -import kamon.context.HttpPropagation +import kamon.context.BinaryPropagation.{ByteStreamReader, ByteStreamWriter} +import kamon.context.HttpPropagation.{HeaderReader, HeaderWriter} +import kamon.context.{BinaryPropagation, HttpPropagation, Propagation} trait ContextPropagation { self: Configuration with ClassLoading => @volatile private var _propagationComponents: ContextPropagation.Components = _ - @volatile private var _defaultHttpPropagation: HttpPropagation = _ + @volatile private var _defaultHttpPropagation: Propagation[HeaderReader, HeaderWriter] = _ + @volatile private var _defaultBinaryPropagation: Propagation[ByteStreamReader, ByteStreamWriter] = _ // Initial configuration and reconfigures init(self.config) @@ -14,28 +17,48 @@ trait ContextPropagation { self: Configuration with ClassLoading => /** * Retrieves the HTTP propagation channel with the supplied name. Propagation channels are configured on the - * kamon.propagation.channels configuration setting. + * kamon.propagation.http configuration section. * * @param channelName Channel name to retrieve. - * @return The HTTP propagation, if defined. + * @return The HTTP propagation, if available. */ - def httpPropagation(channelName: String): Option[HttpPropagation] = + def httpPropagation(channelName: String): Option[Propagation[HeaderReader, HeaderWriter]] = _propagationComponents.httpChannels.get(channelName) /** + * Retrieves the binary propagation channel with the supplied name. Propagation channels are configured on the + * kamon.propagation.binary configuration section. + * + * @param channelName Channel name to retrieve. + * @return The binary propagation, if available. + */ + def binaryPropagation(channelName: String): Option[Propagation[ByteStreamReader, ByteStreamWriter]] = + _propagationComponents.binaryChannels.get(channelName) + + /** * Retrieves the default HTTP propagation channel. Configuration for this channel can be found under the - * kamon.propagation.channels.http configuration setting. + * kamon.propagation.http.default configuration section. * * @return The default HTTP propagation. */ - def defaultHttpPropagation(): HttpPropagation = + def defaultHttpPropagation(): Propagation[HeaderReader, HeaderWriter] = _defaultHttpPropagation + /** + * Retrieves the default binary propagation channel. Configuration for this channel can be found under the + * kamon.propagation.binary.default configuration section. + * + * @return The default HTTP propagation. + */ + def defaultBinaryPropagation(): Propagation[ByteStreamReader, ByteStreamWriter] = + _defaultBinaryPropagation + private def init(config: Config): Unit = synchronized { _propagationComponents = ContextPropagation.Components.from(self.config, self) _defaultHttpPropagation = _propagationComponents.httpChannels(ContextPropagation.DefaultHttpChannel) + _defaultBinaryPropagation = _propagationComponents.binaryChannels(ContextPropagation.DefaultBinaryChannel) } } @@ -44,7 +67,8 @@ object ContextPropagation { val DefaultBinaryChannel = "default" case class Components( - httpChannels: Map[String, HttpPropagation] + httpChannels: Map[String, Propagation[HeaderReader, HeaderWriter]], + binaryChannels: Map[String, Propagation[ByteStreamReader, ByteStreamWriter]] ) object Components { @@ -52,11 +76,17 @@ object ContextPropagation { def from(config: Config, classLoading: ClassLoading): Components = { val propagationConfig = config.getConfig("kamon.propagation") val httpChannelsConfig = propagationConfig.getConfig("http").configurations + val binaryChannelsConfig = propagationConfig.getConfig("binary").configurations + val httpChannels = httpChannelsConfig.map { case (channelName, channelConfig) => (channelName -> HttpPropagation.from(channelConfig, classLoading)) } - Components(httpChannels) + val binaryChannels = binaryChannelsConfig.map { + case (channelName, channelConfig) => (channelName -> BinaryPropagation.from(channelConfig, classLoading)) + } + + Components(httpChannels, binaryChannels) } } } |