fix(anthropic): enable messages.stream() in auto-instrumentation e2e tests#1696
Open
Stephen Belanger (Qard) wants to merge 1 commit intomainfrom
Open
fix(anthropic): enable messages.stream() in auto-instrumentation e2e tests#1696Stephen Belanger (Qard) wants to merge 1 commit intomainfrom
Stephen Belanger (Qard) wants to merge 1 commit intomainfrom
Conversation
…tests (#1592) The root cause of #1592 was fixed by PR #1617: `patch-tracing-channel.ts` now preserves the original `APIPromise` object (with `.withResponse()`) instead of wrapping it in a plain `.then()` chain when the result is a Promise subclass. Remove the `useMessagesStreamHelper: false` workaround that was causing the auto-hook instrumentation path to avoid `client.messages.stream()`. The 140 anthropic e2e tests all pass with `messages.stream()` enabled in both the wrapper and auto-hook paths. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Luca Forstner (lforst)
approved these changes
Mar 27, 2026
| export async function runAutoAnthropicInstrumentation(Anthropic, options) { | ||
| await runAnthropicInstrumentationScenario(Anthropic, { | ||
| ...options, | ||
| useMessagesStreamHelper: false, |
There was a problem hiding this comment.
we should probably also remove the code that used this argument since it's only used once I think
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1592.
The root cause of this issue was fixed by PR #1617, which patched
TracingChannel.prototype.tracePromiseto preserve the originalAPIPromiseobject rather than wrapping it in a plain.then()chain that strips.withResponse().This PR removes the e2e workaround that was preventing
client.messages.stream()from being tested in the auto-hook instrumentation path.What was the workaround?
runAutoAnthropicInstrumentationwas forcinguseMessagesStreamHelper: false, which caused the"anthropic-stream-with-response-operation"scenario to useclient.messages.create({ stream: true })instead ofclient.messages.stream(). This avoided the failure but left the real code path untested.Why is the fix correct?
client.messages.stream()internally callsthis.create({...}).withResponse(). The instrumentedcreatereturns the originalAPIPromise(not a wrapped plain Promise), so.withResponse()is still available. TheAPIPromiseconstructor check (result.constructor !== Promise) correctly routes to the preserve-original branch in the patchedtracePromise.All 140 anthropic e2e tests pass with both wrapper and auto-hook instrumentation paths using
messages.stream().Test plan
messages.stream()enabled (pnpm vitest run scenarios/anthropic-instrumentation/scenario.test.ts)🤖 Generated with Claude Code