feat: Send GenAI spans as V2 envelope items #6079
2 issues
code-review: Found 2 issues (1 high, 1 medium)
High
Transaction is not captured when all child spans are gen_ai spans - `sentry_sdk/client.py:994-996`
The transaction (root span) is only added to the envelope when nonstreamed_spans is truthy (line 994-996). If all child spans have operations starting with "gen_ai.", nonstreamed_spans will be an empty list and add_transaction() is never called. This causes the entire transaction to be lost - only the gen_ai child spans are sent to Sentry without their parent transaction context.
Medium
Unhandled exception in _v1_span_to_v2 can crash event capture - `sentry_sdk/client.py:80`
The _v1_span_to_v2 function directly accesses span["start_timestamp"] without error handling. If a span has a missing or malformed timestamp (e.g., modified by a before_send_transaction callback), datetime.strptime will raise a ValueError or KeyError. This exception would propagate up and cause the entire transaction capture to fail, potentially losing all spans in the transaction.
Duration: 2m 31s · Tokens: 709.0k in / 7.2k out · Cost: $0.80 (+merge: $0.00, +fix_gate: $0.00)
Annotations
Check failure on line 996 in sentry_sdk/client.py
sentry-warden / warden: code-review
Transaction is not captured when all child spans are gen_ai spans
The transaction (root span) is only added to the envelope when `nonstreamed_spans` is truthy (line 994-996). If all child spans have operations starting with "gen_ai.", `nonstreamed_spans` will be an empty list and `add_transaction()` is never called. This causes the entire transaction to be lost - only the gen_ai child spans are sent to Sentry without their parent transaction context.
Check warning on line 80 in sentry_sdk/client.py
sentry-warden / warden: code-review
Unhandled exception in _v1_span_to_v2 can crash event capture
The `_v1_span_to_v2` function directly accesses `span["start_timestamp"]` without error handling. If a span has a missing or malformed timestamp (e.g., modified by a `before_send_transaction` callback), `datetime.strptime` will raise a `ValueError` or `KeyError`. This exception would propagate up and cause the entire transaction capture to fail, potentially losing all spans in the transaction.