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.
What's captured
| Call | Span kind | Auto-extracted |
|---|---|---|
generateText | llm | model, provider, tokens, prompt, completion |
streamText | llm | same, accumulated |
generateObject / streamObject | llm | model, tokens, schema, parsed object |
tool() and the tool-call loop | tool | tool name, input, output |
embed / embedMany | llm | model, tokens |
The provider field is whichever adapter you use (openai, anthropic, google).
Install
npm install ai @ai-sdk/openaiNo OpenTelemetry package is needed; the ai SDK includes its own OTel integration.
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',
parameters: z.object({ city: z.string() }),
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.