feat(pydantic-ai): Support span streaming#6389
Conversation
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)
Generated by Codecov Action |
There was a problem hiding this comment.
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 insentry_sdk/traces.py:227) hasset_attribute/set_attributesbut noset_datamethod (confirmed via grep).update_invoke_agent_spancallsspan.set_data(SPANDATA.GEN_AI_RESPONSE_MODEL, response.model_name)atinvoke_agent.py:168without anisinstance(span, StreamedSpan)guard.- The call is wrapped in
try/except Exception, so theAttributeErroris silently eaten. ai_client_spanandexecute_tool_spanin the same PR both correctly useisinstance(span, StreamedSpan)checks (e.g.,execute_tool.py:update_execute_tool_span).- The new parametrized tests added in the hunk check
gen_ai.chatandgen_ai.execute_toolspans but not theinvoke_agentspan'sGEN_AI_RESPONSE_MODELattribute, so this regression goes undetected.
Identified by Warden code-review
sentrivana
left a comment
There was a problem hiding this comment.
Looks good, small improvement suggestions in tests
Description
Use
sentry_sdk.traces.start_spanand replaceSpan.set_data()withStreamedSpan.set_attribute()when in span streaming mode.Parametrize tests on the trace lifecycle option.
Issues
Closes #6046
Reminders
tox -e linters.feat:,fix:,ref:,meta:)