Package Name
pydantic_ai
Package Version(s)
No response
Describe the goal of the feature
The pydantic_ai LLMObs integration (ddtrace/contrib/internal/pydantic_ai/patch.py) traces Agent.iter and
Agent.run_stream, both of which receive an optional conversation_id: str | None keyword argument (see
pydantic_ai/agent/__init__.py, Agent.iter signature). This conversation_id is exactly the semantic equivalent of LLMObs' session_id: it groups multiple agent runs that belong to the same end-user conversation/thread.
Today, traced_agent_iter and traced_agent_run_stream never read this argument, so it's silently dropped.
The only way to get session correlation in LLM Observability is to wrap the call in an explicit
LLMObs.workflow(session_id=...) / LLMObs.agent(session_id=...) context manager, duplicating a value the
integration already has in kwargs at interception time:
def traced_agent_run_stream(func, instance, args, kwargs):
integration = pydantic_ai._datadog_integration
integration._run_stream_active = True
span = integration.trace(
_agent_resource(instance),
span_name="pydantic_ai.agent",
submit_to_llmobs=True,
model=getattr(instance, "model", None),
kind="agent",
)
...
A solution: When conversation_id is present in kwargs for Agent.iter / Agent.run_stream, pass it through to _annotate_llmobs_span_data as session_id, e.g. in PydanticAIIntegration._llmobs_set_tags_agent :
conversation_id = kwargs.get("conversation_id")
_annotate_llmobs_span_data(
span,
name=agent_name or "PydanticAI Agent",
input_value=user_prompt,
output_value=result,
session_id=conversation_id,
)
Is your feature request related to a problem?
No response
Describe alternatives you've considered
No response
Additional context
No response
Package Name
pydantic_ai
Package Version(s)
No response
Describe the goal of the feature
The
pydantic_aiLLMObs integration (ddtrace/contrib/internal/pydantic_ai/patch.py) tracesAgent.iterandAgent.run_stream, both of which receive an optionalconversation_id: str | Nonekeyword argument (seepydantic_ai/agent/__init__.py,Agent.itersignature). Thisconversation_idis exactly the semantic equivalent of LLMObs' session_id: it groups multiple agent runs that belong to the same end-user conversation/thread.Today,
traced_agent_iterandtraced_agent_run_streamnever read this argument, so it's silently dropped.The only way to get session correlation in LLM Observability is to wrap the call in an explicit
LLMObs.workflow(session_id=...)/LLMObs.agent(session_id=...)context manager, duplicating a value theintegration already has in kwargs at interception time:
A solution: When
conversation_idis present inkwargsforAgent.iter/Agent.run_stream, pass it through to_annotate_llmobs_span_dataassession_id, e.g. inPydanticAIIntegration._llmobs_set_tags_agent:Is your feature request related to a problem?
No response
Describe alternatives you've considered
No response
Additional context
No response