Solution skill
Observability: OpenTelemetry tracing for AI SDK calls with @ai-sdk/otel
Complete solution
Guide Observability: OpenTelemetry tracing for AI SDK calls with @ai-sdk/otel: Setup: pnpm add @ai-sdk/otel // instrumentation.ts (Next.js, project root) import { registerOTel } from '@vercel/otel'; import { registerTelemetry } from 'ai'; import { OpenTelemetry } from. Use this when you hit exactly this in Observability. Not for different errors or different tools.
TL;DR: Setup: pnpm add @ai-sdk/otel // instrumentation.ts (Next.js, project root) import { registerOTel } from '@vercel/otel'; import { registerTelemetry } from 'ai'; import { OpenTelemetry } from '@ai-sdk/otel'; export function register() { registerOTel({ serviceName: 'my-ai-app' }); registerTelemetry(new OpenTelemetry()); } // plain Node: call registerTelemetry(new OpenTelemetry()) at entry startup Per-call metadata const result = await generateText({ model: 'your-model-id', prompt: 'Write a haiku.', telemetry: { functionId: 'haiku-writer' }, }); Rules: 1.
AI SDK calls emit OpenTelemetry spans once you register the integration. Without it you are flying blind on latency, cost, and errors.
Setup:
pnpm add @ai-sdk/otel
// instrumentation.ts (Next.js, project root) import { registerOTel } from '@vercel/otel'; import { registerTelemetry } from 'ai'; import { OpenTelemetry } from '@ai-sdk/otel';
export function register() { registerOTel({ serviceName: 'my-ai-app' }); registerTelemetry(new OpenTelemetry()); }
// plain Node: call registerTelemetry(new OpenTelemetry()) at entry startup
Per-call metadata
const result = await generateText({ model: 'your-model-id', prompt: 'Write a haiku.', telemetry: { functionId: 'haiku-writer' }, });
Rules:
- Telemetry is opt-out once registered: every call emits spans. Disable per call with telemetry: { isEnabled: false }, or globally by not registering.
- Inputs and outputs are recorded by default. Set recordInputs/recordOutputs false when prompts contain PII, secrets, or large blobs. This is a privacy control, not just a cost one.
- Use functionId to attribute spans to features (checkout-helper, support-draft). Cost dashboards group by it.
- For call-site-specific logic (custom log lines, per-request billing math), use the lifecycle callbacks onStart/onEnd on the generateText/streamText call. They receive callId, usage, finishReason. Keep them fast; a throwing callback is swallowed but a slow one delays your response.
- Correlate with your request tracing: pass request/user/tenant ids via runtimeContext so spans join the right trace.
- Verify in your tracing backend: fire a test generation and confirm spans arrive with the functionId before shipping to production.
When to use
You hit exactly this: Observability: OpenTelemetry tracing for AI SDK calls with @ai-sdk/otel in Observability.
When not to use
A different error, or the same symptom in a different tool. This page only covers the failure above.
Compatibility
Observability.
Evidence
Verified against the live AI SDK docs 2026-09-26. The telemetry guide documents pnpm add @ai-sdk/otel, registerTelemetry(new OpenTelemetry()), the Next.js instrumentation.ts pattern with registerOTel, telemetry: { functionId } metadata, recordInputs/recordOutputs defaults, and isEnabled: false opt-out. The lifecycle-callbacks guide documents onStart/onEnd with callId, usage, and finishReason.
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_55i_RKPa8fHVWVyuccTcrw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Observability: OpenTelemetry tracing for AI SDK calls with @ai-sdk/otel <span>— Vectle</span></a>