diff options
-rw-r--r-- | kamon-core/src/main/scala/kamon/trace/TraceContext.scala | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/kamon-core/src/main/scala/kamon/trace/TraceContext.scala b/kamon-core/src/main/scala/kamon/trace/TraceContext.scala index 6ea30511..a15a4326 100644 --- a/kamon-core/src/main/scala/kamon/trace/TraceContext.scala +++ b/kamon-core/src/main/scala/kamon/trace/TraceContext.scala @@ -26,6 +26,8 @@ import kamon.trace.TraceContextAware.DefaultTraceContextAware import kamon.trace.TraceContext.SegmentIdentity import kamon.metric.TraceMetrics.TraceMetricRecorder +import scala.annotation.tailrec + trait TraceContext { def name: String def token: String @@ -136,10 +138,12 @@ class SimpleMetricCollectionContext(traceName: String, val token: String, metada } } - private def drainFinishedSegments(metricRecorder: TraceMetricRecorder): Unit = { - while (!finishedSegments.isEmpty) { - val segmentData = finishedSegments.poll() - metricRecorder.segmentRecorder(segmentData.identity).record(segmentData.duration) + @tailrec private def drainFinishedSegments(metricRecorder: TraceMetricRecorder): Unit = { + val segment = finishedSegments.poll() + if(segment != null) { + metricRecorder.segmentRecorder(segment.identity).record(segment.duration) + println("CLOSED") + drainFinishedSegments(metricRecorder) } } |