Guides · Artificial intelligence

LLM monitoring and AI agent observability with OpenTelemetry

An application that uses a large language model (LLM) fails differently from a traditional one. It can answer fast and without errors, and still answer badly or cost ten times more than yesterday. This guide lays out what to measure and how to do it with OpenTelemetry, which already has conventions for generative AI.

By the OneGlass team · December 3, 2026 · 8 min read

What is different

  • Cost is per use and varies with every request. You pay per token, and a longer prompt or an agent that takes more turns changes the bill without any change in traffic.
  • Latency is high and uneven. A response can take from one to thirty seconds depending on how much text it generates.
  • It is not deterministic. The same question can get different answers. "It worked" is not enough: you have to look at what it answered.
  • Agents chain steps. One user request can be ten calls to the model and fifteen to tools. When something goes wrong, you need to know at which step.
  • It depends on a third party. The model provider has its own rate limits, outages and version changes.

What to measure

1. Latency

Two numbers, not one. The total time of the call and the time to first token, which is what the user perceives when the response is shown as it arrives. Look at both by model and by operation, and in percentiles: the average hides the long responses.

2. Tokens and cost

Input and output tokens per call, by model and by feature of your product. Cost is computed by multiplying by each model's price. Input tokens read from cache cost less: if your provider reports them, measure them separately, because they explain cost jumps that traffic doesn't.

3. Errors, and how each response ended

Besides the classic errors (timeout, rate limit exceeded, provider down), every response comes with a finish reason. A response that ends because it hit the maximum tokens is cut off. One that ends because of a content filter didn't answer. Neither is an HTTP error, and both are a problem for the user.

4. Tools

In an agent, tools are where most things fail: malformed arguments, an API that doesn't respond, a result the model couldn't use. Measure how many times each tool is called, how long it takes and how many times it fails.

5. Agent runs

How many steps each run takes, how many finish well and how many get stuck going in circles. An agent that repeats the same tool with the same arguments is the most common way to burn tokens without making progress.

6. Quality

The hardest one and the one that matters most. The practical signals are user ratings, how often users rephrase the same question, and automated evaluations on a sample of responses. All of them need a way to go from a bad number to the specific conversation.

What it looks like in OpenTelemetry

OpenTelemetry defines conventions for generative AI under the gen_ai.* prefix. Every call to a model is a span, just like an HTTP call or a database query, and it sits inside the same trace as the user request that caused it.

There are three span types worth knowing. The name of each is the operation followed by the model, tool or agent:

  • chat {model}: a call to the model.
  • execute_tool {tool}: the agent runs a tool.
  • invoke_agent {agent}: a run of an agent, which contains the other two.

This is what a model call looks like:

span
name:   chat gpt-4o-mini
kind:   CLIENT

gen_ai.operation.name          = "chat"
gen_ai.provider.name           = "openai"
gen_ai.request.model           = "gpt-4o-mini"
gen_ai.response.model          = "gpt-4o-mini-2024-07-18"
gen_ai.usage.input_tokens      = 1840
gen_ai.usage.output_tokens     = 212
gen_ai.response.finish_reasons = ["stop"]
gen_ai.conversation.id         = "conv_5j66UpCpwteGg4YSxUnt7lPY"
error.type                     = (only if it failed)

And the attributes specific to tools and agents: gen_ai.tool.name, gen_ai.tool.call.id, gen_ai.agent.name and gen_ai.agent.id.

There are also standard metrics, among them gen_ai.client.operation.duration for the duration of each operation and gen_ai.server.time_to_first_token for the time to first token.

A warning: they are still in development

The gen_ai.* conventions are not stable. The names have already changed more than once: the provider attribute used to be gen_ai.system and is now gen_ai.provider.name, and the token metrics were renamed too. Note which version each library emits, and review your dashboards when you update it.

How to instrument

  • Instrumentation libraries: they exist for the most-used model provider clients and for agent frameworks. You add them at startup, like any OpenTelemetry auto-instrumentation.
  • Frameworks that already emit: several agent frameworks ship with instrumentation built in. You only need to configure where to export.
  • By hand: if you call the model with your own HTTP client, create the span yourself with the attributes above. There are few of them and it is worth it.

In every case the destination is standard OTLP: the same Collector and the same platform you use for the rest of your telemetry.

The content of conversations

Prompts, questions and responses are not captured by default. The conventions define attributes for them (gen_ai.input.messages, gen_ai.output.messages, gen_ai.system_instructions), but you have to turn them on deliberately, and for good reason: personal data, internal information and sometimes credentials that someone pasted into a question travel there.

Before turning them on, decide three things:

  • Where: in development and testing, almost always. In production, only if you need it to debug or evaluate.
  • What gets masked: IDs, emails, phone numbers, cards. You can do this in the Collector, before the data leaves your network.
  • How long it is kept and who can read it. A conversation with a customer's data deserves the same care as any other personal data.

The conventions also let you store the content elsewhere and leave only a reference in the span. It is the cleanest option when the content is large or sensitive.

Common mistakes

  • Measuring only latency and HTTP errors. Cut-off, filtered or bad responses don't show up there.
  • Adding up tokens without splitting by model. A million tokens costs very differently depending on which model processed them.
  • Using the conversation ID as a metric attribute. That is millions of distinct values. It goes in traces, not in metrics.
  • Leaving model calls out of the request's trace. Without that relationship, you can't tell which product feature generated the spend.
  • Turning on content capture in production without masking. It is the fastest way to end up with personal data in a system that wasn't designed to hold it.

With OneGlass

OneGlass is an OpenTelemetry-native observability platform, made in Argentina. The Applications › AI Agents screen reads the gen_ai.* conventions, so agents that use them show up with no extra configuration: whether the model is responding, tokens, failed calls grouped by reason, a map of which agent calls which model and which tool, and each run step by step.