fix(server-utils): Match the Anthropic stream helper header regardless of case (#24855)
`messages.stream()` calls the instrumented `messages.create({ stream:
true })` underneath and tags that call with a helper-method header. The
integration uses that header to skip the nested `create`, so a streamed
message gets one span.
The SDK sent the header as `X-Stainless-Helper-Method` up to 0.105 and
as lowercase `x-stainless-helper-method` since 0.106. The check compared
the exact casing, so on a current SDK every `messages.stream()` produced
two nested `gen_ai.chat` spans, both with the full attributes. Header
names are case-insensitive, so the check now matches without regard to
case.
**Second commit, from review.** Matching the header alone was not
enough: `beta.messages.stream()` and the streaming tool runner tag their
internal `create` with the same header, but only the non-beta helper is
on the `messages-stream` channel, so nothing covers them and skipping
left them with no span at all. The skip now only applies while a
stream-helper span this integration opened is the active span. The
regular helper is still deduped; the beta helper and the tool runner
keep their span.
**Found by** the send-to-sentry e2e app for Anthropic (#24748, PR
#24856) in its `latest` variant. On 0.63 the stream helper gives one
span; on 0.129 it gave two.
**Tests.**
- `suites/tracing/anthropic/v0.129` (Node), pinned to that SDK version
the way the openai v7 suite is: one span for `messages.stream()`, and
one span each for `beta.messages.stream()` and the eager streaming tool
runner. The beta scenario is from isaacs' review.
- `suites/tracing/anthropic-ai-stream-helper` (Cloudflare), built
through the Sentry Vite plugin so the calls go through the channel
integration on workerd, where the active span is the core span rather
than an OpenTelemetry one: one span for the regular helper, one for the
beta helper.
Each suite fails without its half of the fix and passes with it. The
existing Anthropic suites on 0.63 still pass.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: isaacs <i@izs.me> R
Rola Abuhasna committed
ed31852e19ec238c2f1bc7e16d41ee34cc8651d3
Parent: fb43c0b
Committed by GitHub <noreply@github.com>
on 10/1/2026, 2:37:48 PM