Skip to content

Commit

Permalink
Warn on finished span in runWithSpan
Browse files Browse the repository at this point in the history
  • Loading branch information
SimunKaracic committed Feb 2, 2021
1 parent 28cdeac commit 367d3bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/kamon-core/src/main/scala/kamon/ContextStorage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package kamon

import kamon.context.{Context, Storage}
import kamon.trace.Span
import org.slf4j.LoggerFactory

import scala.util.control.NonFatal

Expand All @@ -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.
Expand Down Expand Up @@ -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) =>
Expand Down
8 changes: 8 additions & 0 deletions core/kamon-core/src/main/scala/kamon/trace/Span.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 367d3bb

Please sign in to comment.