From 367d3bbebf22710a74855586820e87f5f259486c Mon Sep 17 00:00:00 2001 From: SimunKaracic Date: Tue, 2 Feb 2021 11:45:55 +0100 Subject: [PATCH] Warn on finished span in runWithSpan --- core/kamon-core/src/main/scala/kamon/ContextStorage.scala | 5 +++++ core/kamon-core/src/main/scala/kamon/trace/Span.scala | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/core/kamon-core/src/main/scala/kamon/ContextStorage.scala b/core/kamon-core/src/main/scala/kamon/ContextStorage.scala index 7cebc33fc..625d404b8 100644 --- a/core/kamon-core/src/main/scala/kamon/ContextStorage.scala +++ b/core/kamon-core/src/main/scala/kamon/ContextStorage.scala @@ -18,6 +18,7 @@ package kamon import kamon.context.{Context, Storage} import kamon.trace.Span +import org.slf4j.LoggerFactory import scala.util.control.NonFatal @@ -28,6 +29,7 @@ import scala.util.control.NonFatal trait ContextStorage { import ContextStorage._ + private val log = LoggerFactory.getLogger(classOf[ContextStorage]) /** * Returns the current Context on Kamon's Context Storage. As the default behavior, this will return Context.Empty if * no other Context has been stored on the calling thread. @@ -118,6 +120,9 @@ trait ContextStorage { */ @inline def runWithSpan[T](span: Span, finishSpan: Boolean)(f: => T): T = { try { + if (span.isFinished) { + log.warn(s"Running with a finished span: ${span},${span.operationName()}") + } runWithContextEntry(Span.Key, span)(f) } catch { case NonFatal(t) => diff --git a/core/kamon-core/src/main/scala/kamon/trace/Span.scala b/core/kamon-core/src/main/scala/kamon/trace/Span.scala index f0fe65997..310a5e8c2 100644 --- a/core/kamon-core/src/main/scala/kamon/trace/Span.scala +++ b/core/kamon-core/src/main/scala/kamon/trace/Span.scala @@ -77,6 +77,11 @@ sealed abstract class Span extends Sampler.Operation { */ def trace: Trace + /** + * Returns true if this Span was finished. + */ + def isFinished: Boolean + /** * Returns true if this Span was initially created in another process and then transferred to this process. */ @@ -426,6 +431,7 @@ object Span { override val isRemote: Boolean = false override val isEmpty: Boolean = false + override val isFinished: Boolean = _isOpen override def start(): Delayed = start(clock.instant()) @@ -679,6 +685,7 @@ object Span { override def kind: Kind = Kind.Unknown override def isRemote: Boolean = false override def isEmpty: Boolean = true + override def isFinished: Boolean = false override def position(): Position = Position.Unknown override def tag(key: String, value: String): Span = this override def tag(key: String, value: Long): Span = this @@ -715,6 +722,7 @@ object Span { override def kind: Kind = Kind.Unknown override def isRemote: Boolean = true override def isEmpty: Boolean = false + override def isFinished: Boolean = false override def position(): Position = Position.Unknown override def tag(key: String, value: String): Span = this override def tag(key: String, value: Long): Span = this