diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2015-07-14 16:58:36 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2015-07-14 16:58:36 +0200 |
commit | 7e716fd032235dd574983ab5be8242748d95c7d4 (patch) | |
tree | 65b85be96abd7dbc49dfd224e067071de1219339 /kamon-core/src/main/scala/kamon | |
parent | f20a35447617349828a109c67781d19897e0e8a9 (diff) | |
parent | 7e74030ea824a6b6a561880103f69f3e8e409bba (diff) | |
download | Kamon-7e716fd032235dd574983ab5be8242748d95c7d4.tar.gz Kamon-7e716fd032235dd574983ab5be8242748d95c7d4.tar.bz2 Kamon-7e716fd032235dd574983ab5be8242748d95c7d4.zip |
Merge pull request #223 from jtjeferreira/customTraceTokenGenerator
+ core: kamon.trace.token-generator conf
Diffstat (limited to 'kamon-core/src/main/scala/kamon')
3 files changed, 21 insertions, 11 deletions
diff --git a/kamon-core/src/main/scala/kamon/trace/Sampler.scala b/kamon-core/src/main/scala/kamon/trace/Sampler.scala index 5abba221..ac780d5e 100644 --- a/kamon-core/src/main/scala/kamon/trace/Sampler.scala +++ b/kamon-core/src/main/scala/kamon/trace/Sampler.scala @@ -16,9 +16,14 @@ package kamon.trace +import java.net.InetAddress +import java.util.concurrent.atomic.AtomicLong + import kamon.util.{ NanoInterval, Sequencer } import scala.concurrent.forkjoin.ThreadLocalRandom +import scala.util.Try + trait Sampler { def shouldTrace: Boolean def shouldReport(traceElapsedTime: NanoInterval): Boolean @@ -71,3 +76,12 @@ class ThresholdSampler(thresholdInNanoseconds: Long) extends Sampler { def shouldReport(traceElapsedTime: NanoInterval): Boolean = traceElapsedTime.nanos >= thresholdInNanoseconds } +class DefaultTokenGenerator extends Function0[String] { + private val _hostnamePrefix = Try(InetAddress.getLocalHost.getHostName).getOrElse("unknown-localhost") + private val _tokenCounter = new AtomicLong + + def apply(): String = { + _hostnamePrefix + "-" + String.valueOf(_tokenCounter.incrementAndGet()) + } +} + diff --git a/kamon-core/src/main/scala/kamon/trace/TracerExtensionSettings.scala b/kamon-core/src/main/scala/kamon/trace/TracerExtensionSettings.scala index 6167a007..80f59466 100644 --- a/kamon-core/src/main/scala/kamon/trace/TracerExtensionSettings.scala +++ b/kamon-core/src/main/scala/kamon/trace/TracerExtensionSettings.scala @@ -20,7 +20,7 @@ import java.util.concurrent.TimeUnit import kamon.util.ConfigTools.Syntax import com.typesafe.config.Config -case class TraceSettings(levelOfDetail: LevelOfDetail, sampler: Sampler) +case class TraceSettings(levelOfDetail: LevelOfDetail, sampler: Sampler, tokenGeneratorFQN: String) object TraceSettings { def apply(config: Config): TraceSettings = { @@ -41,6 +41,8 @@ object TraceSettings { case "threshold" ⇒ new ThresholdSampler(tracerConfig.getFiniteDuration("threshold-sampler.minimum-elapsed-time").toNanos) } - TraceSettings(detailLevel, sampler) + val tokenGeneratorFQN = tracerConfig.getString("token-generator") + + TraceSettings(detailLevel, sampler, tokenGeneratorFQN) } }
\ No newline at end of file diff --git a/kamon-core/src/main/scala/kamon/trace/TracerModule.scala b/kamon-core/src/main/scala/kamon/trace/TracerModule.scala index 416af20e..88464a30 100644 --- a/kamon-core/src/main/scala/kamon/trace/TracerModule.scala +++ b/kamon-core/src/main/scala/kamon/trace/TracerModule.scala @@ -16,17 +16,12 @@ package kamon.trace -import java.net.InetAddress -import java.util.concurrent.atomic.AtomicLong - import akka.actor._ import com.typesafe.config.Config import kamon.Kamon import kamon.metric.MetricsModule import kamon.util._ -import scala.util.Try - trait TracerModule { def newContext(name: String): TraceContext def newContext(name: String, token: Option[String]): TraceContext @@ -96,14 +91,13 @@ object Tracer { private[kamon] class TracerModuleImpl(metricsExtension: MetricsModule, config: Config) extends TracerModule { private val _settings = TraceSettings(config) - private val _hostnamePrefix = Try(InetAddress.getLocalHost.getHostName).getOrElse("unknown-localhost") - private val _tokenCounter = new AtomicLong private val _subscriptions = new LazyActorRef private val _incubator = new LazyActorRef + private val _dynamic = new akka.actor.ReflectiveDynamicAccess(getClass.getClassLoader) + private val _tokenGenerator = _dynamic.createInstanceFor[Function0[String]](_settings.tokenGeneratorFQN, Nil).get // let's bubble up any problems. - private def newToken: String = - _hostnamePrefix + "-" + String.valueOf(_tokenCounter.incrementAndGet()) + private def newToken: String = _tokenGenerator() def newContext(name: String): TraceContext = createTraceContext(name, None) |