diff options
Diffstat (limited to 'kamon-core/src/main')
-rw-r--r-- | kamon-core/src/main/scala/kamon/trace/Sampler.scala | 7 | ||||
-rw-r--r-- | kamon-core/src/main/scala/kamon/util/Sequencer.scala | 2 |
2 files changed, 5 insertions, 4 deletions
diff --git a/kamon-core/src/main/scala/kamon/trace/Sampler.scala b/kamon-core/src/main/scala/kamon/trace/Sampler.scala index 650592a5..5e6bef89 100644 --- a/kamon-core/src/main/scala/kamon/trace/Sampler.scala +++ b/kamon-core/src/main/scala/kamon/trace/Sampler.scala @@ -3,6 +3,7 @@ package kamon.trace import java.util.concurrent.atomic.AtomicLong import kamon.NanoInterval +import kamon.util.Sequencer import scala.concurrent.forkjoin.ThreadLocalRandom trait Sampler { @@ -31,9 +32,9 @@ class RandomSampler(chance: Int) extends Sampler { class OrderedSampler(interval: Int) extends Sampler { require(interval > 0, "kamon.trace.ordered-sampler.interval cannot be <= 0") - private val counter = new AtomicLong(0L) - def shouldTrace: Boolean = counter.incrementAndGet() % interval == 0 - // TODO: find a more efficient way to do this, protect from long overflow. + private val sequencer = Sequencer() + + def shouldTrace: Boolean = sequencer.next() % interval == 0 def shouldReport(traceElapsedTime: NanoInterval): Boolean = true } diff --git a/kamon-core/src/main/scala/kamon/util/Sequencer.scala b/kamon-core/src/main/scala/kamon/util/Sequencer.scala index 8901ba81..f368e54f 100644 --- a/kamon-core/src/main/scala/kamon/util/Sequencer.scala +++ b/kamon-core/src/main/scala/kamon/util/Sequencer.scala @@ -18,7 +18,7 @@ package kamon.util /** * This class implements an extremely efficient, thread-safe way to generate a - * simple incrementing sequence of Longs with a simple Long overflow protection. + * incrementing sequence of Longs with a simple Long overflow protection. */ class Sequencer { private val CloseToOverflow = Long.MaxValue - 1000000000 |