Conversation
…GEN_AI spans under an invoke_agent span
There was a problem hiding this comment.
Bug: Agent Name Missing in Async Non-Streaming Wrapper
The _wrap_async_generate_content function is missing the line that sets SPANDATA.GEN_AI_AGENT_NAME on the chat_span. This line was added to the other three wrapper functions (_wrap_generate_content_stream, _wrap_async_generate_content_stream, and _wrap_generate_content), but was not added here. This causes the async non-streaming variant to be inconsistent with the other implementations and fails to meet the PR's goal of ensuring agent name is set on all gen_ai children.
sentry_sdk/integrations/google_genai/__init__.py#L257-L301
sentry-python/sentry_sdk/integrations/google_genai/__init__.py
Lines 257 to 301 in 0e23407
| chat_span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "chat") | ||
| chat_span.set_data(SPANDATA.GEN_AI_SYSTEM, GEN_AI_SYSTEM) | ||
| chat_span.set_data(SPANDATA.GEN_AI_REQUEST_MODEL, model_name) | ||
| chat_span.set_data(SPANDATA.GEN_AI_AGENT_NAME, model_name) | ||
| set_span_data_for_request( | ||
| chat_span, integration, model_name, contents, kwargs | ||
| ) |
There was a problem hiding this comment.
Bug: _wrap_async_generate_content omits setting SPANDATA.GEN_AI_AGENT_NAME on the chat span.
Severity: HIGH | Confidence: 1.00
🔍 Detailed Analysis
The _wrap_async_generate_content function fails to set the SPANDATA.GEN_AI_AGENT_NAME on the chat span. This omission occurs when handling async non-streaming generate_content calls, leading to inconsistent span data compared to other wrapper functions which correctly set this attribute. Consequently, monitoring attributes for these specific calls will be incomplete.
💡 Suggested Fix
Add chat_span.set_data(SPANDATA.GEN_AI_AGENT_NAME, model_name) within the _wrap_async_generate_content function, specifically after setting SPANDATA.GEN_AI_REQUEST_MODEL.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: sentry_sdk/integrations/google_genai/__init__.py#L235-L241
Potential issue: The `_wrap_async_generate_content` function fails to set the
`SPANDATA.GEN_AI_AGENT_NAME` on the chat span. This omission occurs when handling async
non-streaming `generate_content` calls, leading to inconsistent span data compared to
other wrapper functions which correctly set this attribute. Consequently, monitoring
attributes for these specific calls will be incomplete.
Did we get this right? 👍 / 👎 to inform future reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5038 +/- ##
==========================================
+ Coverage 83.93% 83.96% +0.03%
==========================================
Files 179 179
Lines 17887 17890 +3
Branches 3181 3181
==========================================
+ Hits 15014 15022 +8
+ Misses 1908 1902 -6
- Partials 965 966 +1
|
### Description Cherry-picked off of #5030 #### Issues Ref https://linear.app/getsentry/issue/TET-1293/make-sure-that-agent-name-is-set-on-all-of-its-gen-ai-children #### Reminders - Please add tests to validate your changes, and lint your code using `tox -e linters`. - Add GH Issue ID _&_ Linear ID (if applicable) - PR title should use [conventional commit](https://develop.sentry.dev/engineering-practices/commit-messages/#type) style (`feat:`, `fix:`, `ref:`, `meta:`) - For external contributors: [CONTRIBUTING.md](https://github.com/getsentry/sentry-python/blob/master/CONTRIBUTING.md), [Sentry SDK development docs](https://develop.sentry.dev/sdk/), [Discord community](https://discord.gg/Ww9hbqr) --------- Co-authored-by: Fabian Schindler <fabian.schindler@sentry.io>
Description
Cherry-picked off of #5030
Issues
Ref https://linear.app/getsentry/issue/TET-1293/make-sure-that-agent-name-is-set-on-all-of-its-gen-ai-children
Reminders
tox -e linters.feat:,fix:,ref:,meta:)