Skip to content

feat(server-utils): Emit execute_tool spans for Anthropic's beta.messages.toolRunner() #25288

Open

Description

@RulaKhaled

Our Anthropic integration creates chat spans but no execute_tool spans. With .create() and .stream(), user code runs the tools, so we can't see them. beta.messages.toolRunner() is the one place in the SDK that calls tool code itself, through each tool's run().

The runner's chat calls already get spans. What's missing:

  • execute_tool spans
  • tool errors, which the runner catches and turns into an is_error tool result, so Sentry never sees them

Since 0.129.0, runToolsEagerly: true starts tools while the reply is still streaming, so tool spans can overlap the chat span.

TODO

  • Wrap each runnable tool's run() with a gen_ai.execute_tool span. Cover tools passed to toolRunner(), addTools(), and setMessagesParams().
  • Set the span to error when run() throws. Decide whether to also capture the exception, since the model gets the error and may recover.
  • Do it on both paths: orchestrion and instrumentAnthropicAiClient.
  • Tests: multiple tool calls, eager and lazy, a tool that throws, an abort mid-stream, and an incomplete tool call (max_tokens).
  • Check that the AI agents views handle tool spans that overlap the chat span.

Activity

  1. self-assigned this
    on Oct 12, 2026
  2. linear-code commented on Oct 12, 2026

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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions