Interview Prep/SRE & Reliability/Observability & Telemetry Decisions

A service's logs are unstructured strings like `Order 123 failed for user 9 after 3 retries`. Searching them during incidents is painful.

BeginnerScenarioObservability & Telemetry Decisions
Answer

Situation read → Free-text logs force regex searches and make aggregation impossible. Structured logs turn logs into queryable data.

What I'd do →

  1. Agree a JSON log schema: timestamp, level, service, trace_id, span_id, message, plus event fields such as order_id, retry_count, error_type.
  2. Switch the logger to JSON output (Logback JSON encoder, structlog, pino, zap).
  3. Inject trace_id automatically from the OpenTelemetry context.
  4. Query by field instead of regex, for example in Loki:
    {app="orders"} | json | error_type="PaymentTimeout" | retry_count >= 3
    
  5. Keep high-cardinality fields (order IDs) as log fields, not as Loki stream labels.

Why → Structured logs make "how many orders failed with PaymentTimeout in the last 10 minutes" a one-line query.

Interview tip → Mention that in Loki, labels must stay low-cardinality while JSON fields can be anything.

All SRE & Reliability questions

More on Observability & Telemetry Decisions