diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2014-10-26 02:21:11 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-10-26 02:21:11 +0200 |
commit | cd8dce169b4231bf533445656bfb5a35034a6304 (patch) | |
tree | 4561bf3b8b7890891990a0d1b500155975d54277 /kamon-core/src/main/scala | |
parent | ea1a0d5d76988992227eb30b0baaf8e97678c946 (diff) | |
download | Kamon-cd8dce169b4231bf533445656bfb5a35034a6304.tar.gz Kamon-cd8dce169b4231bf533445656bfb5a35034a6304.tar.bz2 Kamon-cd8dce169b4231bf533445656bfb5a35034a6304.zip |
= all: upgrade to be compatible with the latest code in core
Diffstat (limited to 'kamon-core/src/main/scala')
3 files changed, 27 insertions, 15 deletions
diff --git a/kamon-core/src/main/scala/kamon/metric/TraceMetrics.scala b/kamon-core/src/main/scala/kamon/metric/TraceMetrics.scala index 54626b6c..7246ccb5 100644 --- a/kamon-core/src/main/scala/kamon/metric/TraceMetrics.scala +++ b/kamon-core/src/main/scala/kamon/metric/TraceMetrics.scala @@ -30,7 +30,6 @@ object TraceMetrics extends MetricGroupCategory { val name = "trace" case object ElapsedTime extends MetricIdentity { val name = "elapsed-time" } - case class HttpClientRequest(name: String) extends MetricIdentity case class TraceMetricRecorder(elapsedTime: Histogram, private val segmentRecorderFactory: () ⇒ Histogram) extends MetricGroupRecorder { diff --git a/kamon-core/src/main/scala/kamon/trace/TraceContext.scala b/kamon-core/src/main/scala/kamon/trace/TraceContext.scala index a5855308..08289acf 100644 --- a/kamon-core/src/main/scala/kamon/trace/TraceContext.scala +++ b/kamon-core/src/main/scala/kamon/trace/TraceContext.scala @@ -35,7 +35,9 @@ sealed trait TraceContext { def origin: TraceContextOrigin def isOpen: Boolean def isEmpty: Boolean + def nonEmpty: Boolean = !isEmpty def startSegment(segmentName: String, label: String): Segment + def nanoTimestamp: Long } sealed trait Segment { @@ -43,6 +45,7 @@ sealed trait Segment { def rename(newName: String): Unit def label: String def finish(): Unit + def isEmpty: Boolean } case object EmptyTraceContext extends TraceContext { @@ -54,23 +57,25 @@ case object EmptyTraceContext extends TraceContext { def isOpen: Boolean = false def isEmpty: Boolean = true def startSegment(segmentName: String, label: String): Segment = EmptySegment + def nanoTimestamp: Long = 0L case object EmptySegment extends Segment { val name: String = "empty-segment" val label: String = "empty-label" + def isEmpty: Boolean = true def rename(newName: String): Unit = {} def finish: Unit = {} } } class DefaultTraceContext(traceName: String, val token: String, izOpen: Boolean, val levelOfDetail: LevelOfDetail, - val origin: TraceContextOrigin, startNanoTime: Long)(implicit system: ActorSystem) extends TraceContext { + val origin: TraceContextOrigin, nanoTimeztamp: Long, val system: ActorSystem) extends TraceContext { val isEmpty: Boolean = false @volatile private var _name = traceName @volatile private var _isOpen = izOpen - private val _startNanoTime = startNanoTime + private val _nanoTimestamp = nanoTimeztamp private val finishedSegments = new ConcurrentLinkedQueue[SegmentData]() private val metricsExtension = Kamon(Metrics)(system) private[kamon] val traceLocalStorage: TraceLocalStorage = new TraceLocalStorage @@ -80,10 +85,11 @@ class DefaultTraceContext(traceName: String, val token: String, izOpen: Boolean, if (isOpen) _name = newName // TODO: log a warning about renaming a closed trace. def isOpen: Boolean = _isOpen + def nanoTimestamp: Long = _nanoTimestamp def finish(): Unit = { _isOpen = false - val elapsedNanoTime = System.nanoTime() - _startNanoTime + val elapsedNanoTime = System.nanoTime() - _nanoTimestamp val metricRecorder = metricsExtension.register(TraceMetrics(name), TraceMetrics.Factory) metricRecorder.map { traceMetrics ⇒ @@ -119,6 +125,7 @@ class DefaultTraceContext(traceName: String, val token: String, izOpen: Boolean, def name: String = _segmentName def rename(newName: String): Unit = _segmentName = newName + def isEmpty: Boolean = false def finish: Unit = { val segmentFinishNanoTime = System.nanoTime() diff --git a/kamon-core/src/main/scala/kamon/trace/TraceRecorder.scala b/kamon-core/src/main/scala/kamon/trace/TraceRecorder.scala index 9b0ba038..8da187cb 100644 --- a/kamon-core/src/main/scala/kamon/trace/TraceRecorder.scala +++ b/kamon-core/src/main/scala/kamon/trace/TraceRecorder.scala @@ -36,23 +36,25 @@ object TraceRecorder { private def newTraceContext(name: String, token: Option[String], system: ActorSystem): TraceContext = { new DefaultTraceContext( - name, token.getOrElse(newToken), + name, + token.getOrElse(newToken), izOpen = true, LevelOfDetail.OnlyMetrics, TraceContextOrigin.Local, - startNanoTime = System.nanoTime)(system) + nanoTimeztamp = System.nanoTime, + system) } def joinRemoteTraceContext(traceName: String, traceToken: String, startMilliTime: Long, isOpen: Boolean, system: ActorSystem): TraceContext = { - /*new SimpleMetricCollectionContext( + val equivalentNanotime = System.nanoTime() - ((System.currentTimeMillis() - startMilliTime) * 1000000) + new DefaultTraceContext( traceName, traceToken, - Map.empty, + isOpen, + LevelOfDetail.OnlyMetrics, TraceContextOrigin.Remote, - system, - startMilliTime, - isOpen)*/ - ??? + equivalentNanotime, + system) } def setContext(context: TraceContext): Unit = traceContextStorage.set(context) @@ -61,10 +63,9 @@ object TraceRecorder { def currentContext: TraceContext = traceContextStorage.get() - // TODO: Remove this method. def start(name: String, token: Option[String] = None)(implicit system: ActorSystem) = { - //val ctx = newTraceContext(name, token, metadata, system) - //traceContextStorage.set(Some(ctx)) + val ctx = newTraceContext(name, token, system) + traceContextStorage.set(ctx) } def rename(name: String): Unit = currentContext.rename(name) @@ -79,6 +80,11 @@ object TraceRecorder { try thunk finally setContext(oldContext) } + def withTraceContextAndSystem[T](thunk: (TraceContext, ActorSystem) ⇒ T): Option[T] = currentContext match { + case ctx: DefaultTraceContext ⇒ Some(thunk(ctx, ctx.system)) + case EmptyTraceContext ⇒ None + } + def withInlineTraceContextReplacement[T](traceCtx: TraceContext)(thunk: ⇒ T): T = macro InlineTraceContextMacro.withInlineTraceContextImpl[T, TraceContext] def finish(): Unit = currentContext.finish() |