LLM Observability

Last updated:

LLM observability is the practice of recording what your LLM application does on every request (prompts, model responses, retrieval results, tool calls, latency, token usage, and cost) as structured traces, and using that data to debug failures, measure quality, and monitor production behavior. LLM applications are non-deterministic, so the same input can produce different outputs. Logs and uptime metrics cannot tell you why an answer was wrong. A trace can.

MLflow Tracing is an open source way to get LLM observability. One line of code captures every LLM call, and the MLflow UI lets you search traces, inspect each step, track token cost, and score quality with LLM judges. It is compatible with OpenTelemetry, works with any LLM provider or agent framework, and stores your data where you choose. This page covers how LLM observability works and how to set it up. For a deep dive into the tracing layer itself, see LLM tracing.

MLflow Traces page listing LLM requests with input, output, duration, token count, and LLM judge scores for correctness, groundedness, relevance, and safety
The MLflow Traces page: every request with its input, output, latency, tokens, and quality scores. Demo data.

Quick Navigation:

What Is LLM Observability?

Traditional observability answers "is the service up and how fast is it?" LLM observability adds the questions that matter for language model applications: what exactly did the model see, what did it return, which documents were retrieved, which tools were called, how many tokens did it cost, and was the answer any good?

It is built on traces. A trace is the record of one request through your application. It is made of nested spans, one per step: an LLM call, a retrieval, a tool call, or a function of your own. Each span stores its inputs, outputs, timing, and attributes such as model name and token counts. Reading a trace top to bottom shows what the application did and where it went wrong.

PracticeQuestion it answersMain data
LLM observabilityWhy did the application behave this way?Traces with spans, inputs, outputs, tokens
LLM monitoringDid something change in production?Aggregated latency, errors, cost, quality scores
LLM evaluationIs the output good enough?Scores from LLM judges, code checks, and human feedback

The three work as a loop. Traces give evaluation realistic data to score, evaluation turns traces into quality signals, and monitoring watches those signals over time and points you back to the traces that need attention.

What Should You Capture in an LLM Application?

A useful trace records more than the final answer. These are the signals that explain most production problems:

Prompts and responses

The full input and output of every LLM call, including system prompts, parameters such as temperature, and the model name.

Intermediate steps

Retrieved documents, tool calls with their arguments and results, and agent decisions, recorded as nested spans.

Latency, tokens, and cost

Time spent in each step, input and output token counts, and cost per request, so you can find slow or expensive steps.

Errors and context

Exceptions with the span that raised them, plus user, session, and application version so you can filter and compare.

How Do You Set Up LLM Observability with MLflow?

Start an MLflow tracking server (mlflow server), then enable automatic tracing for your LLM library. MLflow supports one-line tracing for many providers and frameworks, including OpenAI, Anthropic, LangChain, LangGraph, LlamaIndex, CrewAI, and DSPy.

python
import mlflow
from openai import OpenAI
mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment("my-llm-app")
# One line: every OpenAI call is now captured as a trace
mlflow.openai.autolog()
client = OpenAI()
client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "What is LLM observability?"}],
)

Automatic tracing covers library calls. For your own logic, such as retrieval, business rules, or custom tools, add the @mlflow.trace decorator or wrap a block in mlflow.start_span(). The two approaches combine into a single trace.

python
import mlflow
from mlflow.entities import SpanType
@mlflow.trace(span_type=SpanType.RETRIEVER)
def retrieve(query: str) -> list[str]:
return search_index(query) # your retrieval code
@mlflow.trace
def answer(question: str) -> str:
docs = retrieve(question)
# Add a custom span around any block of code
with mlflow.start_span(name="build_prompt") as span:
prompt = f"Context: {docs}\n\nQuestion: {question}"
span.set_inputs({"question": question, "num_docs": len(docs)})
return call_llm(prompt) # auto-traced if you enabled autolog

To make traces searchable by who and what produced them, attach session, user, and tags to the current trace. In the UI you can then filter to one customer, one conversation, or one app version.

python
import mlflow
@mlflow.trace
def chat(message: str, session_id: str, user_id: str) -> str:
# Group traces by conversation and user so you can filter by them later
mlflow.update_current_trace(
session_id=session_id,
user=user_id,
tags={"app_version": "2.3.1", "environment": "production"},
)
return run_agent(message)

See the tracing quickstart for a complete walkthrough, or manual tracing for the full decorator and span API.

How Do You Debug LLM Applications with Traces?

