Logs and Observability
Logs and observability refer to making the internal state of a system inferable from the outside through three kinds of signals: logs, metrics, and traces. It is not only a tool for "finding the cause after a problem occurs" but also a dashboard for judging daily whether the system is healthy, directly determining the speed of fault discovery and the cost of localization.
Core Principles
Observability is built on three kinds of data: logs record discrete events and answer "what happened"; metrics are aggregated numerical time series and answer "what is the overall trend"; trace tracking strings together the various services a request passes through and answers "which segment is slow." The three complement each other; lacking any one leads to one-sided judgment: logs alone get drowned by volume, metrics alone do not reveal the specific cause, and traces alone do not show contextual detail.
In AI applications there is a special dimension: the nondeterminism of model calls themselves. The same request may behave differently because of sampling, upstream rate limiting, or different context lengths, so logs must retain enough call context, otherwise the problem cannot be reproduced. This requires log design to shift from "what was printed" to "what questions will need to be answered later."
Key Points
First, structured logs are the foundation. Output in a machine-parseable format such as JSON, with fields including time, level, service name, request identifier, user identifier, elapsed time, error code, and key business parameters. Avoid string concatenation that stuffs information into a sentence, which is both hard to search and hard to aggregate. Field naming must be uniform, using the same conventions across services, otherwise queries require repeated trial and error between multiple spellings. Sensitive information must be masked, since prompts and user input often contain private data.
Second, log levels need discipline. Reserve the error level for problems that require human handling; logging expected business failures (such as failed parameter validation) as errors leads to alert fatigue, until everyone becomes numb to alerts. Debug-level logs are off by default and dynamically enabled per request when needed. In production keep warnings and errors, record milestones at info level for key flows, rather than logging every function entry and exit.
Third, trace tracking solves cross-service attribution. Generate a trace identifier for each inbound request and propagate it to all downstream calls, including model APIs, caches, databases, and external services. Then a slow request shows the proportion of time spent in each segment, quickly indicating whether the bottleneck is in retrieval, inference, or network. Sampling strategy must be designed: full sampling is costly, so sample all errors and a proportion of normal requests. Without traces, troubleshooting cross-service problems often comes down to guessing from timestamps.
Fourth, alert thresholds should be based on business impact rather than purely technical metrics. Prioritize alerting on rising error rates, key API latency exceeding budget, and sustained queue backlog growth, rather than alerting when CPU reaches eighty. All alerts should be configured with suppression and aggregation to avoid dozens of notifications from a single incident. Each alert should include a troubleshooting entry point: which dashboard to look at, which trace to check, whom to contact.
Fifth, logs themselves need cost awareness. A surge in log volume often occurs earlier than a fault; set ingestion caps, retention periods, and hot-cold tiering to avoid disk exhaustion causing cascading failures.
Common Misconceptions
Misconception one: logs are all free text, so when a problem occurs they cannot be filtered by field. Misconception two: logging all exceptions at error level, so alerts lose their signal value. Misconception three: monitoring only machine metrics and not business metrics, so the service is already returning many errors while the monitoring dashboard is still all green.
Application Scenarios
Latency analysis of inference services, attribution of model call failures, performance localization of retrieval pipelines, post-incident review of online faults, capacity planning, cost and usage statistics, and security audit tracing.