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/trace/Sampler.scala | |
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/trace/Sampler.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/trace/Sampler.scala | 14 |
1 files changed, 14 insertions, 0 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()) + } +} + |