fix(streaming): Set segment source if unset#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
- Construct sentry-trace headers manually since StreamedSpan.sampled is always True, making it impossible to vary parent_sampled via real spans - Use context managers for streaming spans so they finish and get sent - Fix sampling condition to match streaming behavior (uses sample_rate/ sample_rand, not parent_sampled directly) - Update span name via span.name instead of scope.transaction - Fix copy-paste errors in DSC test (wrong transaction name, missing URL encoding) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ac2f342 to
d8b7724
Compare
b6e7f84 to
2092b87
Compare
Codecov Results 📊✅ 96032 passed | ❌ 1 failed | ⏭️ 6328 skipped | Total: 102361 | Pass Rate: 93.82% | Execution Time: 335m 28s 📊 Comparison with Base Branch
➕ New Tests (1)View new tests
❌ Failed Tests
|
Description
Set segment source if not set.
Also, add streaming versions of tests in
tracing/test_integration_tests.py.Issues
Part of #5395
Reminders
uv run ruff.feat:,fix:,ref:,meta:)