Skip to content

Commit a0f4f12

Browse files
Qardclaude
andauthored
fix(auto-instrumentation): Use sync channel for AI SDK CJS streamText/streamObject in v4+ (#1768)
## Summary - The CJS bundle entries for `streamText` and `streamObject` used `kind: "Async"` for all versions (`>=3.0.0`), but `DefaultStreamTextResult`/`DefaultStreamObjectResult` have no `.then()`, so `asyncEnd` never fires when the transformer wraps via `promise.then()` - Splits the CJS entries to mirror the existing ESM split (which was already correct in main): - `>=3.0.0 <4.0.0`: `kind: "Async"` — v3, where the function was genuinely async - `>=4.0.0`: `kind: "Sync"` + sync channel — v4+, after the sync refactor - The `traceSyncStreamChannel` handlers for `streamTextSync`/`streamObjectSync` already exist in `ai-sdk-plugin.ts` (they were added when the ESM path was fixed), so no plugin change is needed ## Test plan - [x] `ai-sdk-plugin.test.ts` — 96 tests pass - [x] Pre-existing test failures in `transformation.test.ts` / `loader-hook.test.ts` confirmed unrelated (same failures on `main`) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6214e89 commit a0f4f12

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

  • js/src/auto-instrumentations/configs

js/src/auto-instrumentations/configs/ai-sdk.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,26 @@ export const aiSDKConfigs: InstrumentationConfig[] = [
7070
channelName: aiSDKChannels.streamText.channelName,
7171
module: {
7272
name: "ai",
73-
versionRange: ">=3.0.0",
73+
versionRange: ">=3.0.0 <4.0.0",
7474
filePath: "dist/index.js",
7575
},
7676
functionQuery: {
7777
functionName: "streamText",
7878
kind: "Async",
7979
},
8080
},
81+
{
82+
channelName: aiSDKChannels.streamTextSync.channelName,
83+
module: {
84+
name: "ai",
85+
versionRange: ">=4.0.0",
86+
filePath: "dist/index.js",
87+
},
88+
functionQuery: {
89+
functionName: "streamText",
90+
kind: "Sync",
91+
},
92+
},
8193

8294
// generateObject - async function
8395
{
@@ -188,14 +200,26 @@ export const aiSDKConfigs: InstrumentationConfig[] = [
188200
channelName: aiSDKChannels.streamObject.channelName,
189201
module: {
190202
name: "ai",
191-
versionRange: ">=3.0.0",
203+
versionRange: ">=3.0.0 <4.0.0",
192204
filePath: "dist/index.js",
193205
},
194206
functionQuery: {
195207
functionName: "streamObject",
196208
kind: "Async",
197209
},
198210
},
211+
{
212+
channelName: aiSDKChannels.streamObjectSync.channelName,
213+
module: {
214+
name: "ai",
215+
versionRange: ">=4.0.0",
216+
filePath: "dist/index.js",
217+
},
218+
functionQuery: {
219+
functionName: "streamObject",
220+
kind: "Sync",
221+
},
222+
},
199223

200224
// Agent.generate - async method (v5 only)
201225
// The compiled AI SDK bundle emits this as an anonymous class method, so we

0 commit comments

Comments
 (0)