Skip to content

fix(pydantic-ai): Capture reasoning and OTEL output messages - #7010

Open
vgrozdanic wants to merge 4 commits into
masterfrom
feat/pydantic-ai-otel-reasoning-output
Open

fix(pydantic-ai): Capture reasoning and OTEL output messages#7010
vgrozdanic wants to merge 4 commits into
masterfrom
feat/pydantic-ai-otel-reasoning-output

Conversation

@vgrozdanic

@vgrozdanic vgrozdanic commented Aug 3, 2026

Copy link
Copy Markdown
Member

Pydantic AI spans now record assistant output only as gen_ai.output.messages (text, reasoning, and tool calls on chat spans; final agent text on invoke_agent). ThinkingPart is surfaced as reasoning in request history and model responses, and provider reasoning token usage is attached when the count is greater than zero.

Deprecated gen_ai.response.text and gen_ai.response.tool_calls are not set. Request message parts keep the existing text key so truncation and consumers of gen_ai.request.messages stay compatible.

Capture ThinkingPart as reasoning, write gen_ai.output.messages on chat
spans, and record provider reasoning token usage. Align request text
parts to content and stop dual-writing deprecated gen_ai.response.text.

Co-Authored-By: opencode <noreply@opencode.ai>
@vgrozdanic vgrozdanic changed the title feat(pydantic-ai): Capture reasoning and OTEL output messages fix(pydantic-ai): Capture reasoning and OTEL output messages Aug 3, 2026
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

95072 passed | ⏭️ 6343 skipped | Total: 101415 | Pass Rate: 93.75% | Execution Time: 338m 57s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +90
Passed Tests 📈 +90
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 93.22%. Project has 2516 uncovered lines.
✅ Project coverage is 89.89%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/pydantic_ai/spans/ai_client.py 91.49% ⚠️ 4 Missing and 7 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.88%    89.89%    +0.01%
==========================================
  Files          193       193         —
  Lines        24834     24876       +42
  Branches      8912      8936       +24
==========================================
+ Hits         22321     22360       +39
- Misses        2513      2516        +3
- Partials      1417      1422        +5

Generated by Codecov Action

Comment thread sentry_sdk/integrations/pydantic_ai/spans/invoke_agent.py Outdated
Comment thread sentry_sdk/integrations/pydantic_ai/spans/ai_client.py Outdated
vgrozdanic and others added 3 commits August 3, 2026 18:32
gen_ai.request.messages text and reasoning parts must use the text key
so truncate_and_annotate_messages still truncates long prompts. Output
messages continue to use content per the OTEL shape.

Co-Authored-By: opencode <noreply@opencode.ai>
Tool calls already live on gen_ai.output.messages; drop the second
attribute on chat spans.

Co-Authored-By: opencode <noreply@opencode.ai>
Stop setting deprecated gen_ai.response.text on invoke_agent spans;
use the OTEL output messages shape instead.

Co-Authored-By: opencode <noreply@opencode.ai>
@vgrozdanic
vgrozdanic marked this pull request as ready for review August 3, 2026 20:03
@vgrozdanic
vgrozdanic requested a review from a team as a code owner August 3, 2026 20:03
output_tokens=50,
details={details_key: 12},
)
_set_usage_data(span, usage)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find a single new test that uses the pydantic-ai package as a user would. All the tests are full of unnecessary mocks.
I want to know that your changes work with pydantic-ai, not some mocks you made up.
In it's current state, it doesn't make sense to review the PR further.

Imports in the middle of function w/o justification, most things Any-typed, old style type annotation which the repo doesn't use anymore should all be removed as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is following existing test patterns, unless you are proposing refactor of all the tests for this package, which is IMO out of the scope for this small bug fix.

If you prefer, I can close this PR, and open an issue in sentry-python to support reasoning and proper tool calls format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants