Created
August 9, 2017 14:28
-
-
Save jeroenr/bd854316fd04de7dcee238686dec3d8e to your computer and use it in GitHub Desktop.
Trace an async operation with 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 traceFuture[T](name: String)(f: => Future[T]): Future[T] = { | |
val spanBuilder = Kamon.tracer.buildSpan("${getClass().getSimpleName}.$name")) | |
val newSpan = addDefaultTags(spanBuilder).start() | |
val activatedSpan = Kamon.makeActive(newSpan) | |
val evaluatedFuture = f.transform( | |
r => { newSpan.finish(); r}, | |
t => { newSpan.finish(); t} | |
)(CallingThreadExecutionContext) | |
activatedSpan.deactivate() | |
evaluatedFuture | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment