Skip to content

fix(auto-instrumentation): Fix AI SDK streaming version handling for v3/v4+/v5#1739

Open
Stephen Belanger (Qard) wants to merge 1 commit intomainfrom
fix/ai-sdk-streaming-version-fixes
Open

fix(auto-instrumentation): Fix AI SDK streaming version handling for v3/v4+/v5#1739
Stephen Belanger (Qard) wants to merge 1 commit intomainfrom
fix/ai-sdk-streaming-version-fixes

Conversation

@Qard
Copy link
Copy Markdown
Contributor

Summary

  • streamText / streamObject (ESM): Split the instrumentation config by version range. In v3 both functions are declared async, so they need kind: "Async" (asyncEnd fires with the resolved stream result). In v4+ they are sync functions returning the stream directly, so they use kind: "Sync" with the existing sync-stream channels.
  • Agent.stream (v5): The stream() method in v5 is sync (not async), so wrapPromise's asyncEnd never fires under auto-hook instrumentation. Added a new agentStreamSync channel (kind: "sync-stream") for the auto-hook path. The existing agentStream channel is kept for the wrapAISDK wrapper path which uses tracePromise.

These gaps were exposed by the @apm-js-collab/code-transformer v0.11.0 upgrade (PR #1708), which tightened wrapPromise to only fire asyncEnd when the return value is actually thenable.

Test plan

  • All 84 AI SDK instrumentation e2e tests pass (wrapped + auto-hook for v3, v4, v5, v6)
  • pnpm run build succeeds with no type errors

🤖 Generated with Claude Code

…nt.stream version handling

Split ESM streamText/streamObject instrumentation configs by version range:
- v3 (>=3.0.0 <4.0.0): keep kind: "Async" since both functions are declared
  async in v3; asyncEnd fires with the resolved stream result
- v4+ (>=4.0.0): use kind: "Sync" + streamTextSync/streamObjectSync channels
  since these functions are sync in v4+ and return the stream object directly

Add agentStreamSync channel (kind: "sync-stream") for auto-hook path on v5:
- v5 Agent.stream() is a sync method, so wrapPromise never fires asyncEnd
- The existing agentStream channel (kind: "async") is kept for wrapAISDK's
  tracePromise path; the new agentStreamSync channel handles auto-hook via
  traceSyncStreamChannel with patchAISDKStreamingResult

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant