Skip to main content

Documentation Index

Fetch the complete documentation index at: https://traceroot.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

Trace Vercel AI SDK agents in TraceRoot. Unlike LangChain, OpenAI, or Anthropic, no instrumentModules configuration is needed — the Vercel AI SDK emits OpenTelemetry spans natively when experimental_telemetry is enabled, and TraceRoot enriches them via the OpenInference span processor automatically.

Setup

npm install @traceroot-ai/traceroot ai @ai-sdk/openai zod
Initialize TraceRoot at your entry point — no instrumentModules config:
import { TraceRoot } from '@traceroot-ai/traceroot';

// No instrumentModules — Vercel AI SDK telemetry is handled automatically.
TraceRoot.initialize();

Usage

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

const result = await observe({ name: 'my_agent', type: 'agent' }, async () => {
  return await generateText({
    model: openai('gpt-4o-mini'),
    maxSteps: 5,
    prompt: 'What is the weather in Tokyo?',
    // This single line activates Vercel AI SDK's built-in OpenTelemetry spans.
    // TraceRoot enriches them automatically.
    experimental_telemetry: { isEnabled: true },
    tools: {
      getWeather: tool({
        description: 'Get current weather for a city',
        parameters: z.object({ city: z.string() }),
        execute: async ({ city }) => ({ city, temp: 72, condition: 'sunny' }),
      }),
    },
  });
});

console.log(result.text);

What Gets Captured

AttributeDescription
ModelThe model passed to generateText / streamText / generateObject
MessagesInput prompt and message history
ResponseGenerated text output
Tool callsEach tool invocation with input and output
TokensInput and output token counts
CostCalculated from token usage and model pricing
LatencyRequest duration per span
Multi-step iterationsEach maxSteps iteration captured as a child span

Run the example

Clone the repo and run a complete agent end-to-end.

TypeScript

Run the TypeScript example