feat: Send GenAI spans as V2 envelope items#6079
feat: Send GenAI spans as V2 envelope items#6079alexander-alderman-webb wants to merge 63 commits into
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 283 passed | Total: 283 | Pass Rate: 100% | Execution Time: 42.30s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 81.38%. Project has 14726 uncovered lines. Files with missing lines (3)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 30.12% 33.65% +3.53%
==========================================
Files 190 190 —
Lines 21907 22195 +288
Branches 7818 7512 -306
==========================================
+ Hits 6598 7469 +871
- Misses 15309 14726 -583
- Partials 695 747 +52Generated by Codecov Action |
There was a problem hiding this comment.
Sorting key uses 'name' twice instead of 'name' and 'description' (tests/integrations/google_genai/test_google_genai.py:330)
The sorting lambda in test_generate_content_with_tools was changed from key=lambda t: (t.get("name", ""), t.get("description", "")) to key=lambda t: (t.get("name", ""), t.get("name", "")). This appears to be an accidental duplication error. While this may not break the test currently (since tool names are unique in this test), it defeats the purpose of the secondary sort key and could cause non-deterministic test ordering if tools have the same name but different descriptions.
Orphaned _meta after GenAI spans are split from transaction (tests/integrations/openai/test_openai.py:3758)
In test_openai_message_truncation, the test accesses event["_meta"]["spans"]["0"] to verify truncation metadata for the GenAI span. However, with the V2 envelope changes, GenAI spans are now split out of the transaction via _split_gen_ai_spans() in client.py and sent as separate envelope items. The _meta is generated during serialization (line 848) before the span split occurs (line 1104), leaving orphaned metadata that references a span no longer present in the transaction. The test may pass but validates stale metadata that doesn't correspond to any span in the actual transaction payload.
Identified by Warden find-bugs
There was a problem hiding this comment.
Test assertions check orphaned _meta data after GenAI spans are extracted (tests/integrations/openai/test_openai.py:3756)
After GenAI spans are sent as separate V2 envelope items, the transaction's spans array no longer contains them. However, the test at lines 3757-3760 still asserts against event["_meta"]["spans"]["0"] which contains stale metadata referring to a span that's no longer in the transaction. The _meta path references span index "0" but if all spans were GenAI spans, the transaction's spans array will be empty while _meta["spans"]["0"] still exists from before the split.
Identified by Warden find-bugs
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit dcce855. Configure here.

Description
Introduce experimental
stream_gen_ai_spansoption, aligned with JavaScript: getsentry/sentry-javascript@ad1f373Convert any child span with an
opstarting withgen_aito the V2 span format if the option is enabled.Send a V2 span container alongside the transaction containing
gen_aispans, if applicable.Parametrize tests on the new option.
Issues
Reminders
tox -e linters.feat:,fix:,ref:,meta:)