Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: sibling spans order respects the span start timestamp (#9842)

Muhammed Ajmal M815c60485d7d
diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go
index 0e64566df6..a6ba763813 100644
--- a/pkg/query-service/app/clickhouseReader/reader.go
+++ b/pkg/query-service/app/clickhouseReader/reader.go
@@ -934,6 +934,8 @@ func (r *ClickHouseReader) GetWaterfallSpansForTraceWithMetadata(ctx context.Con
events = append(events, eventMap)
}
+ startTimeUnixNano := uint64(item.TimeUnixNano.UnixNano())
+
jsonItem := model.Span{
SpanID: item.SpanID,
TraceID: item.TraceID,
@@ -949,10 +951,10 @@ func (r *ClickHouseReader) GetWaterfallSpansForTraceWithMetadata(ctx context.Con
Events: events,
TagMap: item.Attributes_string,
Children: make([]*model.Span, 0),
+ TimeUnixNano: startTimeUnixNano, // Store nanoseconds temporarily
}
// metadata calculation
- startTimeUnixNano := uint64(item.TimeUnixNano.UnixNano())
if startTime == 0 || startTimeUnixNano < startTime {
startTime = startTimeUnixNano
}
@@ -967,12 +969,9 @@ func (r *ClickHouseReader) GetWaterfallSpansForTraceWithMetadata(ctx context.Con
totalErrorSpans = totalErrorSpans + 1
}
- // convert start timestamp to millis because right now frontend is expecting it in millis
- jsonItem.TimeUnixNano = uint64(item.TimeUnixNano.UnixNano() / 1000000)
-
// collect the intervals for service for execution time calculation
serviceNameIntervalMap[jsonItem.ServiceName] =
- append(serviceNameIntervalMap[jsonItem.ServiceName], tracedetail.Interval{StartTime: jsonItem.TimeUnixNano, Duration: jsonItem.DurationNano / 1000000, Service: jsonItem.ServiceName})
+ append(serviceNameIntervalMap[jsonItem.ServiceName], tracedetail.Interval{StartTime: jsonItem.TimeUnixNano, Duration: jsonItem.DurationNano, Service: jsonItem.ServiceName})
// append to the span node map
spanIdToSpanNodeMap[jsonItem.SpanID] = &jsonItem
@@ -1050,6 +1049,15 @@ func (r *ClickHouseReader) GetWaterfallSpansForTraceWithMetadata(ctx context.Con
selectedSpans, uncollapsedSpans, rootServiceName, rootServiceEntryPoint := tracedetail.GetSelectedSpans(req.UncollapsedSpans, req.SelectedSpanID, traceRoots, spanIdToSpanNodeMap, req.IsSelectedSpanIDUnCollapsed)
zap.L().Info("getWaterfallSpansForTraceWithMetadata: processing post cache", zap.Duration("duration", time.Since(processingPostCache)), zap.String("traceID", traceID))
+ // convert start timestamp to millis because right now frontend is expecting it in millis
+ for _, span := range selectedSpans {
+ span.TimeUnixNano = span.TimeUnixNano / 1000000
+ }
+
+ for serviceName, totalDuration := range serviceNameToTotalDurationMap {
+ serviceNameToTotalDurationMap[serviceName] = totalDuration / 1000000
+ }
+
response.Spans = selectedSpans
response.UncollapsedSpans = uncollapsedSpans
response.StartTimestampMillis = startTime / 1000000