Online evaluations never throw errors into your app’s code. Scorer failures are recorded on the eval span as OTel events, so a broken scorer won’t affect your capability’s response.
Prerequisites
- Follow the procedure in Quickstart to set up Axiom AI SDK in your TypeScript project.
- Wrap your AI model with
wrapAISDKModelfor automatic tracing. See Instrumentation with Axiom AI SDK for details.
Import evaluation functions
ImportonlineEval and Scorer from the Axiom AI SDK and add onlineEval to the withSpan callback:
Write scorers
Online evaluations use the sameScorer API as offline evaluations. The key difference is that online scorers are reference-free: they receive input and output but no expected value. For the full Scorer API reference including return types, patterns, and LLM-as-judge examples, see Scorers.
Here’s a quick example of an online scorer that validates output format:
Sampling
Use sampling to control the percentage of production traffic that gets evaluated. You can set different sampling for each scorer. This is useful for expensive scorers like LLM judges while letting cheap heuristic scorers run on every request. Wrap a scorer in{ scorer, sampling } to control the percentage of production traffic it evaluates. You can mix sampled and unsampled scorers in the same call. Scorers without a sampling wrapper run on every request.
sampling value to a synchronous or asynchronous function that receives { input, output } and returns a Boolean (or Promise<boolean>) for conditional sampling logic. This is useful when the sampling decision depends on an async lookup such as a feature flag service.
Connect to traces
Online evaluations create OTel spans that link back to the originating generation span. The linking mechanism depends on where you callonlineEval.
Inside withSpan (recommended)
When called inside withSpan, the active span is automatically detected and linked. The eval span becomes a child of the withSpan span.
Deferred evaluation
For cases where you want to evaluate afterwithSpan returns, capture span.spanContext() and pass it as links:
Awaitable for short-lived processes
In CLI tools or serverless functions,await the eval to ensure spans are created before flushing telemetry:
void onlineEval(...) (fire-and-forget) instead — the telemetry pipeline flushes spans in the background.
Telemetry reference
Each call toonlineEval creates a parent eval span with one child span per scorer.
Span naming
For the full list of scorer span attributes, see Scorers: Telemetry.
Complete example
This example shows a production support agent that uses online evaluations to monitor message categorization quality:What’s next?
- Learn about the GenAI attributes that your AI spans emit.
- Set up user feedback for human-in-the-loop signals.
- Write offline evaluations to test against known-good answers before shipping.
- Use production insights to iterate on your capabilities.