Skip to content

MCP sampling calls are not nested under agent run spanΒ #3186

@JohnCHarrington

Description

@JohnCHarrington

Initial Checks

Description

Run the MCP sampling example from the PydanticAI docs (https://ai.pydantic.dev/mcp/client/#mcp-sampling) with OpenTelemetry instrumentation.

I would expect the sampling LLM call to appear in the trace of my agent run, ideally nested under the tool call that made that sampling request.

Instead, the sampling LLM call appears as it's own separate trace, with no way to link it to the tool or the trace it was part of. Here the result is shown in langfuse, where agent run is the main trace, and chat acd-openai... is the sampling call:

Image

Example Code

Simply instrument the example in the docs with opentelemetry.

Python, Pydantic AI & LLM client version

Python 3.11
Pydantic AI 1.1.0
Azure OpenAI (latest)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions