Set up Vercel AI SDK telemetry for AgentCore Evaluations
This page explains how to instrument a Vercel AI SDK
Note
AgentCore Evaluations supports the Vercel AI SDK for TypeScript agents only. Python is not supported at this time.
Topics
TypeScript agent support
A Vercel AI SDK agent produces spans under the scope name @aws/aws-distro-opentelemetry-instrumentation-vercel-ai.
Instrument your agent
Instrument a Vercel AI SDK agent with the AWS Distro for OpenTelemetry (ADOT). Add the AWS Distro Node autoinstrumentation package (@aws/aws-distro-opentelemetry-node-autoinstrumentation) to your dependencies. It includes the built-in Vercel AI instrumentation, which activates at startup and emits the scope name @aws/aws-distro-opentelemetry-instrumentation-vercel-ai.
package.json:
{ "dependencies": { "@aws/aws-distro-opentelemetry-node-autoinstrumentation": "^0.12.0" } }
The instrumentation follows the OpenTelemetry generative-AI semantic conventions: it classifies spans with gen_ai.operation.name and carries the conversation in gen_ai.* attributes.
Note
Instrumentation is one step in setting up observability. To export telemetry for evaluation, complete the full setup in Set up observability.
How spans are identified
The Vercel AI instrumentation sets the gen_ai.operation.name attribute on each span. The evaluation service uses this attribute to classify spans:
| Span type | Identifying attribute |
|---|---|
|
Invoke agent |
|
|
Execute tool |
|
|
Inference |
|
How evaluation fields are extracted
The Vercel AI SDK serializes messages in two shapes, and AgentCore Evaluations reads both:
-
An object-dict shape on the input of the invoke agent and inference spans, in which
gen_ai.input.messagesis a JSON object with asystemfield (the system prompt) and amessagesarray (for example,{"system": "…", "messages": [{"role": "user", "content": "…"}]}). -
A parts-list shape on the output, in which each message carries a
partsarray of typed content blocks (for example,[{"role": "assistant", "parts": [{"type": "text", "content": "…"}]}]).
AgentCore Evaluations pulls the text out of both shapes: the user prompt from the last user message in the input, the system prompt from the system field, and the agent response from the text parts of the output.
The Vercel AI instrumentation uses unified telemetry, so the conversation content stays on the span as attributes:
-
User prompt and agent response: from
gen_ai.input.messagesandgen_ai.output.messageson the invoke agent span. -
System prompt: from the
systemfield of the object-dict ingen_ai.input.messages. -
Tool call: the tool name from
gen_ai.tool.name, and the arguments and result fromgen_ai.tool.call.argumentsandgen_ai.tool.call.result, on the execute tool span.
For more information, see Example spans from a TypeScript agent.
Example spans from a TypeScript agent
With unified telemetry, the conversation content stays on the span attributes and no separate event record is produced. The following examples are from a TypeScript Vercel AI SDK travel-planning agent deployed on Amazon Bedrock AgentCore Runtime, using an Amazon Bedrock model.
Note
These examples are not complete spans. They show representative data from a real agent interaction, with some fields omitted and long values truncated for readability.