Proposing telemetry libraries
I need to propose standard telemetry libraries with language-specific wrappers around OpenTelemetry, including configuration guidelines for instrumentation. I’ll mention cardinality controls, like allowlist tags and dimension reduction, as well as using exemplars to link traces. Sampling methods like head/tail sampling at the collector need to be discussed, along with dynamic tail sampling based on errors or latency thresholds.
My outline includes the goals, reference architecture, standardized telemetry libraries, and tracing components to ensure clear guidelines.Detailing metrics and incident management
I’m outlining a comprehensive plan for metrics, logs, SLOs, alerting, and incident management. First, I’ll include golden signals like latency and cardinality controls, structured logs in JSON, and correlation IDs. For SLOs, I’ll define SLIs and error budgets. The alerting strategy needs to cover various thresholds and dependencies.
For incident management, I’ll outline playbooks, runbook templates, and communication strategies post-incident. Lastly, I’ll discuss implementation steps and tools, presenting everything clearly with headings, diagrams, and bullet points for easy understanding.
1) Design goals & principles
- Consistency: every service emits the same baseline signals (metrics, traces, logs) with the same naming + dimensions.
- Actionability: alerts tie to customer impact (SLOs), not infrastructure noise.
- Cost control: explicit cardinality budgets, sampling, retention tiers.
- Correlation: one-click pivot between alerts → dashboards → traces → logs.
- Safety: PII/secret scrubbing at source and in the pipeline; least-privilege access.
2) Reference observability architecture (data plane)
Microservice (OTel SDK / wrapper lib)
├─ Metrics (OTLP) ─┐
├─ Traces (OTLP) ──┼──> Node/Sidecar OTel Collector (Agent)
└─ Logs (OTLP) ────┘ ├─ cardinality guards / scrubbers / sampling
└─ forwards OTLP to
Central OTel Collector (Gateway)
├─ tail sampling, batching, routing
├─ Metrics -> Prometheus Remote Write -> Cortex/Thanos (+ Grafana)
├─ Traces -> Tempo/Jaeger (+ Grafana)
└─ Logs -> Loki/Elastic/OpenSearch (+ Grafana/Kibana)
Alerting:
SLO Evaluator (PromQL / Sloth / Nobl9 / Datadog SLOs)
-> Alertmanager/PagerDuty/Opsgenie
-> Incident channels + ticketing + status page
Collector placement
- Agent (DaemonSet/sidecar): low-latency, local buffering, first-line filtering/scrubbing.
- Gateway (central): tail sampling, multi-tenant routing, consistent policy enforcement.
3) Standardized telemetry libraries (instrumentation plane)
3.1 Standard library strategy
- Adopt OpenTelemetry as the base (W3C Trace Context propagation).
- Provide an internal “observability SDK wrapper” per language (e.g.,
obs-java, obs-go, obs-node, obs-python) that:
- Pins OTel versions and exporters (OTLP).
- Auto-instruments common stacks (HTTP/gRPC, DB clients, message queues).
- Enforces naming conventions and dimension allowlists (see cardinality).
- Injects standard resource attributes:
service.name, service.version, deployment.environment, cloud.region, k8s.namespace.name, k8s.pod.name (careful), etc.
- Provides helpers for:
- RED/USE metrics (server/client)
- span naming + attributes
- structured logging with trace correlation
3.2 Baseline instrumentation contract (every service)
- Tracing: inbound request span + downstream spans; error status set on exceptions; record duration histograms.
- Metrics (minimum):
http.server.request.duration (histogram)
http.server.request.count (counter)
http.server.active_requests (gauge) if meaningful
- dependency client metrics:
http.client.*, db.client.*, rpc.client.*
- Logs: structured JSON; include
trace_id, span_id, service.name, env, request_id (if available).
3.3 Governance & enforcement
- CI checks:
- dependency version policy (wrapper required)
- metric name linting + forbidden labels
- unit tests for “telemetry smoke” (emits baseline metrics/traces)
- Runtime “kill switches” via config:
- disable debug spans
- reduce sampling
- drop high-cardinality labels
4) Distributed tracing design
4.1 Trace context propagation
- Use W3C
traceparent/tracestate across HTTP/gRPC and messaging.
- For async workflows:
- propagate context through message headers (Kafka headers / AMQP props)
- store correlation IDs for batch jobs with explicit linking spans
4.2 Sampling policy (cost + usefulness)
- Head sampling at SDK (small baseline, e.g., 1–5%) to cap overhead.
- Tail sampling at Gateway Collector (recommended) to keep:
- 100% of error traces (HTTP 5xx, exceptions)
- slow traces above latency thresholds per route
- traces for specific tenants or canary deploys during rollouts
- Ensure sampling decisions propagate downstream (OTel does this when configured).
4.3 Trace/log/metric correlation
- Put
trace_id into logs automatically.
- Enable exemplars on latency histograms (Prometheus exemplar support) to jump from a latency spike to representative traces.
5) Metrics design + cardinality controls
5.1 Metric taxonomy
- Prefer Golden Signals:
- Latency (histograms; avoid summaries for aggregation across instances)
- Traffic (RPS)
- Errors (error rate)
- Saturation (CPU, memory, queue depth, thread pools)
- Service-level dashboards: RED for request/response services; USE for infrastructure components.
5.2 Cardinality budgets (hard rules)
High-cardinality metrics break Prometheus-style systems quickly. Define budgets per metric family and enforce them.
Allowed labels (example policy)
- Always allowed:
service, env, region, cluster
- Conditionally allowed (must be bounded):
route (templated), method, status_code, grpc_method
- Usually forbidden:
user_id, account_id, email, ip, request_id, raw path, query, pod_uid
Route normalization
- Use framework hooks to emit route templates (
/users/:id) not raw paths (/users/123).
Collector-level protections
attributes processor to drop/rename offending labels
filter processor to reject metrics with disallowed dimensions
transform to bucket/normalize (e.g., convert status=200 into status_class=2xx)
- Prometheus relabeling to drop labels at ingestion as a last resort
5.3 Histograms & buckets
- Standardize latency buckets org-wide (so aggregation works), e.g.:
- 5ms, 10ms, 25ms, 50ms, 100ms, 250ms, 500ms, 1s, 2.5s, 5s, 10s
- Avoid per-endpoint custom buckets unless approved.
6) Log aggregation architecture
6.1 Logging format & levels
- Structured JSON logs only (no unstructured printf in production paths).
- Standard fields:
timestamp, level, service, env, message
trace_id, span_id, request_id
http.method, http.route, http.status_code (bounded)
error.type, error.message (sanitize), stacktrace (optional sampling)
- Level policy:
ERROR for actionable failures
WARN for unexpected but tolerated conditions (should be rare)
INFO for lifecycle/audit (rate-limited)
DEBUG disabled by default in prod; enable temporarily via config
6.2 Pipeline & retention
- Prefer OTel logs -> Collector -> log backend (Loki/Elastic/OpenSearch).
- Apply at Agent:
- PII/secret scrubbing (regex + structured key denylist)
- log sampling for noisy lines (keep all errors; sample info)
- Retention tiers:
- hot searchable: 7–14 days
- warm: 30–90 days
- cold archive (optional): object storage for compliance
7) SLOs + error budgets (control plane)
7.1 Service SLO model
Each customer-facing service defines:
- SLIs (what you measure): availability, latency, correctness
- SLO targets (e.g., 99.9% availability, p95 < 300ms)
- Windows: 28d (primary), optionally 7d for faster feedback
- Error budget:
1 - SLO (e.g., 0.1% of requests may fail over 28d)
Example SLI (availability)
- Good events:
http_requests_total{status_class!="5xx"}
- Total events:
http_requests_total
- Exclude known non-user-impacting routes (health checks) by policy.
7.2 Error budget policy (how it changes behavior)
- Define explicit actions when budget burn is high:
- freeze feature releases for that service
- prioritize reliability work
- require risk review for large rollouts
- Track burn during deployments (canary + progressive delivery).
7.3 SLO tooling
- Compute SLOs from metrics (Prometheus/Thanos + Sloth, Nobl9, Datadog SLOs, etc.).
- Store SLO definitions as code (Git), reviewed like APIs.
8) Alert tuning (reduce noise, keep sensitivity)
8.1 Alert hierarchy
- Page only on imminent/ongoing SLO burn or severe availability loss.
- Ticket for symptoms that need work but aren’t urgent (e.g., elevated latency but within budget).
- Informational (dashboards only) for capacity trends.
8.2 Multi-window, multi-burn alerts (recommended)
For each SLO:
- Page when burn rate indicates budget exhaustion soon, e.g.:
- fast burn: 2% budget in 1h (short window) AND sustained 5m
- slow burn: 5% budget in 6h AND sustained 30m
This avoids flapping and catches both sharp outages and slow regressions.
8.3 Alert quality controls
- Every alert must include:
- impact statement (users affected, region, endpoint)
- links: dashboard, trace query, log query, runbook
- suggested next steps + owner
- Routing + dedupe:
- group by service/env/region
- silence during planned maintenance
- Regular alert reviews:
- monthly: remove noisy/unused alerts
- after incidents: adjust thresholds/windows
9) Incident review playbooks (operational discipline)
9.1 Standard incident playbook (runbook template)
- Declare + classify: SEV level based on user impact and scope.
- Stabilize:
- stop the bleed: rollback, disable feature flag, shed load, failover
- Triage with observability pivots:
- start from SLO/burn alert dashboard
- check RED metrics by region/route/status class
- jump to exemplars/traces for slow/error requests
- query logs by
trace_id for failing spans
- Mitigate:
- dependency checks (db, cache, queue depth, third-party)
- confirm fix via SLO recovery and error rate normalization
- Communications:
- internal incident channel updates every N minutes
- status page updates if user-visible
- Close:
- note customer impact window, root cause hypothesis, follow-ups
9.2 Post-incident review (PIR) checklist
- What was the SLO impact (error budget consumed)?
- Timeline: detection → page → mitigate → resolve.
- Contributing factors: deploy, config, dependency, capacity, code path.
- Action items (with owners/dates):
- instrumentation gaps (missing route label normalization, missing spans)
- new dashboards/alerts (prefer SLO-based)
- reliability fixes (timeouts, retries with budgets, circuit breakers)
- Confirm alert tuning:
- did we page too late/early?
- noise reduction opportunities
10) Concrete defaults (starter set)
- Telemetry standard: OpenTelemetry (OTLP everywhere)
- Collectors: OTel Agent (DaemonSet) + OTel Gateway (HA)
- Backends (example stack):
- Metrics: Prometheus + Thanos/Cortex; visualize in Grafana
- Traces: Tempo or Jaeger
- Logs: Loki or Elasticsearch/OpenSearch
- Alerting: Alertmanager → PagerDuty/Opsgenie
- Cross-linking: exemplars + trace IDs in logs + Grafana deep links
- Policies as code: SLOs, alert rules, sampling rules, label allowlists in Git
If you share your environment (Kubernetes vs VMs, cloud, expected service count/RPS, preferred vendors), I can tailor: sampling rates, retention tiers, exact SLO formulas, and a concrete set of dashboards/alerts per service type (HTTP API, async worker, data pipeline).