Early-bird price on the GenAI & Agentic AI Engineer Bootcamp batch. Grab a seat →

Trace every model call and every tool call as its own span, and record the model, token counts, latency, finish reason, prompt version and any error on it. Alert on error rate, latency, token usage and quality scores. Leave prompt and response text out of telemetry unless you have made a deliberate decision to capture it, because that text is where personal data lives.

This article is part of the LLMOps guide, which explains how observability fits with evaluation, cost control and release management.

Key takeaways

  • One user request should produce one trace: a parent span, a span for each model call and a span for each tool call.
  • The OpenTelemetry generative AI conventions give you standard attribute names, but they are still marked "Development" and several names changed in November 2026.
  • Message content, system instructions, tool arguments and tool results are opt-in attributes in the conventions. Off is the safe default.
  • Record the prompt name and version on every span, or you cannot tell which release caused a change.
  • Useful alerts watch rates and ratios (errors, cache hits, tokens per request), not single requests.

What should a trace of an LLM request contain?

A span is a timed record of one unit of work, and a trace is the tree of spans for one request. For an LLM application the tree usually has three levels.

A stack of four layers in an LLM trace: the request span, the agent or workflow span, model inference spans and tool execution spans.

Without the parent span you cannot see that one user question triggered six model calls, which is a common explanation for a slow or expensive request.

What do the OpenTelemetry GenAI conventions define today?

OpenTelemetry is a vendor-neutral standard for traces, metrics and logs. Its semantic conventions are agreed attribute names, so different libraries and backends describe the same thing the same way. The generative AI conventions stood as follows in late November 2026.

  • Status. They are marked "Development", not stable.
  • Location. The pages on opentelemetry.io now say the conventions have moved to a separate repository, open-telemetry/semantic-conventions-genai. Its first standalone release, v0.1.0, is dated 21 November 2026.
  • Breaking changes in that release. Among others: the gen_ai.client.token.usage histogram was replaced by gen_ai.client.inference.operation.input_tokens and gen_ai.client.inference.operation.output_tokens; inference duration moved from gen_ai.client.operation.duration to gen_ai.client.inference.duration; and gen_ai.usage.cache_creation.input_tokens was renamed gen_ai.usage.cache_write.input_tokens.

So an upgrade of an instrumentation library can rename the metrics your dashboards query. Pin the version and read the changelog before upgrading.

The core definitions for a model call are these.

ItemWhat the convention says
Span name{gen_ai.operation.name} {gen_ai.request.model}, for example chat claude-sonnet-5-5
Span kindCLIENT (or INTERNAL for a model running in the same process)
Required attributesgen_ai.operation.name, gen_ai.provider.name
Required on failureerror.type
Recommendedgen_ai.request.model, gen_ai.response.model, gen_ai.response.id, gen_ai.response.finish_reasons, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens
When a named prompt template is usedgen_ai.prompt.name, gen_ai.prompt.version
Opt-in (sensitive)gen_ai.input.messages, gen_ai.output.messages, gen_ai.system_instructions, gen_ai.tool.definitions

A tool call gets a span named execute_tool {gen_ai.tool.name} with kind INTERNAL. gen_ai.tool.name is required; gen_ai.tool.call.arguments and gen_ai.tool.call.result are opt-in. Metrics are defined too, including the duration histograms gen_ai.client.inference.duration and gen_ai.execute_tool.duration.

How do you instrument a model call?

Instrumentation libraries can create these spans for you; check which version of the conventions a library emits. Doing it by hand takes little code. The example uses the OpenTelemetry Python SDK and the Anthropic Python SDK.

import anthropic
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
from opentelemetry.trace import SpanKind

provider = TracerProvider()
provider.add_span_processor(BatchSpanProcessor(ConsoleSpanExporter()))
trace.set_tracer_provider(provider)
tracer = trace.get_tracer("support-bot.llm")

client = anthropic.Anthropic()
MODEL = "claude-sonnet-5-5"

def answer(question, system_prompt, prompt_version):
    request_attributes = {
        "gen_ai.operation.name": "chat",
        "gen_ai.provider.name": "anthropic",
        "gen_ai.request.model": MODEL,
        "gen_ai.request.max_tokens": 1024,
        "gen_ai.prompt.name": "support-answer",
        "gen_ai.prompt.version": prompt_version,
    }
    with tracer.start_as_current_span(
        f"chat {MODEL}", kind=SpanKind.CLIENT, attributes=request_attributes
    ) as span:
        try:
            response = client.messages.create(
                model=MODEL,
                max_tokens=1024,
                system=system_prompt,
                messages=[{"role": "user", "content": question}],
            )
        except Exception as exc:
            span.set_attribute("error.type", type(exc).__name__)
            raise

        usage = response.usage
        cache_read = usage.cache_read_input_tokens or 0
        cache_write = usage.cache_creation_input_tokens or 0
        span.set_attribute("gen_ai.response.model", response.model)
        span.set_attribute("gen_ai.response.id", response.id)
        span.set_attribute("gen_ai.response.finish_reasons", [response.stop_reason])
        span.set_attribute(
            "gen_ai.usage.input_tokens", usage.input_tokens + cache_read + cache_write
        )
        span.set_attribute("gen_ai.usage.output_tokens", usage.output_tokens)
        if cache_read:
            span.set_attribute("gen_ai.usage.cache_read.input_tokens", cache_read)
        if cache_write:
            span.set_attribute("gen_ai.usage.cache_write.input_tokens", cache_write)
        return response.content[0].text

