Skip to content

feat: Send GenAI spans as V2 envelope items#6079

Open
alexander-alderman-webb wants to merge 63 commits into
masterfrom
webb/gen-ai-v2
Open

feat: Send GenAI spans as V2 envelope items#6079
alexander-alderman-webb wants to merge 63 commits into
masterfrom
webb/gen-ai-v2

Conversation

@alexander-alderman-webb
Copy link
Copy Markdown
Contributor

@alexander-alderman-webb alexander-alderman-webb commented Apr 15, 2026

Description

Introduce experimental stream_gen_ai_spans option, aligned with JavaScript: getsentry/sentry-javascript@ad1f373

Convert any child span with an op starting with gen_ai to the V2 span format if the option is enabled.

Send a V2 span container alongside the transaction containing gen_ai spans, if applicable.

Parametrize tests on the new option.

Issues

Reminders

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 15, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (ci) Cancel in-progress PR workflows on new commit push by joshuarli in #5994
  • Send GenAI spans as V2 envelope items by alexander-alderman-webb in #6079
  • Add db.driver.name spans to database integrations by ericapisani in #6082

Bug Fixes 🐛

  • (google_genai) Redact binary data in inline_data and fix multi-part message extraction by ericapisani in #5977
  • (grpc) Add isolation_scope to async server interceptor by robinvd in #5940
  • (profiler) Stop nulling buffer on teardown by ericapisani in #6075

Internal Changes 🔧

  • (celery) Remove unused NoOpMgr from utils by sentrivana in #6078
  • (ci) Update outdated pinned action version comments by JoshuaMoelans in #6088
  • (pydantic-ai) Remove dead Model.request patch by alexander-alderman-webb in #5956
  • (tests) Replace deprecated enable_tracingwith traces_sample_rate by sentrivana in #6077
  • Set explicit base-branch for codecov action by ericapisani in #5992

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 15, 2026

Codecov Results 📊

283 passed | Total: 283 | Pass Rate: 100% | Execution Time: 42.30s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +137
Passed Tests 📈 +137
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 81.38%. Project has 14726 uncovered lines.
✅ Project coverage is 33.65%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
client.py 58.92% ⚠️ 274 Missing and 90 partials
tracing.py 70.82% ⚠️ 145 Missing and 50 partials
_types.py 66.67% ⚠️ 14 Missing
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       +52

Generated by Codecov Action

Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py
Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py Outdated
Comment thread tests/integrations/google_genai/test_google_genai.py Outdated
Comment thread tests/integrations/litellm/test_litellm.py Outdated
Copy link
Copy Markdown
Contributor

@sentry-warden sentry-warden Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tests/integrations/huggingface_hub/test_huggingface_hub.py Outdated
Copy link
Copy Markdown
Contributor

@sentry-warden sentry-warden Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tests/integrations/langgraph/test_langgraph.py
Comment thread sentry_sdk/client.py
Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py
Comment thread tests/integrations/huggingface_hub/test_huggingface_hub.py
@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review May 12, 2026 14:04
@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner May 12, 2026 14:04
Comment thread sentry_sdk/client.py
Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py
Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py
Comment thread sentry_sdk/client.py Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread sentry_sdk/client.py
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