diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index df59d222f2..735ebd6021 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -130,7 +130,15 @@ def __init__( start_timestamp=None, # type: Optional[datetime] ): # type: (...) -> None - self.trace_id = trace_id or uuid.uuid4().hex + if trace_id: + self.trace_id = trace_id + elif hub: + traceparent = hub.get_traceparent() + if traceparent: + self.trace_id = traceparent.split("-")[0] + if not self.trace_id: + self.trace_id = uuid.uuid4().hex + self.span_id = span_id or uuid.uuid4().hex[16:] self.parent_span_id = parent_span_id self.same_process_as_parent = same_process_as_parent