Skip to content

Commit 5c94499

Browse files
dasheduntitaker
authored andcommitted
fix(apm): Continuation of a trace from another span should use its span id as the parent span id (getsentry#572)
Correction based on what I see on the JS SDK: https://github.com/getsentry/sentry-javascript/blob/01cac4ff6c09d7cf4b5e9d6cf595b095a8d036f3/packages/apm/src/span.ts#L202-L207
1 parent acc3970 commit 5c94499

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

sentry_sdk/tracing.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ def continue_from_headers(cls, headers):
205205
parent = cls.from_traceparent(headers.get("sentry-trace"))
206206
if parent is None:
207207
return cls()
208-
return parent.new_span(same_process_as_parent=False)
208+
parent.same_process_as_parent = False
209+
return parent
209210

210211
def iter_headers(self):
211212
# type: () -> Generator[Tuple[str, str], None, None]
@@ -236,7 +237,7 @@ def from_traceparent(cls, traceparent):
236237
else:
237238
sampled = None
238239

239-
return cls(trace_id=trace_id, span_id=span_id, sampled=sampled)
240+
return cls(trace_id=trace_id, parent_span_id=span_id, sampled=sampled)
240241

241242
def to_traceparent(self):
242243
# type: () -> str

tests/test_tracing.py

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def test_continue_from_headers(sentry_init, capture_events, sampled):
5959
assert span is not None
6060
assert span.sampled == sampled
6161
assert span.trace_id == old_span.trace_id
62+
assert span.same_process_as_parent is False
63+
assert span.parent_span_id == old_span.span_id
64+
assert span.span_id != old_span.span_id
6265

6366
with Hub.current.start_span(span):
6467
with Hub.current.configure_scope() as scope:

0 commit comments

Comments
 (0)