9. Full Local Observability: Metrics, Logs, Traces, and Profiling
Why run this locally first
Section titled “Why run this locally first”Before this lesson, /health returning JSON was the only signal available — no way to answer “which dependency slowed this request” or “did errors spike when Redis flapped” without guessing inside a container. The point of standing up the full stack locally rather than pointing straight at a paid cloud vendor is checking that labels and spans actually mean what you think before paying to ship them anywhere.
Two separate Docker Compose projects end up bridged together: the observability stack (collector, Prometheus, Loki, Promtail, Tempo, Pyroscope, Grafana) on its own network, and the existing app stack joining that network externally so the backend can reach the collector by container name.
Bug one: an exporter type that no longer exists
Section titled “Bug one: an exporter type that no longer exists”The collector config’s log pipeline was written against a loki: exporter type — removed from recent otelcol-contrib builds entirely. The startup error was direct: 'exporters' unknown type: "loki". Loki 3.x accepts OpenTelemetry data natively at its own /otlp endpoint now, so the fix was switching to the generic otlphttp exporter pointed at that path instead of chasing a exporter type that no longer ships.
Bug two: an image tag that was never real
Section titled “Bug two: an image tag that was never real”grafana/promtail:3.7.1, specified in the original plan, doesn’t exist on Docker Hub — surfaced immediately as Error failed to resolve reference on docker compose up. The closest real tag was 3.6.8. Small, but the kind of thing that stops a seven-container stack cold on the very first run if nobody checks the tag exists before pinning it.
Bug three: instrumentation loading in the wrong place entirely
Section titled “Bug three: instrumentation loading in the wrong place entirely”The natural assumption — edit docker-entrypoint.sh’s exec node server.js line to load OpenTelemetry instrumentation first — turned out to be pointless for this repo. The backend service’s Compose definition already used command: sh -c "npm run migrate && npm start", and a Compose command: override replaces a Dockerfile’s CMD entirely — meaning docker-entrypoint.sh never runs for this container at all, no matter what’s written in it. The actual fix was changing the start script in package.json itself: node -r ./instrumentation.js server.js, loading instrumentation before any application code via Node’s own -r require flag. Worth knowing as a general Docker fact, not just a one-off: a Compose-level command: silently wins over whatever the image’s own entrypoint would otherwise do.
Getting profiling to actually show data
Section titled “Getting profiling to actually show data”Pyroscope integration looked broken for a while and wasn’t — it just needed patience and a different debug flag than documented. The client’s default flush interval is longer than a quick manual check; the profiler visibly starting in logs doesn’t mean anything has uploaded yet, and confirming that took waiting 60-90 seconds, not 10. The documented DEBUG=pyroscope flag also doesn’t match the library’s actual internal namespaces — DEBUG=pyroscope*, with the trailing wildcard, was needed to see anything at all. And once data genuinely was landing, Grafana’s own Pyroscope datasource tag-picker still appeared to show stale results — querying Pyroscope’s UI directly, or running the raw query rather than relying on the dropdown, was the way to actually confirm it.
Why the collector pattern is worth the extra layer
Section titled “Why the collector pattern is worth the extra layer”The app never talks to Tempo, Loki, or Prometheus directly — everything goes to the OpenTelemetry Collector’s OTLP receiver, which fans each signal out to wherever it actually lives. That indirection is deliberate: adding sampling, filtering, or redaction later happens in one collector config, not scattered across application code.
Verifying resilience, not just happy path
Section titled “Verifying resilience, not just happy path”Stopping the collector container and generating traffic against the app confirmed the actual requirement: the app kept serving requests normally, logging export retries in the background rather than hanging or crashing. An app that blocks on a down telemetry pipeline is arguably worse than having no telemetry at all.
How this looks in production
Section titled “How this looks in production”The pattern here — one collector, fan-out to purpose-built backends, dev-friendly local storage that would never survive a real deployment (Tempo’s trace storage under /tmp, for instance) — mirrors how most real observability stacks are shaped, just swapped for managed or clustered storage in production. The genuinely transferable skill isn’t memorizing any one vendor’s dashboard; it’s knowing that a receiver takes data in, a processor transforms it in flight, and an exporter sends it on — and that pipelines per signal type are independent unless a change is explicitly applied to more than one.
Next: Lesson 10, Grafana.