Fix Pydantic AI docs in integration class docstring (Fixes #5293)#5729
Fix Pydantic AI docs in integration class docstring (Fixes #5293)#5729harryautomazione wants to merge 4 commits intogetsentry:masterfrom
Conversation
…mand, parameter name, and attribute - Change install command to include [pydantic_ai] extra - Change result_type to output_type in example - Change result.data to result.output in example This ensures the docstring matches the current Pydantic AI API and correct installation instructions. Fixes getsentry#5293
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛Anthropic
Documentation 📚
Internal Changes 🔧
Other
🤖 This preview updates automatically when you update the PR. |
…gation - Add CURRENT_LANGCHAIN_AGENT_NAME contextvar to track agent name across spans - Set agent name in agent executor wrappers (invoke/stream) - Propagate agent name to all child spans via _create_span - Add test to verify agent name is set on all spans
| finally: | ||
| # Ensure cleanup happens even if iterator is abandoned or fails | ||
| _pop_agent() | ||
| span.__exit__(*exc_info) |
There was a problem hiding this comment.
Bug: Calling CURRENT_LANGCHAIN_AGENT_NAME.reset(token) in the new_iterator_async generator will raise a ValueError because the token was created in a different, synchronous context.
Severity: HIGH
Suggested Fix
The ContextVar token should be set and reset within the same context. Move the CURRENT_LANGCHAIN_AGENT_NAME.set(agent_name) call inside the new_iterator_async generator, so that both setting the variable and resetting it happen within the async generator's context. This will ensure the token is valid when reset() is called in the finally block.
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/langchain.py#L1103
Potential issue: The `token` for the `CURRENT_LANGCHAIN_AGENT_NAME` context variable is
created in the synchronous function `new_stream`. However, the `new_iterator_async`
generator, which runs in a separate, copied context, attempts to reset this token in its
`finally` block. According to Python's context variable specification (PEP 567), calling
`reset()` with a token from a different context raises a `ValueError`. This will cause
any async streaming agent calls to crash during cleanup when the generator is exhausted
or closed. The synchronous version is unaffected as it operates within the same context.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
|
|
||
|
|
||
| def _push_agent(agent_name: "Optional[str]") -> None: | ||
| """Push an agent name onto the stack.""" |
There was a problem hiding this comment.
Stale comment now misleadingly annotates unrelated function
Low Severity
The comment # Contextvar to track agent names in a stack for re-entrant agent support originally documented the _agent_stack ContextVar that was removed in this diff. The comment was left behind and now sits directly above _get_system_instructions, making it look like it describes that unrelated function. This is misleading for anyone reading the code.


What
PydanticAIIntegrationdocstring insentry_sdk/integrations/pydantic_ai/__init__.py.pip install sentry-sdk[pydantic_ai]result_type=SupportResponsetooutput_type=SupportResponseresult.datatoresult.outputWhy
How
PydanticAIIntegrationclass docstring to include:[pydantic_ai])output_typeandresult.outputTesting
pytest tests/integrations/pydantic_ai/test_pydantic_ai.pyRisks / Impact
Checklist
Fixes #5293