Skip to content

test: Add streaming integration tests#6791

Draft
sentrivana wants to merge 2 commits into
masterfrom
ivana/streaming-integration-tests
Draft

test: Add streaming integration tests#6791
sentrivana wants to merge 2 commits into
masterfrom
ivana/streaming-integration-tests

Conversation

@sentrivana

Copy link
Copy Markdown
Contributor

Description

Will need #6757

Issues

Part of #5395

Reminders

# child segment, to prove that we can read 'sentry-trace' header data correctly
sentry_sdk.traces.continue_trace(headers)
child_segment = sentry_sdk.traces.start_span(name="WRONG")
assert child_segment is not None

@sentry-warden sentry-warden Bot Jul 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

parent_sampled parameter never applied to headers, making assertions always fail for False/None cases

Unlike the original test_continue_trace which sets old_span.sampled = parent_sampled before capturing headers, this test never applies the parent_sampled parameter — so the sentry-trace header always reflects the actual span's sampling decision rather than the parametrized value. Because StreamedSpan.sampled always returns True, the header will always carry sampled=1, meaning child_segment._parent_sampled will always be True and the assertion assert child_segment._parent_sampled == parent_sampled will fail for every parent_sampled=False and parent_sampled=None combination.

Evidence
  • StreamedSpan.sampled (traces.py:477-478) is a property that unconditionally returns True.
  • StreamedSpan._to_traceparent() (traces.py:503-513) uses self.sampled to set the sampled flag in the sentry-trace header, so iter_trace_propagation_headers(old_span) always produces sampled=1.
  • PropagationContext.from_incoming_data (tracing_utils.py:463) sets parent_sampled = sampled_str != '0', so _parent_sampled will always be True when reading these headers.
  • The original test_continue_trace (line ~120) explicitly does old_span.sampled = parent_sampled before generating headers to inject the parametrized value; this new test has no equivalent step.
  • The downstream envelope-count branch if parent_sampled is False or (sample_rate == 0 and parent_sampled is None) is also affected: the child segment will always be sampled regardless of sample_rate because parent_sampled=True overrides the sample rate (tracing_utils.py:1574-1575).

Identified by Warden code-review, find-bugs · WE9-4VB

Comment thread tests/tracing/test_integration_tests.py

@sentry-warden sentry-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Streaming span payload accessed with wrong key "transaction" instead of attributes["sentry.segment.name"]

In test_continue_trace_span_streaming, the falsy-branch asserts trace1_payload["transaction"] == "hi", but streaming span envelopes use the _to_json() format which has "name", not "transaction". The else-branch of the same test correctly uses trace1_payload["attributes"]["sentry.segment.name"], making the falsy-branch a copy-paste error that will raise KeyError at runtime.

Evidence
  • StreamedSpan._to_json() (traces.py:592) produces a dict with keys "name", "trace_id", "attributes", etc., but no top-level "transaction" key.
  • test_continue_trace_span_streaming uses capture_envelopes, so trace1.items[0].payload.json is the raw _to_json() output.
  • The else-branch of the same test correctly accesses trace1_payload["attributes"]["sentry.segment.name"], confirming the expected format.
  • The non-streaming counterpart test_continue_trace calls trace1.get_transaction_event() which does return a "transaction" key — this is the source of the copy-paste.

Identified by Warden code-review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant