From 6b9beb2f80e53875bca2138e09094f030ac71782 Mon Sep 17 00:00:00 2001 From: Paul Draper Date: Fri, 24 Feb 2017 21:10:40 -0700 Subject: [PATCH] Fix span management --- .../play/active/ActiveTracingFilter.scala | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/play-active/src/main/scala/io/opentracing/play/active/ActiveTracingFilter.scala b/play-active/src/main/scala/io/opentracing/play/active/ActiveTracingFilter.scala index 0b3ea13..3752d6e 100644 --- a/play-active/src/main/scala/io/opentracing/play/active/ActiveTracingFilter.scala +++ b/play-active/src/main/scala/io/opentracing/play/active/ActiveTracingFilter.scala @@ -11,15 +11,16 @@ class ActiveTracingFilter(taggers: Traversable[SpanTagger]) extends BaseTracingF protected[this] def tracer = GlobalTracer.get override def apply(next: EssentialAction) = EssentialAction { request => - val oldManagedSpan = DefaultSpanManager.getInstance.currentSpan() val span = spanBuilder(request).start() val managedSpan = DefaultSpanManager.getInstance.manage(span) - next(request).map { result => - taggers.foreach(_.tag(span, request, result)) - span.finish() + try { + next(request).map { result => + taggers.foreach(_.tag(span, request, result)) + span.finish() + result + } + } finally { managedSpan.release() - DefaultSpanManager.getInstance().manage(oldManagedSpan) - result } } }