-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
Description
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: trueis passed, OR- Module detection succeeds (CJS mode only), OR
- OTEL successfully patches the
aimodule
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
shouldForceIntegrationfails (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: truewhenVERCELenv var is present - Document the workaround: Add clear documentation that
force: trueis 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:
aipackage from Vercel
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Projects
Status
No status