Use it when designing application logging.
Structured Logging
Structured logging writes logs as key-value data (usually JSON) instead of free text, so fields can be filtered, aggregated and correlated.
1. Sample line is valid JSON: tail -1 app.log | jq ..
2. Required fields present.
3. trace_id included.
4. No secrets in logs.
5. Query by field works in the log platform.
event + context → JSON line → parsed fields → queries
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Confirm timestamps are UTC with time zone and milliseconds. Confirm log levels are used consistently.
Step 2 Common failures Narrow the fault
Multi-line stack traces break line-based collectors unless joined. Inconsistent field names (userId, user_id) make queries miss data. Debug logging left on in production costs storage and performance.
Use consistent field names (timestamp, level, service, message, trace_id). Log the event once with context instead of many lines. Never log passwords, tokens or full card data.
tail -1 app.log | jq .— first check for this topiccurl -s localhost:9090/-/ready— Prometheus readycurl -s 'localhost:9090/api/v1/query?query=up'— scrape targets up/downpromtool check config prometheus.yml— config valid
ReferenceWhat it is1 section · depth on demand
How it works
Structured loggers serialise fields at the source. Collectors forward them without regex parsing. Shared trace IDs let you jump from a trace to its logs.
ReferenceImportant terms & boundaries3 sections · depth on demand
Example
{"ts":"2026-11-01T09:14:03.120Z","level":"error","service":"checkout","trace_id":"4bf92f3577b34da6","user_tier":"pro","msg":"payment declined","provider":"stripe","latency_ms":812}
Illustrative output, not captured Evidence. Use consistent field names (OpenTelemetry semantic conventions or ECS), include trace/span IDs for correlation, log in UTC, and never log secrets or full personal data.
In depth
One event, one line, machine-readable fields
{"timestamp":"2026-11-27T09:14:03.120Z","severity":"ERROR","service.name":"checkout",
"trace_id":"4bf92f3577b34da6a3ce929d0e0e4736","span_id":"00f067aa0ba902b7",
"event":"payment.declined","order_id":"A-10293","provider":"nets","http.status_code":402,
"duration_ms":812,"message":"payment declined by provider"}
Field conventions that pay off
| Practice | Why |
|---|---|
Timestamp in UTC, RFC 3339 with milliseconds and Z | Sorts and correlates across hosts |
A stable event name per kind of event | Count and alert on events without regex on messages |
trace_id / span_id from the active context | Jump from log to trace and back |
Same field names everywhere (user.id, not userId here and uid there) | One query works for all services; OpenTelemetry semantic conventions give names |
Variable data in fields, constant text in message | "payment declined" stays groupable; the amount is a field |
| Durations as numbers with the unit in the name | duration_ms: 812, not "812ms" |
Severity mapping
The OpenTelemetry log data model defines SeverityNumber ranges: 1–4 TRACE, 5–8 DEBUG, 9–12 INFO, 13–16 WARN, 17–20 ERROR, 21–24 FATAL. Mapping each logging library's levels onto these makes "errors across all services" one query.
What must not be logged
Passwords, tokens, session cookies, full card numbers and personal data beyond what the purpose requires. Redact at the source (logger configuration or a wrapper) and add a second filter in the collector, because a log line, once shipped, is copied into many systems.
Multi-line output
Stack traces should be one event: log them as a field (exception.stacktrace) in JSON, rather than relying on collectors to join lines with regex rules.
Common mistakes
- Logging secrets.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.