Metrics tell you what changed. Logs tell you why something happened. Traces tell you where time was spent and how a request moved across your system. At the heart of distributed tracing in OpenTelemetry are two core concepts:Trace: The full journey of one request / transaction across services.Span: A timed unit of work inside that journey (function call, DB query, external API call, queue processing, etc.).This guide walks through how traces and spans are structured, how context is propagated, how to model work properly, and how to implement everything in Node.js / TypeScript with practical patterns you can copy into production.Table of ContentsCore ConceptsAnatomy of a SpanVisual Mental ModelSetting Up Tracing in Node.jsManual Instrumentation BasicsExpress / Fastify Middleware ExampleDatabase + External Call SpansError Recording & StatusAttributes, Events & LinksContext Propagation (Sync + Async)Sampling (Head & Tail)Span Naming Best PracticesCommon Anti-PatternsPutting It All TogetherNext Steps (Correlating with Metrics & Logs)1. Core Concepts ConceptDescription (Plain Language)TraceThe full story of a single request. Made of many spans. Has a trace_id so all pieces stay linked.SpanOne timed step in that story (e.g., DB query, HTTP call, function). Starts, ends, and carries metadata.Root SpanThe first span (no parent). Usually the inbound HTTP request, queue message, or scheduled job trigger.Child SpanA smaller step inside a bigger one. Lets you break work into clear pieces.ContextThe “current trace + active span” that rides along your async calls and network hops so new spans attach correctly.SamplerThe rule that decides: keep (record/export) this trace or drop it to save cost/noise.ExporterThe piece that ships finished spans to your backend (OneUptime, Jaeger, Tempo, etc.). Quick analogy (HTTP request version): A trace is the entire lifecycle of one HTTP request from accept to response. The root span is the server receiving the request. Child spans are each stag...
First seen: 2025-08-31 06:43
Last seen: 2025-08-31 17:45