Vercel AI SDK

generateText, streamText, generateObject, and tool calls capture once you opt in with experimental_telemetry.

The Vercel AI SDK emits OpenTelemetry spans only when you enable telemetry per call. With the Trodo SDK initialised, every ai call inside wrap your agent flagged with experimental_telemetry becomes a span.

On Next.js with @vercel/otel? You can skip the Trodo SDK install and use the env-var-only OTLP path instead. See Use your existing OpenTelemetry. The SDK install below is the right choice when you want wrapAgent boundaries, feedback, or MCP.

AI SDK v7 removed built-in OpenTelemetry. On v5/v6, experimental_telemetry: { isEnabled: true } per call is all you need. On v7 that option is gone and emits nothing — you must install @ai-sdk/otel and register it once at startup:

import { OpenTelemetry } from '@ai-sdk/otel';
import { registerTelemetry } from 'ai';
registerTelemetry(new OpenTelemetry()); // after Trodo/OTel provider is registered

After that, every call emits spans by default and Trodo captures them unchanged (v7 uses the newer GenAI semconv — gen_ai.input.messages, gen_ai.tool.call.arguments, etc., all handled). If a v7 app shows no spans, this missing registration is why.

What's captured

CallSpan kindAuto-extracted
generateTextllmmodel, provider, tokens, prompt, completion
streamTextllmsame, accumulated
generateObject / streamObjectllmmodel, tokens, schema, parsed object
tool() and the tool-call looptooltool name, input, output
embed / embedManyllmmodel, tokens

The provider field is whichever adapter you use (openai, anthropic, google).

Install

npm install ai@^5 @ai-sdk/openai@^2

On AI SDK v5, no OpenTelemetry package is needed; the ai SDK includes its own OTel integration.

AI SDK v7 moved OTel telemetry out of the core ai package into @ai-sdk/otel — on v7, experimental_telemetry: { isEnabled: true } alone is a silent no-op (calls succeed, zero spans). Pin ai@^5 until you migrate to the v7 telemetry adapter.

Minimal example

import trodo from 'trodo-node';
import { generateText, tool } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';

trodo.init({ siteId: process.env.TRODO_SITE_ID });

await trodo.wrapAgent('ai-sdk-bot', async (run) => {
  const { text } = await generateText({
    model: openai('gpt-4o-mini'),
    prompt: 'What is the weather in SF?',
    tools: {
      get_weather: tool({
        description: 'Current weather in a city',
        inputSchema: z.object({ city: z.string() }), // AI SDK v5+: inputSchema (was `parameters` in v4)
        execute: async ({ city }) => `Sunny in ${city}, 72F`,
      }),
    },
    experimental_telemetry: { isEnabled: true }, // required
  });
  run.setOutput(text);
});

The experimental_telemetry: { isEnabled: true } flag is required. Without it, the AI SDK emits no spans.

On this page