21 / 67 · 06 Observability-Driven Testing · Structured Logging Best Practices← prev⊞ allnext →☰ Read as one page
4.2Unstructured vs. Structured Logging
# BAD: Unstructured -- human-readable, machine-hostile
2026-01-15 14:23:45 ERROR Failed to process order for user john@example.com: timeout after 30s
# GOOD: Structured JSON -- machine-parseable, human-readable with tooling
{
"timestamp": "2026-01-15T14:23:45.123Z",
"level": "error",
"service": "order-service",
"event": "order_processing_failed",
"user_id": "usr_42",
"order_id": "ord_789",
"error_type": "timeout",
"timeout_seconds": 30,
"downstream_service": "payment-service",
"trace_id": "abc123def456",
"span_id": "span_789",
"environment": "production",
"version": "2.4.1"
}
The structured version enables queries like:
- "Show all timeout errors in the last hour for the payment-service dependency"
- "Count errors by type for user usr_42"
- "Correlate this error with the trace abc123def456 to see the full request flow"