diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2017-07-14 14:12:47 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2017-07-14 14:12:47 +0200 |
commit | 34010efc7b273e50d805a277646f14aa96aaa8b2 (patch) | |
tree | 8f7a6f00eac4e0a4cb60c9093b3c5d06ed982662 /kamon-core/src/main/scala/kamon/trace/ActiveSpan.scala | |
parent | 52c4503b6aea2309feeb550b7db2e5fa627dedc8 (diff) | |
download | Kamon-34010efc7b273e50d805a277646f14aa96aaa8b2.tar.gz Kamon-34010efc7b273e50d805a277646f14aa96aaa8b2.tar.bz2 Kamon-34010efc7b273e50d805a277646f14aa96aaa8b2.zip |
wip
Diffstat (limited to 'kamon-core/src/main/scala/kamon/trace/ActiveSpan.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/trace/ActiveSpan.scala | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/kamon-core/src/main/scala/kamon/trace/ActiveSpan.scala b/kamon-core/src/main/scala/kamon/trace/ActiveSpan.scala new file mode 100644 index 00000000..3a46d94f --- /dev/null +++ b/kamon-core/src/main/scala/kamon/trace/ActiveSpan.scala @@ -0,0 +1,70 @@ +package kamon.trace + +/** + * Wraps a [[kamon.trace.Span]] that has been activated in the current Thread. By activated we really mean, it is + * stored in a ThreadLocal value inside the tracer until [[kamon.trace.ActiveSpan#deactivate()]] is called. + * + * When a [[kamon.trace.Span]] is activated it will keep a reference to the previously active Span on the current + * Thread, take it's place as the currently active Span and put the original one once this ActiveSpan gets deactivated. + * + */ +trait ActiveSpan extends Span { + + /** + * Sets the currently active Span to whatever Span was active when this Span was activated. + * + */ + def deactivate(): Unit +} + +object ActiveSpan { + + final class Default(wrappedSpan: Span, restoreOnDeactivate: ActiveSpan, tl: ThreadLocal[ActiveSpan]) + extends ActiveSpan { + + override def deactivate(): Unit = + tl.set(restoreOnDeactivate) + + // + // Forward all other members to the wrapped Span. + // + + override def annotate(annotation: Span.Annotation): Span = + wrappedSpan.annotate(annotation) + + override def addSpanTag(key: String, value: String): Span = + wrappedSpan.addSpanTag(key, value) + + override def addMetricTag(key: String, value: String): Span = + wrappedSpan.addMetricTag(key, value) + + override def addBaggage(key: String, value: String): Span = + wrappedSpan.addBaggage(key, value) + + override def getBaggage(key: String): Option[String] = + wrappedSpan.getBaggage(key) + + override def disableMetricsCollection(): Span = + wrappedSpan.disableMetricsCollection() + + override def context(): SpanContext = + wrappedSpan.context() + + override def setOperationName(operationName: String): Span = + wrappedSpan.setOperationName(operationName) + + override def finish(): Unit = + wrappedSpan.finish() + + override def finish(finishMicros: Long): Unit = + wrappedSpan.finish(finishMicros) + + override def capture(): Continuation = + wrappedSpan.capture() + } + + object Default { + def apply(wrappedSpan: Span, restoreOnDeactivate: ActiveSpan, tl: ThreadLocal[ActiveSpan]): Default = + new Default(wrappedSpan, restoreOnDeactivate, tl) + } +}
\ No newline at end of file |