Skip to content

Commit 80ba8fb

Browse files
authored
Cleanup PropagationContext.from_incoming_data (#5155)
### Description I'm cleaning up the `PropagationContext`/`continue_trace` flow like I did on `potel-base`. The early return now makes sure that the `incoming_data` only matters when we have a `sentry-trace` first and foremost and avoids the multiple `PropagationContext` instantiations.
1 parent ab0103e commit 80ba8fb

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

sentry_sdk/tracing_utils.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -444,26 +444,23 @@ def __init__(
444444
@classmethod
445445
def from_incoming_data(cls, incoming_data):
446446
# type: (Dict[str, Any]) -> Optional[PropagationContext]
447-
propagation_context = None
448-
449447
normalized_data = normalize_incoming_data(incoming_data)
448+
449+
sentry_trace_header = normalized_data.get(SENTRY_TRACE_HEADER_NAME)
450+
sentrytrace_data = extract_sentrytrace_data(sentry_trace_header)
451+
if sentrytrace_data is None:
452+
return None
453+
454+
propagation_context = PropagationContext()
455+
propagation_context.update(sentrytrace_data)
456+
450457
baggage_header = normalized_data.get(BAGGAGE_HEADER_NAME)
451458
if baggage_header:
452-
propagation_context = PropagationContext()
453459
propagation_context.dynamic_sampling_context = Baggage.from_incoming_header(
454460
baggage_header
455461
).dynamic_sampling_context()
456462

457-
sentry_trace_header = normalized_data.get(SENTRY_TRACE_HEADER_NAME)
458-
if sentry_trace_header:
459-
sentrytrace_data = extract_sentrytrace_data(sentry_trace_header)
460-
if sentrytrace_data is not None:
461-
if propagation_context is None:
462-
propagation_context = PropagationContext()
463-
propagation_context.update(sentrytrace_data)
464-
465-
if propagation_context is not None:
466-
propagation_context._fill_sample_rand()
463+
propagation_context._fill_sample_rand()
467464

468465
return propagation_context
469466

0 commit comments

Comments
 (0)