From d12fe28c5d3dd2f00384fd38b3c028e9da240ca9 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Fri, 23 Sep 2022 13:46:49 +0530 Subject: [PATCH] fix: skip spans with negative duration (#16) --- processor/signozspanmetricsprocessor/processor.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/processor/signozspanmetricsprocessor/processor.go b/processor/signozspanmetricsprocessor/processor.go index 7709ecba..2b060147 100644 --- a/processor/signozspanmetricsprocessor/processor.go +++ b/processor/signozspanmetricsprocessor/processor.go @@ -591,6 +591,13 @@ func getRemoteAddress(span ptrace.Span) (string, bool) { } func (p *processorImp) aggregateMetricsForSpan(serviceName string, span ptrace.Span, resourceAttr pcommon.Map) { + + // Ideally shouldn't happen but if for some reason span end time is before start time, + // ignore the span. We don't want to count negative latency. + if span.EndTimestamp() < span.StartTimestamp() { + return + } + latencyInMilliseconds := float64(span.EndTimestamp()-span.StartTimestamp()) / float64(time.Millisecond.Nanoseconds()) // Binary search to find the latencyInMilliseconds bucket index.