feat: Send GenAI spans as V2 envelope items #6079
4 issues
code-review: Found 4 issues (3 medium, 1 low)
Medium
None values stored in attributes dictionary when unsupported types are encountered - `sentry_sdk/client.py:248-250`
The _serialized_v1_attribute_to_serialized_v2_attribute function returns None for unsupported attribute types (line 152), but the calling code in _serialized_v1_span_to_serialized_v2_span (lines 247-250) does not filter these None values before storing them in res["attributes"]. This results in None values being included in the serialized V2 span's attributes dictionary, which may cause issues when the Sentry backend processes these spans. The existing serialize_attribute utility function in utils.py handles this by falling back to a string representation for unknown types.
GenAI span conversion uses unprocessed event instead of event_opt - `sentry_sdk/client.py:1122-1125`
The _serialized_v1_span_to_serialized_v2_span function is called with event (the original unprocessed event) instead of event_opt (the event after _prepare_event processing). The function extracts user attributes, release, environment, SDK info, and trace context from the event. Since scope processing happens in _prepare_event and updates these fields, using the original event may result in missing or incomplete attributes in the serialized V2 spans.
Test uses wrong key 'attributes' instead of 'data' for inline_data - `tests/integrations/google_genai/test_google_genai.py:2153`
The test changed the inline_data dict key from data to attributes, but the actual implementation in transform_google_content_part (sentry_sdk/ai/utils.py:286) expects inline_data.get("data", ""). Other tests in the same file (lines 1765, 1806) correctly use data. This change means the test no longer validates the real inline_data handling path - the content field would be set to an empty string instead of testing the binary data substitution.
Low
Sorting key uses 'name' twice instead of 'name' and 'description' - `tests/integrations/google_genai/test_google_genai.py:330`
The lambda for sorting tools was changed to use t.get("name", "") twice, but the comment explicitly states it should "sort by name and description for comparison". This appears to be a copy-paste error. While the test may pass because the two tools have different names ('get_weather' vs 'get_weather_tool'), this makes the sort less robust and contradicts the documented intent.
Duration: 15m 25s · Tokens: 4.4M in / 56.0k out · Cost: $6.65 (+extraction: $0.01, +merge: $0.00, +fix_gate: $0.01)
Annotations
Check warning on line 250 in sentry_sdk/client.py
sentry-warden / warden: code-review
None values stored in attributes dictionary when unsupported types are encountered
The `_serialized_v1_attribute_to_serialized_v2_attribute` function returns `None` for unsupported attribute types (line 152), but the calling code in `_serialized_v1_span_to_serialized_v2_span` (lines 247-250) does not filter these `None` values before storing them in `res["attributes"]`. This results in `None` values being included in the serialized V2 span's attributes dictionary, which may cause issues when the Sentry backend processes these spans. The existing `serialize_attribute` utility function in `utils.py` handles this by falling back to a string representation for unknown types.
Check warning on line 1125 in sentry_sdk/client.py
sentry-warden / warden: code-review
GenAI span conversion uses unprocessed event instead of event_opt
The `_serialized_v1_span_to_serialized_v2_span` function is called with `event` (the original unprocessed event) instead of `event_opt` (the event after `_prepare_event` processing). The function extracts user attributes, release, environment, SDK info, and trace context from the event. Since scope processing happens in `_prepare_event` and updates these fields, using the original `event` may result in missing or incomplete attributes in the serialized V2 spans.
Check warning on line 2153 in tests/integrations/google_genai/test_google_genai.py
sentry-warden / warden: code-review
Test uses wrong key 'attributes' instead of 'data' for inline_data
The test changed the inline_data dict key from `data` to `attributes`, but the actual implementation in `transform_google_content_part` (sentry_sdk/ai/utils.py:286) expects `inline_data.get("data", "")`. Other tests in the same file (lines 1765, 1806) correctly use `data`. This change means the test no longer validates the real inline_data handling path - the `content` field would be set to an empty string instead of testing the binary data substitution.