feat: Send GenAI spans as V2 envelope items#6079
feat: Send GenAI spans as V2 envelope items#6079alexander-alderman-webb wants to merge 9 commits intomasterfrom
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 📊✅ 6 passed | Total: 6 | Pass Rate: 100% | Execution Time: 6.52s 📊 Comparison with Base Branch
All tests are passing successfully. ❌ Patch coverage is 19.30%. Project has 16721 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 21.84% 22.05% +0.21%
==========================================
Files 190 190 —
Lines 21351 21452 +101
Branches 7066 7146 +80
==========================================
+ Hits 4662 4731 +69
- Misses 16689 16721 +32
- Partials 379 388 +9Generated by Codecov Action |
| "item_count": len(gen_ai_spans), | ||
| }, | ||
| payload=PayloadRef( | ||
| json={ | ||
| "items": [ | ||
| _serialized_v1_span_to_serialized_v2_span( | ||
| span, event | ||
| ) | ||
| for span in gen_ai_spans | ||
| if isinstance(span, dict) | ||
| ] |
There was a problem hiding this comment.
item_count header may not match actual items due to isinstance filtering
The item_count header is set to len(gen_ai_spans) but the actual items list filters spans with if isinstance(span, dict). If any span in gen_ai_spans is not a dict (e.g., an AnnotatedValue or other type), the header will report more items than are actually present in the payload. This could cause issues with downstream processing that relies on the item_count header being accurate.
Verification
Verified by examining: (1) _split_gen_ai_spans at lines 255-277, which iterates spans and appends to gen_ai_spans list without type checking (it only calls .get() on spans, assuming dict-like behavior); (2) The spans in event_opt["spans"] could potentially contain non-dict types as seen in other parts of the codebase that check for AnnotatedValue. The filtering on line 1127 guards against this but creates a mismatch with the count on line 1118.
Suggested fix: Either filter gen_ai_spans before calculating item_count, or compute item_count from the filtered list.
| "item_count": len(gen_ai_spans), | |
| }, | |
| payload=PayloadRef( | |
| json={ | |
| "items": [ | |
| _serialized_v1_span_to_serialized_v2_span( | |
| span, event | |
| ) | |
| for span in gen_ai_spans | |
| if isinstance(span, dict) | |
| ] | |
| gen_ai_spans = [span for span in gen_ai_spans if isinstance(span, dict)] | |
| span, event_opt |
Identified by Warden find-bugs · BKJ-YKB
Description
Issues
Reminders
tox -e linters.feat:,fix:,ref:,meta:)