Skip to content

Anthropic tool runner and message threads drop gen_ai.chat spans on @anthropic-ai/sdk >=1.2.0 #25816

Open

Description

@chargome

On @anthropic-ai/sdk 1.2.0 and newer, calls made through beta.messages.toolRunner() or beta.messages.thread() produce no gen_ai.chat spans. gen_ai.execute_tool spans still show up. This is the follow-up mentioned in #25750.

I ran the eager streaming tool runner scenario from suites/tracing/anthropic/v0.129 against several versions with the range widened to <2:

SDK version gen_ai.chat spans gen_ai.execute_tool spans
0.133.0, 0.137.0, 1.0.0, 1.1.0 2 2
1.2.0, 1.3.0 0 2

Cause. 1.2.0 added message threads, which are on by default for the first-party Anthropic client (_supportsMessageThreads = true). The tool runner now sends each turn through BetaMessageThread._createWithRecovery, which still calls beta.messages.create(), so our chat channel opens a span. But the thread then awaits request._responseProps() and builds its own APIPromise from the raw props. wrapApiPromiseResponse (packages/server-utils/src/ai/core/apiPromise.ts) only ends the span from parseResponse or asResponse(), and neither runs on that path. The span is opened but never ended, so it is never sent.

Requests that fail still end the span, through the asResponse() error handler.

Scope. This affects every toolRunner() call and any direct thread().send() on the default client from 1.2.0 on. Bedrock and Vertex clients don't support threads, so they should not be affected (not verified).

Fix direction. End the span from the response props as well, for example by also observing _responseProps(). The streaming case is harder: the thread builds the Stream itself, so we would need to hook that stream to record usage and end the span when it finishes.

Activity

  1. linear-code commented on Oct 28, 2026

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions