diff options
Diffstat (limited to 'kamon-core/src/main/scala/kamon/ContextPropagation.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/ContextPropagation.scala | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/kamon-core/src/main/scala/kamon/ContextPropagation.scala b/kamon-core/src/main/scala/kamon/ContextPropagation.scala new file mode 100644 index 00000000..518aa021 --- /dev/null +++ b/kamon-core/src/main/scala/kamon/ContextPropagation.scala @@ -0,0 +1,67 @@ +package kamon + +import com.typesafe.config.Config +import kamon.context.HttpPropagation + +trait ContextPropagation { self: Configuration with ClassLoading => + @volatile private var _propagationComponents: ContextPropagation.Components = _ + @volatile private var _defaultHttpPropagation: HttpPropagation = _ + + // Initial configuration and reconfigures + init(self.config) + self.onReconfigure(newConfig => self.init(newConfig)) + + + /** + * Retrieves the HTTP propagation channel with the supplied name. Propagation channels are configured on the + * kamon.propagation.channels configuration setting. + * + * @param channelName Channel name to retrieve. + * @return The HTTP propagation, if defined. + */ + def httpPropagation(channelName: String): Option[HttpPropagation] = + _propagationComponents.httpChannels.get(channelName) + + /** + * Retrieves the default HTTP propagation channel. Configuration for this channel can be found under the + * kamon.propagation.channels.http configuration setting. + * + * @return The default HTTP propagation. + */ + def defaultHttpPropagation(): HttpPropagation = + _defaultHttpPropagation + + + + private def init(config: Config): Unit = synchronized { + _propagationComponents = ContextPropagation.Components.from(self.config, self) + _defaultHttpPropagation = _propagationComponents.httpChannels(ContextPropagation.DefaultHttpChannel) + } +} + +object ContextPropagation { + val DefaultHttpChannel = "http" + val DefaultBinaryChannel = "binary" + + case class Components( + httpChannels: Map[String, HttpPropagation] + ) + + object Components { + + def from(config: Config, classLoading: ClassLoading): Components = { + val propagationConfig = config.getConfig("kamon.propagation") + val channels = propagationConfig.getConfig("channels").configurations + + val httpChannels = Map.newBuilder[String, HttpPropagation] + + channels.foreach { + case (channelName, channelConfig) => channelConfig.getString("type") match { + case "http" => httpChannels += (channelName -> HttpPropagation.from(channelConfig, classLoading)) + } + } + + Components(httpChannels.result()) + } + } +} |