Skip to content

test: Add streaming integration tests#6791

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

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

Conversation

@sentrivana

Copy link
Copy Markdown
Contributor

Description

Will need #6757

Issues

Part of #5395

Reminders

Comment thread tests/tracing/test_integration_tests.py
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

Comment on lines +90 to +91
assert span1["attributes"]["sentry.segment.id"] == parent_span["span_id"]
assert span1["attributes"]["sentry.segment.name"] == "hi"

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.

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"] and span2["name"], correctly targeting span2.
  • Lines 90-91 then assert span1["attributes"]["sentry.segment.id"] and span1["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

Comment on lines +399 to +403
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

@sentry-warden sentry-warden Bot Jul 20, 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.

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 %%20 remains two literal percent signs.
  • assert baggage.serialize() == expected_baggage compares against a URL-encoded value that emits single %20.

Identified by Warden code-review, find-bugs · 95K-D3H

Comment on lines +265 to +272
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),
}

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.

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_items fixture (tests/conftest.py:376) stores items as UnwrappedItem where payload = item.payload.json (a dict).
  • The test unpacks trace1, message, trace2 = [item.payload for item in items], so trace2 is a dict, not an envelope.
  • trace2.headers["trace"] on a dict raises AttributeError.
  • The original test_continue_trace (line 179) used capture_envelopes, where trace2 was a full envelope object exposing .headers.

Identified by Warden code-review · EFA-YRW

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