The AI SDK emits OpenTelemetry spans for every generateText, streamText and ToolLoopAgent call. Register its telemetry once, pass your chat id on each call, and Maple groups the spans into one agent session per conversation.
npm install ai@^7.0.106 @ai-sdk/otel @opentelemetry/sdk-node export OTEL_SERVICE_NAME="support-agent"
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=production"
export OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.maple.dev"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_INGEST_KEY" // instrumentation.ts: import it first in your entry point
import { OpenTelemetry } from "@ai-sdk/otel"
import { NodeSDK } from "@opentelemetry/sdk-node"
import { registerTelemetry } from "ai"
// Reads OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES and OTEL_EXPORTER_OTLP_*
export const sdk = new NodeSDK()
sdk.start()
registerTelemetry(
new OpenTelemetry({
usage: true,
runtimeContext: true,
}),
) import { streamText } from "ai"
const result = streamText({
model,
messages,
runtimeContext: { conversationId: chatId },
telemetry: { functionId: "support_agent", includeRuntimeContext: { conversationId: true } },
}) This is the short path. The full Vercel AI SDK guide covers the rest.
Organization in the EU region? Send to https://ingest.eu.maple.dev instead of https://ingest.maple.dev. An ingest key only works in its own region.
What you get
Calls that share a conversation id form one agent session, with one turn per call.
Each turn shows the prompts, the replies and the tool calls in the order they ran.
functionId becomes the agent name, so two agents in one app stay apart. Sub-agents called from a tool keep their own functionId.
usage: true records input and output tokens per model call. Cost shows as unpriced, because the AI SDK does not report it.
A tool that throws from execute is marked as failed on its span. A tool that returns an error value looks successful.
Set recordInputs: false and recordOutputs: false on a call to keep its prompts and replies out of Maple.
In AI SDK 7, experimental_telemetry alone does nothing. Call registerTelemetry() once at startup; a second call emits every span twice.
It has no per-call runtimeContext. Declare conversationId in callOptionsSchema and map it to runtime context in prepareCall.
A stream's spans end when it is read to the end. Return the stream as the response, and call forceFlush() in a finally block in serverless handlers.
SDKを追加し、OTLPエクスポーターをMapleに向ければトレースが届きます。
maple.dev:OpenTelemetryの上のオブザーバビリティ