Skip to content

ref(pydantic-ai): Move pydantic-ai object reads behind an extraction layer - #7194

Draft
ericapisani wants to merge 1 commit into
ep/pydantic-ai-refactor-1-span-helperfrom
ep/pydantic-ai-refactor-2-extract
Draft

ref(pydantic-ai): Move pydantic-ai object reads behind an extraction layer#7194
ericapisani wants to merge 1 commit into
ep/pydantic-ai-refactor-1-span-helperfrom
ep/pydantic-ai-refactor-2-extract

Conversation

@ericapisani

Copy link
Copy Markdown
Member

Description

Issues

Reminders


Stack created with GitHub Stacks CLIGive Feedback 💬

…layer

Introduce _extract.py as the module that concentrates reads of pydantic-ai object internals (private attributes, message part classes, version-dependent shapes) behind typed accessors returning plain data structures. Span modules and patches now consume those accessors, collapsing the duplicated message formatters and blob serializers into one implementation.

Review-driven fixes folded in: response access in extract_response_model_name is now exception-safe (AgentRunResult.response can raise), token usage reporting goes through the shared record_token_usage helper, model-name resolution for the chat span name matches gen_ai.request.model resolution, and unknown model settings are skipped instead of raising KeyError.
@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

111074 passed | ❌ 2 failed | ⏭️ 6759 skipped | Total: 117835 | Pass Rate: 94.26% | Execution Time: 400m 2s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -1387
Passed Tests 📉 -1389
Failed Tests 📈 +2
Skipped Tests

➕ New Tests (1)

View new tests
  • test_binary_content_encoding_mixed_content[False-False]
    • File: tests.integrations.litellm.test_litellm
    • Status: ❌ Failing

❌ Failed Tests

test_binary_content_encoding_mixed_content[False-False]

File: tests.integrations.litellm.test_litellm
Suite: py3.10-litellm-v1.89.7
Error: assert 0 == 1 + where 0 = len([])

Stack Trace
tests/integrations/litellm/test_litellm.py:3128: in test_binary_content_encoding_mixed_content
    assert len(chat_spans) == 1
E   assert 0 == 1
E    +  where 0 = len([])

✅ Patch coverage is 93.75%. Project has 2472 uncovered lines.
✅ Project coverage is 90.26%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
sentry_sdk/integrations/pydantic_ai/_extract.py 92.68% ⚠️ 18 Missing and 27 partials
sentry_sdk/integrations/pydantic_ai/spans/invoke_agent.py 100.00% ⚠️ 1 partials
sentry_sdk/integrations/pydantic_ai/utils.py 100.00% ⚠️ 1 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    90.23%    90.26%    +0.03%
==========================================
  Files          193       194        +1
  Lines        25361     25379       +18
  Branches      9302      9282       -20
==========================================
+ Hits         22883     22907       +24
- Misses        2478      2472        -6
- Partials      1432      1425        -7

Generated by Codecov Action

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant