Time: 60 minutes | Level: Architect | Docker:docker run -it --rm node:20-alpine sh
"You can't manage what you can't measure." This lab covers the three pillars of observability: traces (OpenTelemetry), metrics, and structured logging (pino), plus Node.js's built-in diagnostics_channel.
Step 1: The Three Pillars of Observability
TRACES → WHAT happened, in what order, how long each step took
(distributed request tracing across services)
METRICS → HOW MUCH: counts, rates, histograms over time
(request rate, error rate, latency p99, heap usage)
LOGS → WHAT exactly happened, with context
(structured JSON: level, msg, traceId, userId, duration)
OpenTelemetry (OTel) is the CNCF standard for all three pillars. One SDK, any backend (Jaeger, Zipkin, Tempo, Datadog, etc.).
Step 2: Install OpenTelemetry
npminstall@opentelemetry/sdk-trace-base@opentelemetry/api# For auto-instrumentation:# npm install @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node
Step 3: TracerProvider + Custom Spans
📸 Verified Output:
Step 4: Metrics — Counter, Histogram, Gauge
Step 5: Pino Structured Logging
💡 Use pino-pretty for development: node app.js | pino-pretty. In production, output raw JSON and use a log aggregator (Loki, CloudWatch, ELK).
💡 diagnostics_channel is zero-overhead when no one is subscribed. It's how Node.js's built-in HTTP, PostgreSQL drivers, and Express can publish hook points without impacting performance.