Pre-requisite: Setting up instrumentation
The Axiom AI SDK is built on the OpenTelemetry standard. To send traces, you need to configure a Node.js or edge-compatible tracer that exports data to Axiom.Configuring the tracer
You must configure an OTLP trace exporter pointing to your Axiom instance. This is typically done in a dedicated instrumentation file that’s loaded before your app starts.AXIOM_TOKEN
and AXIOM_DATASET
environment variables in your .env
file.
Capturing Gen AI telemetry with Axiom’s AI SDK
The foundation of the Observe stage is Axiom’s SDK, which integrates with your app to capture detailed OpenTelemetry traces for every AI interaction.The initial release of Axiom’s AI SDK is focused on providing deep integration with TypeScript applications, particularly those using Vercel’s AI SDK to interact with frontier models.
Instrumenting AI SDK calls
The easiest way to get started is by wrapping your existing AI model client. Axiom’s AI SDK provides helper functions for popular libraries like Vercel’s AI SDK. ThewrapAISDKModel
function takes an existing AI model object and returns an instrumented version that will automatically generate trace data for every call.
Adding context with withSpan
While wrapAISDKModel
handles the automatic instrumentation, the withSpan
function allows you to add crucial business context to your traces. It creates a parent span around your LLM call and attaches metadata about the capability
and step
being executed.
Instrumenting tool calls with wrapTool
For many AI capabilities, the LLM call is only part of the story. If your capability uses tools to interact with external data or services, observing the performance and outcome of those tools is critical. The Axiom AI SDK provides the wrapTool
and wrapTools
functions to automatically instrument your Vercel AI SDK tool definitions.
The wrapTool
helper takes your tool’s name and its definition and returns an instrumented version. This wrapper creates a dedicated child span for every tool execution, capturing its arguments, output, and any errors.
Complete instrumentation example
Full end-to-end code example
Full end-to-end code example
Here’s how all three instrumentation functions work together in a single, real-world example:This demonstrates the three key steps to rich observability:
wrapAISDKModel
: Automatically captures telemetry for the LLM provider callwrapTool
: Instruments the tool execution with detailed spanswithSpan
: Creates a parent span that ties everything together under a business capability
Understanding your AI telemetry
Once instrumented, every LLM call will send a detailed span to your Axiom dataset. These spans are enriched with standardizedgen_ai.*
attributes that make your AI interactions easy to query and analyze.
Key attributes include:
gen_ai.capability.name
: The high-level capability name you defined inwithSpan
.gen_ai.step.name
: The specific step within the capability.gen_ai.request.model
: The model requested for the completion.gen_ai.response.model
: The model that actually fulfilled the request.gen_ai.usage.input_tokens
: The number of tokens in the prompt.gen_ai.usage.output_tokens
: The number of tokens in the generated response.gen_ai.prompt
: The full, rendered prompt or message history sent to the model (as a JSON string).gen_ai.completion
: The full response from the model, including tool calls (as a JSON string).gen_ai.response.finish_reasons
: The reason the model stopped generating tokens (e.g.,stop
,tool-calls
).gen_ai.tool.name
: The name of the executed tool.gen_ai.tool.arguments
: The arguments passed to the tool (as a JSON string).gen_ai.tool.message
: The result returned by the tool (as a JSON string).
Visualizing traces in the console
Visualizing and making sense of this telemetry data is a core part of the Axiom Console experience.- A dedicated AI Trace Waterfall view will visualize single and multi-step LLM workflows, with clear input/output inspection at each stage.
- A pre-built Gen AI OTel Dashboard will automatically appear for any dataset receiving AI telemetry. It will feature elements for tracking cost per invocation, time-to-first-token, call counts by model, and error rates.