Open any trace in the MLflow UI to see the span tree on the left and the inputs, outputs, and attributes of the selected span on the right. Typical questions this answers in minutes:

  • Why was the answer wrong? Check whether the retrieval span returned relevant documents or the model ignored good context.
  • Why is this request slow? Compare the duration of each span to find the slow LLM call, tool, or retrieval.
  • Why did the agent loop or pick the wrong tool? Read the sequence of tool calls and the arguments passed to each.
  • What changed since last week? Filter traces by app version tag and compare them.
MLflow trace detail view showing an agent trace with nested spans for LLM calls and tool calls, with duration, token count, and cost per span
A trace in the MLflow UI: nested spans for each LLM and tool call, with duration, tokens, and cost per step. Demo data.

How Do You Track LLM Token Usage, Cost, and Latency?

MLflow records token counts on LLM spans and rolls them up to the trace. Cost in USD is calculated from token usage and model pricing when the model has a known price. Both are available in code and charted in the experiment Overview dashboard, along with request volume, latency percentiles, and error rates.

python
import mlflow
trace = mlflow.get_trace(mlflow.get_last_active_trace_id())
print(trace.info.token_usage) # input_tokens, output_tokens, total_tokens
print(trace.info.cost) # input_cost, output_cost, total_cost in USD
MLflow experiment Overview dashboard with charts for trace volume, latency percentiles, errors, token usage, and tokens per trace
The MLflow Overview dashboard: trace volume, latency, errors, and token usage over time. Demo data.

Token usage and cost depend on what the provider returns, so some models report no usage. See token usage and cost tracking and the dashboard guide for details. To enforce rate limits and budgets rather than only observe spend, see the AI Gateway.

How Do You Monitor LLM Output Quality?

Latency and cost are easy to measure. Quality is the hard part, and observability is what makes it measurable: once requests are traces, you can run LLM judges over them. Pass traces to mlflow.genai.evaluate() with built-in scorers such as Safety and RelevanceToQuery, or write custom judges for your own criteria.

python
import mlflow
from mlflow.genai.scorers import Safety, RelevanceToQuery
# Pull recent production traces...
traces = mlflow.search_traces(
experiment_ids=["<your-experiment-id>"],
max_results=100,
return_type="list",
)
# ...and score them with built-in LLM judges
results = mlflow.genai.evaluate(
data=traces,
scorers=[Safety(), RelevanceToQuery()],
)

You can also configure judges to score a sample of production traces automatically, so quality shows up next to latency and cost. Add human feedback to the same traces to calibrate the judges. See LLM evaluation and automatic evaluations.

How Do You Run LLM Observability in Production?

Tracing should not slow down or destabilize your application. For production deployments:

  • Async logging. MLflow exports traces asynchronously by default in OSS deployments, so requests are not blocked on the tracking server.
  • Sampling. Set MLFLOW_TRACE_SAMPLING_RATIO to a value below 1.0 to export only a fraction of traces for high-volume services.
  • Lightweight SDK. The production tracing SDK keeps the dependency footprint small.
  • Privacy. Mask sensitive fields before traces are stored. See masking.
  • Open standards. Because MLflow Tracing is OpenTelemetry-compatible, traces can flow to and from the rest of your observability stack.

The full checklist is in the production tracing guide.

What Are the Best LLM Observability Tools and Platforms?

The best LLM observability platform for your team is one that traces your stack with little code, speaks open standards, lets you own your data, and connects traces to quality. MLflow is an open source LLM observability platform that does all four. When comparing any tools, these questions matter most:

  • Coverage. Does it trace your LLM providers and agent frameworks with minimal code?
  • Standards. Does it speak OpenTelemetry, so you are not locked into one vendor's SDK and format?
  • Data ownership. Can you self-host and keep prompts and responses in your own infrastructure?
  • Quality, not just logs. Does it connect traces to evaluation, human feedback, and monitoring?
  • Cost. What does it cost at your trace volume?

MLflow is Apache 2.0 licensed and hosted by the Linux Foundation, so you can run it yourself at no license cost. For side-by-side comparisons, see the top agent observability tools, or the Langfuse, LangSmith, and Arize Phoenix comparisons.

Frequently Asked Questions

LLM observability is the practice of recording what an LLM application does on every request (prompts, model responses, retrieval results, tool calls, latency, token usage, and cost) as structured traces, then using that data to debug failures, measure output quality, and monitor production behavior. It matters because LLM applications are non-deterministic: the same input can produce different outputs, so logs and uptime metrics alone cannot explain why an answer was wrong.

Related Resources