test: Add streaming integration tests#6791
Conversation
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
| assert span1["attributes"]["sentry.segment.id"] == parent_span["span_id"] | ||
| assert span1["attributes"]["sentry.segment.name"] == "hi" |
There was a problem hiding this comment.
span2 segment assertions accidentally check span1
The last two assertions in the span2 block reference span1 instead of span2, so span2's sentry.segment.id/sentry.segment.name attributes are never actually validated.
Evidence
- Lines 88-89 assert
span2["status"]andspan2["name"], correctly targeting span2. - Lines 90-91 then assert
span1["attributes"]["sentry.segment.id"]andspan1["attributes"]["sentry.segment.name"], duplicating the span1 checks at lines 84-85. - span2's segment attributes are therefore never asserted, leaving that edge case uncovered.
Identified by Warden code-review · M3R-3T2
| f"sentry-transaction=Head%%20SDK%%20tx," | ||
| f"sentry-sample_rate={sample_rate}," | ||
| f"sentry-sampled={'true' if segment.sampled else 'false'}" | ||
| ) | ||
| assert baggage.serialize() == expected_baggage |
There was a problem hiding this comment.
expected_baggage uses literal %%20 in f-string context
This value is built with f-strings (no %-formatting applied), so Head%%20SDK%%20tx stays literal and won't match the single-percent Head%20SDK%20tx produced by baggage.serialize(), failing the assertion.
Evidence
- The original non-streaming test at line ~332 uses
%-string formatting (... % (trace_id, sample_rate, ...)), where%%correctly collapses to%. - Here the string is assembled purely from f-strings/plain literals with no
%operator, so%%20remains two literal percent signs. assert baggage.serialize() == expected_baggagecompares against a URL-encoded value that emits single%20.
Identified by Warden code-review, find-bugs · 95K-D3H
| assert trace2.headers["trace"] == baggage.dynamic_sampling_context() | ||
| assert trace2.headers["trace"] == { | ||
| "public_key": "49d0f7386ad645858ae85020e393bef3", | ||
| "trace_id": "771a43a4192642f0b136d5159a501700", | ||
| "user_id": "Amelie", | ||
| "sample_rand": "0.250000", | ||
| "sample_rate": str(sample_rate), | ||
| } |
There was a problem hiding this comment.
trace2.headers access raises AttributeError in streaming test
trace2 is a payload dict from capture_items (item.payload.json), which has no .headers attribute, so this assertion will raise AttributeError instead of testing DSC headers; the envelope/item headers need to be captured separately.
Evidence
capture_itemsfixture (tests/conftest.py:376) stores items asUnwrappedItemwherepayload = item.payload.json(a dict).- The test unpacks
trace1, message, trace2 = [item.payload for item in items], sotrace2is a dict, not an envelope. trace2.headers["trace"]on a dict raisesAttributeError.- The original
test_continue_trace(line 179) usedcapture_envelopes, wheretrace2was a full envelope object exposing.headers.
Identified by Warden code-review · EFA-YRW
Description
Will need #6757
Issues
Part of #5395
Reminders
uv run ruff.feat:,fix:,ref:,meta:)