From 12d68acb3b96712149d0eb5a0f6f3d981d2970ce Mon Sep 17 00:00:00 2001 From: Roch Devost Date: Thu, 25 Apr 2024 19:17:29 +0200 Subject: [PATCH] fix invalid parent index on segment reset --- packages/dd-trace/src/collector/span.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/dd-trace/src/collector/span.js b/packages/dd-trace/src/collector/span.js index 6ccf2702800..bb7a0587f89 100644 --- a/packages/dd-trace/src/collector/span.js +++ b/packages/dd-trace/src/collector/span.js @@ -52,7 +52,7 @@ class DatadogCollectorSpan extends DatadogSpan { spanContext._spanIndex = trace.lastIndex++ - if (fields.parent) { + if (parent && trace.segmentId === parent.segmentId) { spanContext._parentIndex = parent._spanIndex >= 0 ? parent._spanIndex + 1 : 0 @@ -98,7 +98,7 @@ class DatadogCollectorSpan extends DatadogSpan { } else { const traceId = spanContext._traceId const parentId = spanContext._parentId - const time = trace.startTime + const time = trace.startTime // TODO: update time on new segment trace.active = 1 trace.lastIndex = 0 @@ -106,6 +106,8 @@ class DatadogCollectorSpan extends DatadogSpan { startSegmentChannel.publish({ parentId, segmentId, time, traceId }) } + + spanContext.segmentId = trace.segmentId } _initContext (props) {