Three details are easy to get wrong.

  • Token totals. The convention says cached tokens should be included in gen_ai.usage.input_tokens. Anthropic's input_tokens field counts only the tokens after the last cache breakpoint, so the total is the sum of input_tokens, cache_read_input_tokens and cache_creation_input_tokens. Record the provider's field alone and your dashboards will under-report whenever caching is on.
  • Errors. start_as_current_span records an exception and sets the span status to error by default. You still have to set error.type yourself.
  • Exporter. ConsoleSpanExporter prints spans to standard output. In production you replace it with an exporter that sends spans to your tracing backend.

What should you log, and what should you leave out?

Record these on every call. They are small and hold no user content:

  • model requested and model that responded
  • input, output and cached token counts
  • duration, and time to first chunk for streaming responses
  • finish reason (a response cut off by the token limit looks like a success otherwise)
  • prompt name and version
  • error type, and the provider's request ID for support tickets
  • a conversation or session identifier (gen_ai.conversation.id) that is not itself personal data

Leave these out unless you have a reason and a control for each:

  • Prompt and response text. The conventions mark gen_ai.input.messages and gen_ai.output.messages as opt-in and warn that they are likely to contain sensitive information including personal data.
  • Tool arguments and results. A tool that looks up a customer returns that customer's record, and it would then sit in your tracing backend.
  • System instructions, tool definitions and template variables. Also opt-in. They can hold internal business rules or the user's own details.
  • Credentials. API keys and tokens never belong in span attributes or logs.

Debugging a bad answer does need the text. The conventions offer a middle path: reference attributes such as gen_ai.input.messages_ref hold a URI to content stored elsewhere, so the text can sit in storage with its own access rules and retention period while the trace carries only a pointer. If you do capture content, redact before storing, restrict who can read it and set a short retention period.

Which alerts are worth having?

SignalWhy it mattersSource
Error rate by error.typeSeparates rate limiting (429) from provider overload (529) and timeouts, which need different responsesInference spans
Latency percentilesModel latency varies far more than a database call doesgen_ai.client.inference.duration
Input tokens per requestA rising median means context is growing: longer history, more retrieved text, new tool definitionsgen_ai.client.inference.operation.input_tokens
Share of responses stopped by the token limitUsers are receiving truncated answersgen_ai.response.finish_reasons
Cache read ratioA drop usually means someone changed the start of the prompt, and cost rises with itCache read tokens divided by input tokens
Cost per requestComputed from token counts and your price table; catches regressions the same dayDerived metric
Quality score on sampled trafficThe only signal that notices wrong answersA judged sample; see LLM evaluation in CI

Group every chart by prompt version and model. A latency or cost change that lines up with a prompt release is diagnosed in minutes. Without the version label it takes a day. The article on prompt versioning covers how to produce that label, and how to reduce LLM costs explains the cache metrics.

What are the limits of this approach?

Telemetry tells you a request was slow, expensive or failed. It does not tell you an answer was wrong, because a wrong answer has normal latency, token counts and finish reason. Quality needs evaluation on a sample of production traffic.

Sampling has a cost too. Keeping every trace is expensive at volume, but the request you most want to inspect is the rare bad one. A common compromise is to record metrics for every call and keep full traces for a fraction, plus every trace that ended in an error.

Common questions

Do I need a specialised LLM observability tool?

Not necessarily. Any backend that accepts OpenTelemetry traces can store these spans. Specialised tools add views for conversations, prompt comparisons and evaluation scores, which become useful when non-engineers need to read the traces.

Are the OpenTelemetry GenAI conventions safe to build on?

Yes, with care. They are the closest thing to a shared standard, but they are in Development status and names changed in November 2026. Pin your instrumentation version and treat attribute names in dashboards as code that needs maintenance.

How do I trace a streaming response?

Keep the span open until the stream ends, then set the usage attributes. The conventions define gen_ai.response.time_to_first_chunk on the span and a matching metric, gen_ai.client.inference.time_to_first_chunk, for how long the user waited for the first output.

Free download: LLM cost and latency worksheet

Estimate monthly LLM spend and cost per successful task. Includes a worked example and CSV for comparing model, volume, quality, and latency scenarios. See what’s inside.

LLMOps: how to run LLM applications in production

What changes when you operate an LLM application: prompt and model versions, evaluations, tracing, cost per request and provider limits, with a minimum setup checklist.

Prompt versioning: treating prompts like code

How to keep prompts in the repository, review them like code, tie each version to a model and its evaluation results, label traces, and roll back safely.