For AI agents: a documentation index is available at /docs/llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.
Send Vercel AI SDK traces to Agent Analytics
このページはまだあなたの言語に翻訳されていません。 現在取り組んでいますので、後でもう一度確認してください。
Vercel AI SDK 7 emits OpenTelemetry GenAI spans through @ai-sdk/otel. Point that exporter at Amplitude. You don't need the Amplitude AI SDK in the agent process.
This page covers ai 7.0.155 with @ai-sdk/otel 1.0.155, and ai 6.0.317 with @ai-sdk/openai 2.0.138. Amplitude stores the spans you export. Scrub personal data before it leaves your infrastructure. Refer to Agent Analytics privacy modes.
Set up with your AI coding agent (recommended)
Paste this prompt into your AI coding agent, such as Cursor, Claude Code, Windsurf, GitHub Copilot, or Codex.
Connect this Vercel AI SDK 7 app to Amplitude Agent Analytics with native OpenTelemetry.
Fetch https://raw.githubusercontent.com/amplitude/Amplitude-AI-Node/main/docs/integrations/vercel-ai-sdk.md
and follow "Part 2: Coding agent procedure".
If @amplitude/ai is installed, the same file is under node_modules/@amplitude/ai/docs/integrations/.
Also follow https://raw.githubusercontent.com/amplitude/Amplitude-AI-Node/main/docs/integrations/privacy.md
and scrub content before export.
Follow links in the guide. If your source isn't listed, start at https://raw.githubusercontent.com/amplitude/Amplitude-AI-Node/main/docs/integrations/README.md
Review the changes, then verify with the steps in Get started.
What this means for you
- You run: The Node process, with
@ai-sdk/otelpointed at Amplitude. A function id is not a session id. - You need:
ai@7.0.155,@ai-sdk/otel@1.0.155, your Amplitude project API key, and a stable conversation id and product-analytics user ID on every turn. - Protocol: OTLP over HTTP. Amplitude accepts protobuf and JSON. Amplitude doesn't accept gRPC.
- Privacy: Amplitude doesn't scrub content after receipt.
recordInputs: falseandrecordOutputs: falsedrop message text and tool arguments. The session, user, agent, model, token counts, and tool name still arrive. Mask or drop the content attributes before export.
Export
Set these variables in the agent process. Encode the space in the header value as %20 when the value is in an environment variable. Leave Authorization= as written.
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://api.amplitude.com/otlp/v1/traces
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer%20<project API key>"
OTEL_SERVICE_NAME=order-support
EU data residency uses https://api.eu.amplitude.com/otlp/v1/traces.
Call registerTelemetry(new OpenTelemetry({ enrichSpan })) before the first model call on SDK 7. enrichSpan sets gen_ai.conversation.id, user.id, and gen_ai.agent.id. On SDK 6, enable experimental_telemetry and set those three attributes from a span processor. On a tool loop, set stopWhen: stepCountIs(...) so the final model call carries the reply text. Amplitude maps SDK 6 ai.generateText.doGenerate to a model call and ai.toolCall to a tool call. The parent ai.generateText span stays a span.
Identity
| Attribute | Value |
|---|---|
gen_ai.conversation.id | The conversation, thread, or ticket ID. Use the same value on every turn. |
user.id | The user ID product analytics already uses. Amplitude stores a missing user as unknown. |
gen_ai.agent.id | A stable name for this agent. Amplitude doesn't read gen_ai.agent.name. |
What carries over
| AI SDK span | Amplitude event |
|---|---|
Model invocation (chat) | [Agent] AI Response, plus an [Agent] User Message for each new user message after the last assistant message |
Tool (execute_tool) | [Agent] Tool Call |
| Step and agent spans | [Agent] Span |
A tool-loop continuation repeats the earlier user text inside gen_ai.input.messages. Amplitude doesn't emit that earlier user message again. Tool output is [Agent] Tool Output.
Session close
[Agent] Session End is optional and recommended. A native AI SDK export doesn't send it. Amplitude closes the session after 30 minutes without a qualifying agent event by default, and 24 hours from the session start when no per-session override is set. The first close is the one that counts. Enrichment, including the Session Record and content-based signals, runs once after that close. The OpenTelemetry translator doesn't read an idle-timeout attribute from a span. Refer to How sessions close.
Get started
Follow the Vercel AI SDK integration guide. Send two turns with the same conversation id, then confirm in Live Events:
- Session ID is
gen_ai.conversation.id, not a trace ID. - User ID is the product-analytics user, not
unknown. - Agent ID is
gen_ai.agent.id. - The turn shows User Message text, the tool call, and AI Response text, with the model name and both token counts.
- The second turn doesn't duplicate the first user message.
Guide last verified on October 28, 2026, against ai 7.0.155, @ai-sdk/otel 1.0.155, and ai 6.0.317 with @ai-sdk/openai 2.0.138. Vercel and the AI SDK are trademarks of their owner. Amplitude isn't affiliated with or endorsed by that owner.
これは役に立ちましたか?