Problem
The vercelAIIntegration in @sentry/nextjs doesn't activate on Vercel deployments, causing AI SDK spans to have incorrect names:
- On Vercel: Raw span names like
ai.toolCall, ai.streamText (WRONG)
- Locally: Transformed names like
gen_ai.execute_tool, gen_ai.stream_text (CORRECT)
Root Cause
The Node SDK's vercelAIIntegration has conditional activation logic in afterAllSetup:
// packages/node/src/integrations/tracing/vercelai/index.ts:28-37
afterAllSetup(client) {
const shouldForce = options.force ?? shouldForceIntegration(client);
if (shouldForce) {
addVercelAiProcessors(client); // ← Span transformation enabled
} else {
instrumentation?.callWhenPatched(() => addVercelAiProcessors(client));
}
}
addVercelAiProcessors is only called if:
force: true is passed, OR
- Module detection succeeds (CJS mode only), OR
- OTEL successfully patches the
ai module
Why It Fails on Vercel
The ai package is intentionally NOT externalized in Next.js builds:
// packages/nextjs/src/config/withSentryConfig/constants.ts:5-8
// NOTE: 'ai' (Vercel AI SDK) is intentionally NOT included in this list.
// When externalized, Next.js doesn't properly handle the package's conditional exports,
// specifically the "react-server" export condition.
Because ai is bundled (not externalized):
- OTEL's require hooks can't intercept module loading
instrumentation?.callWhenPatched() callback never fires
- Module detection via
shouldForceIntegration fails (requires CJS mode)
- Result:
addVercelAiProcessors() is never called on Vercel
Comparison: Edge vs Node Implementation
Edge implementation (vercel-edge/src/integrations/tracing/vercelai.ts):
setup(client) {
addVercelAiProcessors(client); // ALWAYS called unconditionally
}
Node implementation - conditional, requires force: true to guarantee activation in bundled environments.
Current Workaround
Users must explicitly add force: true in their server config:
// sentry.server.config.ts
import * as Sentry from "@sentry/nextjs";
Sentry.init({
dsn: "...",
integrations: [Sentry.vercelAIIntegration({ force: true })],
});
Suggested Fix
Consider one of these approaches:
- Auto-detect Vercel environment: Default
force: true when VERCEL env var is present
- Document the workaround: Add clear documentation that
force: true is required for Vercel deployments
- Change default behavior: Make the Node implementation behave like Edge (always register processors)
Environment
@sentry/nextjs: Latest
- Deployment: Vercel (serverless)
- AI SDK:
ai package from Vercel
Problem
The
vercelAIIntegrationin@sentry/nextjsdoesn't activate on Vercel deployments, causing AI SDK spans to have incorrect names:ai.toolCall,ai.streamText(WRONG)gen_ai.execute_tool,gen_ai.stream_text(CORRECT)Root Cause
The Node SDK's
vercelAIIntegrationhas conditional activation logic inafterAllSetup:addVercelAiProcessorsis only called if:force: trueis passed, ORaimoduleWhy It Fails on Vercel
The
aipackage is intentionally NOT externalized in Next.js builds:Because
aiis bundled (not externalized):instrumentation?.callWhenPatched()callback never firesshouldForceIntegrationfails (requires CJS mode)addVercelAiProcessors()is never called on VercelComparison: Edge vs Node Implementation
Edge implementation (
vercel-edge/src/integrations/tracing/vercelai.ts):Node implementation - conditional, requires
force: trueto guarantee activation in bundled environments.Current Workaround
Users must explicitly add
force: truein their server config:Suggested Fix
Consider one of these approaches:
force: truewhenVERCELenv var is presentforce: trueis required for Vercel deploymentsEnvironment
@sentry/nextjs: Latestaipackage from Vercel