Skip to content

feat(pydantic-ai): Support span streaming#6389

Merged
alexander-alderman-webb merged 14 commits into
masterfrom
webb/pydantic-ai/span-first
May 22, 2026
Merged

feat(pydantic-ai): Support span streaming#6389
alexander-alderman-webb merged 14 commits into
masterfrom
webb/pydantic-ai/span-first

Conversation

@alexander-alderman-webb
Copy link
Copy Markdown
Contributor

@alexander-alderman-webb alexander-alderman-webb commented May 22, 2026

Description

Use sentry_sdk.traces.start_span and replace Span.set_data() with StreamedSpan.set_attribute() when in span streaming mode.

Parametrize tests on the trace lifecycle option.

Issues

Closes #6046

Reminders

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Codecov Results 📊

282 passed | Total: 282 | Pass Rate: 100% | Execution Time: 43.34s

All tests are passing successfully.

❌ Patch coverage is 0.00%. Project has 14753 uncovered lines.

Files with missing lines (6)
File Patch % Lines
ai_client.py 0.00% ⚠️ 156 Missing
utils.py 0.00% ⚠️ 107 Missing
agent_run.py 0.00% ⚠️ 86 Missing
invoke_agent.py 0.00% ⚠️ 82 Missing
execute_tool.py 0.00% ⚠️ 31 Missing
utils.py 0.00% ⚠️ 29 Missing

Generated by Codecov Action

Copy link
Copy Markdown
Contributor

@sentry-warden sentry-warden Bot left a comment

Choose a reason for hiding this comment

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

update_invoke_agent_span silently drops GEN_AI_RESPONSE_MODEL in span streaming mode

In sentry_sdk/integrations/pydantic_ai/spans/invoke_agent.py, update_invoke_agent_span calls span.set_data() unconditionally, but StreamedSpan only has set_attribute() — the resulting AttributeError is swallowed by the surrounding except Exception, so the response model name is silently never set when span streaming is enabled.

Evidence
  • StreamedSpan (defined in sentry_sdk/traces.py:227) has set_attribute/set_attributes but no set_data method (confirmed via grep).
  • update_invoke_agent_span calls span.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, response.model_name) at invoke_agent.py:168 without an isinstance(span, StreamedSpan) guard.
  • The call is wrapped in try/except Exception, so the AttributeError is silently eaten.
  • ai_client_span and execute_tool_span in the same PR both correctly use isinstance(span, StreamedSpan) checks (e.g., execute_tool.py:update_execute_tool_span).
  • The new parametrized tests added in the hunk check gen_ai.chat and gen_ai.execute_tool spans but not the invoke_agent span's GEN_AI_RESPONSE_MODEL attribute, so this regression goes undetected.

Identified by Warden code-review

Comment thread sentry_sdk/integrations/pydantic_ai/spans/invoke_agent.py
Comment thread tests/integrations/pydantic_ai/test_pydantic_ai.py Outdated
Comment thread tests/integrations/pydantic_ai/test_pydantic_ai.py Outdated
@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review May 22, 2026 10:45
@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner May 22, 2026 10:45
Copy link
Copy Markdown
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

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

Looks good, small improvement suggestions in tests

Comment thread tests/integrations/pydantic_ai/test_pydantic_ai.py Outdated
Comment thread tests/integrations/pydantic_ai/test_pydantic_ai.py Outdated
Comment thread tests/integrations/pydantic_ai/test_pydantic_ai.py Outdated
Comment thread tests/integrations/pydantic_ai/test_pydantic_ai.py Outdated
Comment thread tests/integrations/pydantic_ai/test_pydantic_ai.py Outdated
Comment thread tests/integrations/pydantic_ai/test_pydantic_ai.py Outdated
Comment thread tests/integrations/pydantic_ai/test_pydantic_ai.py Outdated
Comment thread tests/integrations/pydantic_ai/test_pydantic_ai.py Outdated
Comment thread tests/integrations/pydantic_ai/test_pydantic_ai.py Outdated
Comment thread tests/integrations/pydantic_ai/test_pydantic_ai.py Outdated
@alexander-alderman-webb alexander-alderman-webb merged commit c686455 into master May 22, 2026
154 of 157 checks passed
@alexander-alderman-webb alexander-alderman-webb deleted the webb/pydantic-ai/span-first branch May 22, 2026 13:36
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.

Migrate pydantic_ai to span first

2 participants