32.1 Metrics
What: Numeric measurements collected at regular intervals. Purpose: detect trends, set thresholds, trigger alerts.
| Type | Description | Example |
|---|---|---|
| Counter | Monotonically increasing value | Total HTTP requests, error count |
| Gauge | Value that goes up and down | CPU usage, memory usage, queue depth |
| Histogram | Distribution of values | Request latency distribution (p50, p95, p99) |
| Summary | Similar to histogram, calculates quantiles | Client-side latency percentiles |
RED Method (for request-driven services):
Rate — requests per second
Errors — error rate (% or count)
Duration — latency distribution
USE Method (for resources):
Utilization — % of resource capacity used
Saturation — amount of work queued
Errors — error events on the resource
Tools: Prometheus, Datadog, Azure Monitor, Grafana, InfluxDB.
32.2 Logs
What: Timestamped records of discrete events. Purpose: debugging, audit trails, forensic analysis.
{
"timestamp": "2024-06-15T14:30:00.123Z",
"level": "ERROR",
"service": "payment-service",
"trace_id": "abc123def456",
"span_id": "789xyz",
"message": "Payment processing failed",
"error_code": "GATEWAY_TIMEOUT",
"customer_id": "cust_12345",
"amount": 99.99,
"retry_count": 3,
"duration_ms": 5023
}
Log levels: TRACE (verbose debugging) → DEBUG (dev diagnostics) → INFO (normal ops) → WARN (handled anomalies) → ERROR (needs attention) → FATAL (unrecoverable).
Log Aggregation Pipeline:
Application → Sidecar/Agent → Buffer (Kafka) → Processor → Storage → Query UI
(stdout) (Fluentd/ (Decouple (Parse, (ES/Loki/ (Kibana/
Vector) rate) enrich) Azure) Grafana)
Tools: ELK Stack, Grafana Loki, Splunk, Datadog Logs.
Standards: no PII/PHI in logs, correlation ID injected via middleware (e.g., Serilog LogContext), structured (not string-interpolated) logging.
32.3 Traces
What: end-to-end tracking of a request across services. Purpose: latency analysis, bottleneck discovery, distributed debugging.
Trace (trace_id: abc123)
├── Span: API Gateway (50ms)
│ ├── Span: Auth Service (10ms)
│ └── Span: Order Service (35ms)
│ ├── Span: Database Query (15ms)
│ ├── Span: Payment Service (12ms)
│ │ └── Span: Stripe API (8ms)
│ └── Span: Inventory Service (5ms)
Standards: OpenTelemetry (unified successor to OpenTracing + OpenCensus), W3C Trace Context (HTTP header propagation), B3 Propagation (Zipkin format).
Tools: Jaeger, Zipkin, Grafana Tempo, Azure Application Insights, Datadog APM.
32.4 Q&A
Q1: Design an observability strategy for a microservices platform with 200 services.
- Collection: OTel SDK in every service (auto-instrumentation for HTTP/gRPC/DB); OTel Collector as DaemonSet (per-node) + Gateway Collector (central); standardized JSON logs with mandatory fields (timestamp, level, service, trace_id, span_id).
- Storage: Metrics — Prometheus (15-day hot) + Thanos/Cortex (1-year cold); Logs — Grafana Loki; Traces — Grafana Tempo with sampling; Profiling — Pyroscope.
- Visualization: Grafana as unified pane; per-service RED dashboards; SLO burn-rate dashboards; auto-generated service maps; click-through alert → dashboard → trace → log correlation.
- Alerting: multi-window multi-burn-rate SLO alerts, PagerDuty for P1/P2, Slack for P3/P4, deduplication/correlation to cut noise.
- Cost control: head-based sampling (1% high-volume, 100% low-volume) + tail-based sampling (always keep errors/slow traces); tiered log retention (7d hot / 30d warm / 1yr cold blob); metric downsampling (raw 7d → 1-min 30d → 5-min 1yr).