Vercel AI

Adds instrumentation for Vercel AI SDK.

Import name: Sentry.vercelAIIntegration

The vercelAIIntegration adds instrumentation for the ai SDK by Vercel to capture spans using the AI SDK's built-in Telemetry.

This integration is enabled by default in the Node runtime, but not in the Edge runtime. You need to manually enable it by passing Sentry.vercelAIIntegration() to Sentry.init in your sentry.edge.config.js file:

'sentry.edge.config.(js|ts)'
Copied
Sentry.init({
  dsn: ""
  tracesSampleRate: 1.0,
  integrations: [Sentry.vercelAIIntegration()],
});

To correctly capture spans, pass the experimental_telemetry object with isEnabled: true to every generateText, generateObject, and streamText function call. For more details, see the AI SDK Telemetry Metadata docs.

Copied
const result = await generateText({
  model: openai("gpt-4o"),
  experimental_telemetry: {
    isEnabled: true,
    recordInputs: true,
    recordOutputs: true,
  },
});

Requires SDK version 9.29.0 or higher.

Type: boolean

Forces the integration to be active, even when the ai module is not detected or available. This is useful when you want to ensure the integration is always enabled regardless of module detection.

Defaults to false.

Copied
Sentry.init({
  integrations: [Sentry.vercelAIIntegration({ force: true })],
});

This option is not available in the Edge runtime. There, the integration is forced when it is enabled.

In order to make it easier to correlate captured spans with the function calls we recommend setting functionId in experimental_telemetry in all generation function calls:

Copied
const result = await generateText({
  model: openai("gpt-4o"),
  experimental_telemetry: {
    isEnabled: true,
    functionId: "my-awesome-function",
  },
});

By default this integration adds tracing support to all ai function callsites. If you need to disable span collection for a specific call, you can do so by setting experimental_telemetry.isEnabled to false in the first argument of the function call.

Copied
const result = await generateText({
  model: openai("gpt-4o"),
  experimental_telemetry: { isEnabled: false },
});

If you set experimental_telemetry.recordInputs and experimental_telemetry.recordOutputs it will override the default behavior of collecting inputs and outputs for that function call.

Copied
const result = await generateText({
  model: openai("gpt-4o"),
  experimental_telemetry: {
    isEnabled: true,
    recordInputs: true,
    recordOutputs: true,
  },
});

  • ai: >=3.0.0 <5
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").