Skip to content

Instantly share code, notes, and snippets.

@jeroenr
Created August 9, 2017 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroenr/55a0668ef7b4143b3e222983c0f39934 to your computer and use it in GitHub Desktop.
Save jeroenr/55a0668ef7b4143b3e222983c0f39934 to your computer and use it in GitHub Desktop.
Trace a block of code in Kamon with OpenTracing support
def traceBlock[T](name: String, parentSpanContext: Option[SpanContext] = None)(f: => T): T = {
val spanBuilder = Kamon.tracer.buildSpan(s"${getClass().getSimpleName}.$name")
val newSpan = addDefaultTags(spanBuilder).asChildOf(parentSpanContext).start()
val activatedSpan = Kamon.makeActive(newSpan)
try {
f
} finally {
activatedSpan.deactivate()
newSpan.finish()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment