Created
August 9, 2017 14:18
-
-
Save jeroenr/55a0668ef7b4143b3e222983c0f39934 to your computer and use it in GitHub Desktop.
Trace a block of code in Kamon with OpenTracing support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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