Skip to content

Instantly share code, notes, and snippets.

@jeroenr
Created August 9, 2017 14:28
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/bd854316fd04de7dcee238686dec3d8e to your computer and use it in GitHub Desktop.
Save jeroenr/bd854316fd04de7dcee238686dec3d8e to your computer and use it in GitHub Desktop.
Trace an async operation with Kamon with OpenTracing support
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