Skip to content

Commit b45c204

Browse files
mydeaclaude
andcommitted
fix(nextjs): Add edge no-op shim for vercelAIIntegration
Removing `vercelAIIntegration` from `@sentry/vercel-edge` dropped it from the `@sentry/nextjs` edge build (which re-exports that package), so named imports from `@sentry/nextjs` would fail when Next.js compiles instrumentation for the edge runtime — while `index.types.ts` still declares the export. Mirror the existing `pinoIntegration` pattern: a no-op edge shim plus an explicit server re-export so the export is statically detectable from both builds. Extends the `serverExports` regression test to cover it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent deb0b3d commit b45c204

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

MIGRATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ Sentry.init({
875875
- AI integrations are no longer available in the browser SDK. They remain available in the server-side SDKs.
876876
- The AI instrumentation code moved out of `@sentry/core` into `@sentry/server-utils`. If you imported any AI helper **directly from `@sentry/core`**, import it from `@sentry/server-utils` instead (or keep importing it from your platform SDK, e.g. `@sentry/node`, if it re-exported that helper before — platform SDK availability is unchanged from v10). Affected helpers: `instrumentOpenAiClient`, `instrumentAnthropicAiClient`, `instrumentGoogleGenAIClient`, `instrumentWorkersAiClient`, `createLangChainCallbackHandler`, `instrumentLangChainEmbeddings`, `instrumentStateGraph`, `instrumentStateGraphCompile`, `instrumentCreateReactAgent`.
877877
- The `addVercelAiProcessors` helper was removed. It was an internal building block for setting up Vercel AI span processing by hand; `vercelAIIntegration()` now wires this up on its own, so add that integration instead of calling `addVercelAiProcessors` directly.
878-
- (Vercel Edge) `vercelAIIntegration` was removed from `@sentry/vercel-edge` (and, with it, the Edge runtime of `@sentry/nextjs`). Vercel AI is no longer instrumented on the Edge runtime.
878+
- (Vercel Edge) `vercelAIIntegration` was removed from `@sentry/vercel-edge`; Vercel AI is not instrumented on the Edge runtime. `@sentry/nextjs` keeps the export on its Edge build as a no-op (so `import { vercelAIIntegration }` from `@sentry/nextjs` still resolves in edge-compiled instrumentation files), with the real instrumentation running only in the Node runtime.
879879
- (Cloudflare & Deno) `vercelAIIntegration` no longer post-processes the OpenTelemetry spans emitted by the `ai` SDK. Instrumentation now goes solely through the channel-based instrumentation, the same as the other server SDKs.
880880
- The following low-level AI exports are no longer part of the public API (they were provider-instrumentation internals exported from `@sentry/core`):
881881
- Attribute/stream/util helpers: `extractOpenAiRequestAttributes`, `addOpenAiRequestAttributes`, `addOpenAiResponseAttributes`, `extractOpenAiRequestParameters`, `instrumentOpenAiStream`, `extractAnthropicRequestAttributes`, `addAnthropicRequestAttributes`, `addAnthropicResponseAttributes`, `instrumentAsyncIterableStream`, `instrumentMessageStream`, `extractGoogleGenAIRequestAttributes`, `addGoogleGenAIRequestAttributes`, `addGoogleGenAIResponseAttributes`, `instrumentGoogleGenAIStream`, `getProviderMetadataAttributes`, `getTruncatedJsonString`, `shouldEnableTruncation`, `resolveAIRecordingOptions`, `wrapToolsWithSpans`, `extractLLMFromParams`, `extractAgentNameFromParams`, `instrumentCompiledGraphInvoke`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineIntegration } from '@sentry/core';
2+
3+
/**
4+
* Shim for the edge build so named imports from `@sentry/nextjs` stay resolvable in
5+
* edge-compiled instrumentation modules. The real implementation ships in the server build;
6+
* Vercel AI is not instrumented on the edge runtime.
7+
*/
8+
export const vercelAIIntegration = defineIntegration(() => {
9+
return {
10+
name: 'VercelAI',
11+
};
12+
});

packages/nextjs/src/edge/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export * from '../common';
4242
export { captureUnderscoreErrorException } from '../common/pages-router-instrumentation/_error';
4343

4444
export { pinoIntegration } from '../common/pinoIntegrationShim';
45+
export { vercelAIIntegration } from '../common/vercelAIIntegrationShim';
4546

4647
// Override core span methods with Next.js-specific implementations that support Cache Components
4748
export { startSpan, startSpanManual, startInactiveSpan } from '../common/utils/nextSpan';

packages/nextjs/src/server/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import { maybeCleanupQueueSpan } from './vercelQueuesMonitoring';
2525

2626
export * from '@sentry/node';
2727

28-
// Explicitly re-export so it is statically detectable by turbopack
29-
export { pinoIntegration } from '@sentry/node';
28+
// Explicitly re-export so these are statically detectable by turbopack
29+
export { pinoIntegration, vercelAIIntegration } from '@sentry/node';
3030

3131
export { captureUnderscoreErrorException } from '../common/pages-router-instrumentation/_error';
3232

packages/nextjs/test/serverExports.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ import { beforeAll, describe, expect, it } from 'vitest';
66
/**
77
* Node-only exports must be statically resolvable from the server AND edge builds, since Next.js compiles
88
* instrumentation modules for the edge runtime too. Otherwise named imports from `@sentry/nextjs` fail to compile
9-
* under Turbopack/webpack.
9+
* under Turbopack/webpack. Exports that are Node-only get a no-op shim on the edge build (e.g. `vercelAIIntegration`).
1010
*
1111
*
1212
* Regression test for https://github.com/getsentry/sentry-javascript/issues/21317
1313
*/
14-
describe('`pinoIntegration` is a statically detectable export from every runtime build', () => {
14+
describe('Node-only integrations are statically detectable exports from every runtime build', () => {
1515
const builds = {
1616
server: resolve(__dirname, '../build/cjs/index.server.js'),
1717
edge: resolve(__dirname, '../build/cjs/edge/index.js'),
1818
};
1919

20+
const dualRuntimeExports = ['pinoIntegration', 'vercelAIIntegration'];
21+
2022
const staticExports: Record<string, string[]> = {};
2123

2224
beforeAll(async () => {
@@ -26,7 +28,10 @@ describe('`pinoIntegration` is a statically detectable export from every runtime
2628
}
2729
});
2830

29-
it.each(Object.keys(builds))('statically exports `pinoIntegration` from the %s build', runtime => {
30-
expect(staticExports[runtime]).toContain('pinoIntegration');
31-
});
31+
it.each(Object.keys(builds).flatMap(runtime => dualRuntimeExports.map(name => ({ runtime, name }))))(
32+
'statically exports `$name` from the $runtime build',
33+
({ runtime, name }) => {
34+
expect(staticExports[runtime]).toContain(name);
35+
},
36+
);
3237
});

0 commit comments

Comments
 (0)