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.