feat: Send GenAI spans as V2 envelope items #6079
2 issues
find-bugs: Found 2 issues (1 high, 1 medium)
High
Wrong variable `event` used instead of `event_opt` causes missing span attributes - `sentry_sdk/client.py:1124-1125`
The _serialized_v1_span_to_serialized_v2_span function is called with event (the raw input) instead of event_opt (the prepared/processed event). The conversion function extracts user info, release, environment, transaction name, trace context, and SDK metadata from the event parameter. Since event_opt is populated by _prepare_event which applies scope data, using the raw event will result in GenAI spans missing important attributes like user.id, sentry.release, sentry.environment, sentry.segment.name, and sentry.sdk.* when these values come from the scope rather than the original event.
Also found at:
sentry_sdk/client.py:124-125
Medium
item_count header may not match actual items due to isinstance filtering - `sentry_sdk/client.py:1118-1128`
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.
Duration: 2m 30s · Tokens: 681.7k in / 7.9k out · Cost: $0.88 (+merge: $0.00, +fix_gate: $0.00)
Annotations
Check failure on line 1125 in sentry_sdk/client.py
sentry-warden / warden: find-bugs
Wrong variable `event` used instead of `event_opt` causes missing span attributes
The `_serialized_v1_span_to_serialized_v2_span` function is called with `event` (the raw input) instead of `event_opt` (the prepared/processed event). The conversion function extracts user info, release, environment, transaction name, trace context, and SDK metadata from the event parameter. Since `event_opt` is populated by `_prepare_event` which applies scope data, using the raw `event` will result in GenAI spans missing important attributes like user.id, sentry.release, sentry.environment, sentry.segment.name, and sentry.sdk.* when these values come from the scope rather than the original event.
Check failure on line 125 in sentry_sdk/client.py
sentry-warden / warden: find-bugs
[M5W-3GS] Wrong variable `event` used instead of `event_opt` causes missing span attributes (additional location)
The `_serialized_v1_span_to_serialized_v2_span` function is called with `event` (the raw input) instead of `event_opt` (the prepared/processed event). The conversion function extracts user info, release, environment, transaction name, trace context, and SDK metadata from the event parameter. Since `event_opt` is populated by `_prepare_event` which applies scope data, using the raw `event` will result in GenAI spans missing important attributes like user.id, sentry.release, sentry.environment, sentry.segment.name, and sentry.sdk.* when these values come from the scope rather than the original event.
Check warning on line 1128 in sentry_sdk/client.py
sentry-warden / warden: find-bugs
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.