Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,12 @@ def generate_propagation_context(self, incoming_data=None):
If there is `incoming_data` overwrite existing propagation context.
If there is no `incoming_data` create new propagation context, but do NOT overwrite if already existing.
"""
if incoming_data:
propagation_context = PropagationContext.from_incoming_data(incoming_data)
if propagation_context is not None:
self._propagation_context = propagation_context
if incoming_data is not None:
self._propagation_context = PropagationContext.from_incoming_data(
incoming_data
)

# TODO-neel this below is a BIG code smell but requires a bunch of other refactoring
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexander-alderman-webb since you wanted me to point out more insights like these, this branch and how it interacts with the get_active_propagation_context method logic is still pretty badly implemented.

if self._type != ScopeType.CURRENT:
if self._propagation_context is None:
self.set_new_propagation_context()
Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,25 +447,25 @@ def __init__(

@classmethod
def from_incoming_data(cls, incoming_data):
# type: (Dict[str, Any]) -> Optional[PropagationContext]
# type: (Dict[str, Any]) -> PropagationContext
propagation_context = PropagationContext()
normalized_data = normalize_incoming_data(incoming_data)

sentry_trace_header = normalized_data.get(SENTRY_TRACE_HEADER_NAME)
sentrytrace_data = extract_sentrytrace_data(sentry_trace_header)

# nothing to propagate if no sentry-trace
if sentrytrace_data is None:
return None
return propagation_context

baggage_header = normalized_data.get(BAGGAGE_HEADER_NAME)
baggage = (
Baggage.from_incoming_header(baggage_header) if baggage_header else None
)

if not _should_continue_trace(baggage):
return None
return propagation_context

propagation_context = PropagationContext()
propagation_context.update(sentrytrace_data)
if baggage:
propagation_context.baggage = baggage
Expand Down
11 changes: 11 additions & 0 deletions tests/tracing/test_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,14 @@ def test_continue_trace_strict_trace_continuation(
)
assert transaction.parent_span_id != "1234567890abcdef"
assert not transaction.parent_sampled


def test_continue_trace_forces_new_traces_when_no_propagation(sentry_init):
"""This is to make sure we don't have a long running trace because of TWP logic for the no propagation case."""

sentry_init(traces_sample_rate=1.0)

tx1 = continue_trace({}, name="tx1")
tx2 = continue_trace({}, name="tx2")

assert tx1.trace_id != tx2.trace_id