Skip to content

Observability Stack for LLM Applications: From Logs to Tracing

Cover: Observability Stack for LLM Applications: From Logs to Tracing When an LLM application moves beyond the notebook, the question arises: what is happening inside the system at any given moment? Without observability, it is impossible to understand why the model returned the wrong answer, how much each request costs, and where the bottleneck lies. In this article, I will break down the practical observability stack for LLM applications: from simple logging to full tracing with quality assessment.

Why Observability is Needed in LLM Systems

Classic server monitoring measures CPU, memory, and network. This is insufficient for LLM applications. The model is not a deterministic component: the same prompt can yield different responses. Therefore, observability must answer questions such as: - What prompt was sent and what response was received; - How many tokens were used and how much it costs; - How long each pipeline stage took; - How well does the response meet user expectations; - Were there data injections or leaks. Without answers to these questions, it is impossible to debug the system, optimize costs, and guarantee quality.

Observability Stack Components

The observability stack for LLM applications consists of four levels: | Level | What it measures | Tools | |---|---|---| | Logging | Prompts, responses, metadata | JSON logs, Langfuse, Helicone | | Tracing | Call chains, delays | Langfuse, LangSmith | | Metrics | Cost, tokens, errors | Dashboards, alerts | | Quality Assessment | Faithfulness, Answer Relevancy | RAGAS, LLM-as-a-Judge | Logging is the foundation. Without complete logs of requests and responses, it is impossible to reproduce problems. Tracing adds context: it shows which tools were called, which documents were retrieved, and which intermediate steps were performed.

Logging Prompts and Responses

The first step is to configure logging for all model requests. A minimal set of fields for the log:

{
  "timestamp": "2025-01-15T10:30:00Z",
  "request_id": "uuid-1234",
  "model": "deepseek-chat",
  "prompt": "...",
  "response": "...",
  "prompt_tokens": 120,
  "completion_tokens": 80,
  "total_tokens": 200,
  "latency_ms": 850,
  "cost_usd": 0.0012
}
It is important to log not only the final response but also intermediate steps: search results in RAG, calls to tools, system prompts. This allows reproducing system behavior during debugging. For storing logs, a regular database or object storage can be used. The key is to ensure fast searching by request_id and time range.

Call Tracing

Tracing shows the full path of the request through the system. In an LLM application, this can be a chain: user request → semantic router → model selection → RAG pipeline → response generation. Tracing schema:

graph TD
    A[User Request] --> B[Semantic Router]
    B --> C[Model A]
    B --> D[Model B]
    C --> E[Vector DB Search]
    E --> F[Response Generation]
    D --> F
    F --> G[Response to User]
Tracing tools automatically record the time of each step, the number of tokens, and errors. This allows finding bottlenecks: for example, if 90% of the time is spent on vector database search rather than generation.

Cost and Performance Metrics

Cost metrics are critical for LLM applications. Each request has a cost, depending on the model and the number of tokens. Without metrics, it is impossible to control the budget. Key metrics: - request cost in dollars; - number of tokens per request; - time to first token; - tokens per second; - percentage of errors and timeouts; - number of requests per minute. These metrics need to be aggregated by models, users, and request types. For example, you can discover that 5% of users generate 50% of the cost—this is an opportunity for optimization.

Quality Assessment of Responses

Performance metrics do not show the quality of responses. For this, a separate assessment is needed. In production, two approaches are used: 1. Automated assessment — LLM-as-a-Judge or metrics RAGAS: faithfulness, answer relevancy, context precision. 2. User assessment — like/dislike buttons, feedback collection. Automated assessment does not replace human assessment but allows detecting quality degradation. For example, if the faithfulness metric drops from 0.9 to 0.7, it is a signal to check embeddings or chunks.

Practical Implementation

For a small project, a combination of JSON logs in a file + a script for aggregating metrics is sufficient. For production systems, it is better to use ready-made platforms: Langfuse or Helicone. They provide dashboards, alerts, and tracing out of the box. Example alert setup: if the request cost exceeds $0.05 or latency is more than 5 seconds — send a notification to Telegram. This allows quickly reacting to anomalies. Observability is not a one-time task but a continuous process. The stack needs to be developed alongside the application: adding new metrics, refining alerts, analyzing trends. Without this, an LLM system remains a black box that cannot be controlled.