From 05732d8693910248338744fa587bc4bc38ffb1ed Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Sun, 11 Jun 2017 22:45:04 +0200 Subject: add withSpan and withContinuation helper functions --- kamon-core/src/main/scala/kamon/Kamon.scala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'kamon-core') diff --git a/kamon-core/src/main/scala/kamon/Kamon.scala b/kamon-core/src/main/scala/kamon/Kamon.scala index b256cb22..dff143c4 100644 --- a/kamon-core/src/main/scala/kamon/Kamon.scala +++ b/kamon-core/src/main/scala/kamon/Kamon.scala @@ -80,7 +80,21 @@ object Kamon extends MetricLookup with ReporterRegistry with io.opentracing.Trac override def makeActive(span: Span): ActiveSpan = kamonTracer.makeActive(span) - def withActiveSpan[T](continuation: Continuation)(code: => T): T = { + + /** + * Makes the provided Span active before code is evaluated and deactivates it afterwards. + */ + def withSpan[T](span: Span)(code: => T): T = { + val activeSpan = makeActive(span) + val evaluatedCode = code + activeSpan.deactivate() + evaluatedCode + } + + /** + * Actives the provided Continuation before code is evaluated and deactivates it afterwards. + */ + def withContinuation[T](continuation: Continuation)(code: => T): T = { val activeSpan = continuation.activate() val evaluatedCode = code activeSpan.deactivate() -- cgit v1.2.3