Skip to content
Back to log

Observability: logs, metrics, and traces

Chainabit's Chao · · 8 min read

In short

Learn what log, metric, and trace data record, how spans represent a request, and where the limits of monitoring data lie.

Observability and telemetry

OpenTelemetry defines observability as the ability to understand a system from the outside by asking questions about it, without knowing its inner workings. This ability helps troubleshoot problems that have not been encountered before and understand why an incident happened.

According to OpenTelemetry, for these questions to be answerable, the application must produce data through instrumentation. Application code emits signals such as traces, metrics, and logs. OpenTelemetry is the mechanism that instruments application code so that a system can become observable.

Telemetry is the data a system and its behavior produce. OpenTelemetry notes that this data can take the form of traces, metrics, or logs. A metric aggregates numerical data about infrastructure or an application over a period of time. A log is a timestamped message. A trace records the path a single request takes across multiple services.

Metrics: numerical data over time

OpenTelemetry's metric examples include a system's error rate, CPU utilization, and the rate of requests to a given service. This data is an aggregation of numerical measurements about infrastructure or an application over a period of time.

OpenTelemetry describes reliability as whether a service does what its users expect it to do. In its example, even if the system is continuously available, when a user wants to add a pair of black shoes to the cart, the system may not always add black shoes. Such a system may not be reliable.

A Service Level Indicator, or SLI, is a measurement of a service's behavior. OpenTelemetry describes a measurement taken from the user's point of view as a good SLI. The loading speed of a web page is one example. A Service Level Objective, or SLO, is a means of communicating reliability to an organization or to other teams; it does so by tying one or more SLIs to business value.

Four signals for monitoring

Google SRE defines four golden signals for monitoring: latency, traffic, errors, and saturation. Latency is the time it takes to service a request. Google SRE distinguishes between the latency of successful requests and that of failed requests. Including a fast error response in the overall latency calculation can be misleading. The latency of error responses is also tracked.

Traffic expresses the amount of demand placed on the system, using a metric suited to the nature of the system. Google SRE gives the HTTP request rate for a web service as an example. The same measurement can be split by the nature of the requests, for example into static and dynamic content. In an audio streaming system, network I/O rate or concurrent sessions, and in a key-value storage system, transactions and retrievals per second, are examples of traffic measurements.

Errors is the rate of requests that fail. According to Google SRE, a failure can appear as an explicit error response, as wrong content served alongside a successful response, or as a violation of a defined policy. If protocol response codes do not express every error condition, secondary, internal protocols may be needed to track partial failure modes.

Google SRE also distinguishes between catching requests that fail outright and detecting that wrong content is being served. Monitoring error responses on the load balancer may catch the first case. End-to-end system tests can detect that wrong content is being served.

Saturation shows how full the service is and focuses on the most constrained part of the system. Google SRE gives memory in a memory-constrained system and I/O in an I/O-constrained system as examples. In some systems, performance degrades before full utilization is reached. A rise in latency can also be an early sign of saturation.

Averages and distributions

Google SRE notes that an uneven distribution can hide behind average utilization values. Some CPUs or databases may be used much more heavily than others. A similar imbalance can arise with latency: a portion of requests can be much slower than the average suggests.

Grouping request counts by latency buckets is one way to show the difference between a slow average and a tail made up of very slow requests. These counts can be displayed as a histogram. Google SRE describes setting histogram boundaries at approximately exponential intervals as a way to visualize the distribution of requests.

The measurement interval also affects what data can be seen. According to Google SRE, observing CPU load over a long interval may not reveal brief spikes that cause high tail latency. On the other hand, measuring frequently can be costly in terms of collecting, storing, and analyzing the data.

Turn this insight into action.

Use the mobile app to continue with guided workflows.

Google SRE describes sampling inside the server when finer-grained measurement is needed but very low collection latency is not. In its example, CPU utilization is recorded regularly, each measurement increments the counter for the appropriate utilization bucket, and these values are aggregated later. This method makes it possible to observe short-lived CPU spikes.

Logs: timestamped messages

According to OpenTelemetry, a log is a timestamped message emitted by a service or another component. A log message is not necessarily tied to a particular user request or transaction. Developers and operators use logs to understand system behavior.

OpenTelemetry notes that logs alone are not sufficient to follow code execution. Messages often lack contextual information, such as where the call was made from. A log becomes more useful when it is part of a span or is correlated with a trace and a span.

Google SRE bases white-box monitoring on metrics exposed by the internals of the system. Logs are among the information that can be used to inspect the system's internals. White-box monitoring can make it possible to detect errors masked by retries and problems that are about to occur. Google SRE also gives an HTTP handler that exposes internal statistics as an example of white-box monitoring.

Black-box monitoring, on the other hand, relies on testing externally visible behavior as a user would see it. According to Google SRE, this approach focuses on symptoms of problems that are happening now. Black-box monitoring is of limited use for problems that have not yet occurred but are imminent.

Spans: the work within a request

OpenTelemetry defines a span as a single unit of work or operation. A span tracks a specific operation that a request makes and provides a view of what happened while that operation was running. A span contains a name, time-related data, structured log messages, and other metadata known as Attributes. This information describes the operation the span tracks.

Span attributes are metadata fields attached to a span. OpenTelemetry's example fields include http.request.method, url.path, url.query, and http.route. In the examples, the request method, URL path, query, and route are represented by these fields.

The same examples include server.address for the server address, server.port for the server port, and url.scheme for the URL scheme. The response status code is represented by http.response.status_code. Example fields for the client side are named client.address and client.socket.address. In the example for the last field, the client passes through a proxy.

Traces: a request's path across services

According to OpenTelemetry, distributed tracing makes it possible to observe requests as they propagate through complex, distributed systems. It helps debug behavior that is difficult to reproduce locally. In distributed systems, problems may be non-deterministic or too complex to reproduce in a local environment.

A distributed trace, or simply a trace, records the path that a single request, made by an application or an end user, takes across multiple services in the architecture. A trace consists of one or more spans. The first span is the root span, and it represents the request from start to finish.

Spans beneath a parent span provide more detailed context about what happened during the request or which steps made up the request. In OpenTelemetry's web page example, the initial HTTP request may pass through an API gateway, a backend service, and a database. Each step is represented by a span. Together, these spans form the trace that shows the request's end-to-end path.

Observability backends can display traces as waterfall diagrams. According to OpenTelemetry, these diagrams show the parent-child relationship between the root span and the child spans. One span enclosing another also represents a nested relationship.

Limits and different perspectives

OpenTelemetry says an application is properly instrumented when developers have all the information they need to troubleshoot a problem and do not need to add further instrumentation.

According to Google SRE, in a multi-layered system, the same situation can be a symptom for one team and a cause for another. Slow database reads are a symptom for the database team that detects them. For the frontend team investigating a slow website, the same reads may be a cause. Whether white-box monitoring shows a symptom or a cause depends on the scope of the information it provides.

Google SRE describes two separate perspectives when web servers appear slow on database-heavy requests: how the web server perceives the database's speed, and how the database sees its own speed. Without this information, it is impossible to tell a genuinely slow database server apart from a network problem between the web server and the database.

Ready to start?

Download the app and continue from your phone.

End of Entry