test: Add streaming integration tests#6791
Conversation
| # 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 |
There was a problem hiding this comment.
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 returnsTrue.StreamedSpan._to_traceparent()(traces.py:503-513) usesself.sampledto set thesampledflag in thesentry-traceheader, soiter_trace_propagation_headers(old_span)always producessampled=1.PropagationContext.from_incoming_data(tracing_utils.py:463) setsparent_sampled = sampled_str != '0', so_parent_sampledwill always beTruewhen reading these headers.- The original
test_continue_trace(line ~120) explicitly doesold_span.sampled = parent_sampledbefore 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 ofsample_ratebecauseparent_sampled=Trueoverrides the sample rate (tracing_utils.py:1574-1575).
Identified by Warden code-review, find-bugs · WE9-4VB
There was a problem hiding this comment.
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_streamingusescapture_envelopes, sotrace1.items[0].payload.jsonis the raw_to_json()output.- The
else-branch of the same test correctly accessestrace1_payload["attributes"]["sentry.segment.name"], confirming the expected format. - The non-streaming counterpart
test_continue_tracecallstrace1.get_transaction_event()which does return a"transaction"key — this is the source of the copy-paste.
Identified by Warden code-review
Description
Will need #6757
Issues
Part of #5395
Reminders
uv run ruff.feat:,fix:,ref:,meta:)