Skip to content

Commit

Permalink
Take trace id always from propagation context (#2209)
Browse files Browse the repository at this point in the history
Make sure that the trace information is always taken from propagation context. (was not the case if you create a span without a transaction, which is happening if you have a vanilla Python without any Integrations and you make an outgoing HTTP request)
  • Loading branch information
antonpirker committed Jul 4, 2023
1 parent acb504b commit 7113508
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,13 @@ def start_span(self, span=None, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
if span is not None:
return span.start_child(**kwargs)

# If there is already a trace_id in the propagation context, use it.
if "trace_id" not in kwargs:
traceparent = self.get_traceparent()
trace_id = traceparent.split("-")[0] if traceparent else None
if trace_id is not None:
kwargs["trace_id"] = trace_id

return Span(**kwargs)

def start_transaction(
Expand Down

0 comments on commit 7113508

Please sign in to comment.