When an application is split into 20 microservices communicating over HTTP and gRPC, a single user click might touch 8 different databases, caches, and APIs.
If the request takes 4.8 seconds, metrics and logs cannot easily pinpoint which specific call caused the delay. Distributed Tracing tracks the end-to-end journey of every request through the entire distributed system.
Core Distributed Tracing Terminology
- Trace: The complete end-to-end journey of a single transaction through the system (composed of multiple spans).
- Span: A single unit of work with a start time, end time, name, status, tags, and events (e.g. an SQL query or HTTP call).
- Trace ID: A globally unique 128-bit hex string identifying the overall trace (e.g.
4bf92f3577b34da6a3ce929d0e0e4736). - Span ID: A unique 64-bit hex string identifying an individual operation within the trace.
- Context Propagation: Injecting the
traceparentHTTP header (00-4bf92f...-00) across service boundaries so downstream services continue the same trace!
The OpenTelemetry (OTel) Architecture
OpenTelemetry (CNCF) is the vendor-neutral standard for telemetry collection:
Hands-On: Auto-Instrumenting a Node.js App with OpenTelemetry
You do not need to rewrite your code to get distributed traces! OpenTelemetry provides automatic instrumentation for popular frameworks (Express, Next.js, HTTP, PostgreSQL, Redis).
1. Install OTel Packages
2. Create tracer.js
3. Run with Node Pre-Load
Now, every incoming HTTP request, outgoing database query, and third-party API call is automatically traced with zero application code changes!