Structured logging: logs a machine can query
OpenTelemetry's documentation prefers structured logs in production, because a stable schema makes them straightforward to validate, parse and correlate with traces and metrics. Give every service the same field names, and each JSON line carries that schema.

One event, one JSON object
{
"timestamp": "2026-11-24T09:15:02.417Z",
"level": "ERROR",
"service": "checkout",
"message": "payment provider timeout",
"trace_id": "102981abcd2901",
"span_id": "abcdef1010"
}The values are chosen for this page. The field names are documented. timestamp, level, service and message come from the structured log example in OpenTelemetry's documentation. trace_id and span_id, with these two ID values, come from its trace context specification. Write each event on one line: Loki's json parser works on a log line that is a valid JSON document. The line is wrapped here to fit the page.
JSON alone does not make a log structured. OpenTelemetry's documentation says a structured log has a consistent schema: field names, types and semantics that downstream systems can rely on.
OpenTelemetry's log data model lists the fields of a log record. Among them:
- Timestamp: the time when the event occurred.
- SeverityText: the severity text, also known as the log level.
- Body: the body of the log record.
- Resource: the observed entity that generated the log.
- TraceId and SpanId: the request's trace ID and span ID.
Pick one name for each and use it in every service.
Levels with one meaning
The data model defines six severity ranges by number, in rising order:
- TRACE (1 to 4): a fine-grained debugging event.
- DEBUG (5 to 8): a debugging event.
- INFO (9 to 12): an informational event.
- WARN (13 to 16): a warning event. Not an error.
- ERROR (17 to 20): an error event. Something went wrong.
- FATAL (21 to 24): a fatal error, such as an application or system crash.
Map your logging library's levels to these ranges.
Secrets and personal data
OpenTelemetry's page on sensitive data says that collecting telemetry always carries the risk of capturing sensitive or personal information. Its examples of sensitive data include:
- personally identifiable information
- authentication credentials and session tokens
- financial information
- health-related data
The same page sets out data minimization: only collect data that serves an observability purpose, and avoid personal information unless it is absolutely necessary.
The page also lists Collector processors. The attributes processor removes or modifies attributes, and its documented example hashes user.email and deletes user.full_name. The redaction processor deletes log attributes that are not on a list of allowed attributes.
Trace IDs in every line
OpenTelemetry's specification says how to record trace context in a JSON log: as top-level fields named trace_id and span_id, lowercase and hex-encoded.
OpenTelemetry's logs page says that when you add auto-instrumentation or activate an SDK, it correlates your existing logs with the active trace and span and adds their IDs. It provides logging bridges for existing logging frameworks. Check that yours has one.
Standard output in containers
The Kubernetes documentation calls writing to standard output and standard error the easiest and most adopted logging method for containerized applications. The container runtime handles and redirects both streams, and the kubelet rotates the log files. It states two limits:
kubectl logsreturns only the latest log file. The kubelet'scontainerLogMaxSizedefaults to 10Mi andcontainerLogMaxFilesto 5.- When a pod is evicted from a node, its containers are evicted with it, along with their logs.
Kubernetes says logs should have storage and a lifecycle independent of nodes, pods and containers, and that it provides no native storage for log data. One approach it lists is a logging agent on every node, which it recommends running as a DaemonSet. It also advises against writing entries with different formats to the same stream.
Labels and cardinality in Loki
Grafana Loki's label best practices ask for static labels with bounded values, such as region, cluster, application, namespace and environment. They say never to use a label that can have unbounded values, and not to extract a trace ID or an order ID into a label. Too many label value combinations lead to too many streams, and the page names the penalty: a large index and small chunks in the store.
Its guidance is to favor filter expressions over dynamic labels. This query is from the Loki documentation:
{job="mysql"} |= "error" | json | line_format "{{.err}}"{job="mysql"} is the stream selector. |= "error" keeps the lines that contain that string. The documentation calls line filters the fastest way to filter and says to place them at the beginning. | json extracts all JSON properties as labels when the line is a valid JSON document. line_format rewrites the line from a template, here the err property.
For high-cardinality metadata, Loki has structured metadata, which attaches it to a log with no index entry. The documentation filters on it like this:
{job="example"} | pod="myservice-abc1234-56789" | trace_id="0242ac120002"What to check in a service
- Every line is a valid JSON document. When a line is not in the expected format, Loki's parser keeps it and adds an
__error__label. - Every service uses the same field names.
- Recent logs contain none of the sensitive data listed above.
- Lines written during a request carry
trace_idandspan_id. - No label has unbounded values. Loki's
logcli seriescommand has an--analyze-labelsflag for debugging high-cardinality labels.
Sources
Want a second pair of eyes on yours? We do this work for a living.
More guides

OpenTelemetry: traces, metrics and logs through one collector
Observability · 4 min read
Signal stability, the documented Collector configuration, agent or gateway, and sampling.

Kubernetes audit logs: what to record and what to look for
Security · 4 min read
Audit levels, an example policy, where managed clusters send the log, and what to search for.

The four golden signals: what to measure first
Observability · 4 min read
Latency, traffic, errors and saturation, with a PromQL query for each and a first dashboard.