{"canonical_url":"https://engineer.company/glossary/trace-context/","content_markdown":"# Trace context\n\n## What it is\n\nTrace context carries the information needed to relate parts of a distributed\ntrace as work moves between components. An application can start a trace for a\nrequest and record a span for one operation. When that operation calls another\nservice, it can pass context that lets the receiver identify the trace and\nrelate its work to the operation that made the call.\n\nThe W3C Trace Context standard defines an HTTP representation. Its traceparent\nfield carries a version, trace identifier, parent identifier and flags. The\nrelated tracestate field can carry additional vendor-specific context within the\nformat's rules. An application can extract incoming context and inject\nappropriate outgoing context. The receiver uses that information when it decides\nhow to record or continue its own observation.\n\nThe context travels during work. Exported spans can reach the collector later\nand in a different order. Keeping the context consistently available allows the\ntrace store to connect spans after they arrive. A trace identifier relates work\nwithin a trace. An order identifier, message identifier or user identifier\nserves a separate purpose. Those values have their own lifecycle and privacy\nrequirements.\n\n## Why it matters\n\nA user can experience a slow operation across a frontend, API and storage\ncomponent even if each team's log makes sense on its own. Correlation by time is\ndifficult when many requests overlap. Propagating context lets a maintainer\nfollow the relevant operations and measure where the delay was introduced. It\nalso helps show which work the application attempted before an error or a retry.\n\nContext is useful at more than one kind of boundary. A browser request can call\nan API. That service can enqueue a task which another process handles later. The\nappropriate relationship depends on how the system describes the work. A worker\nmay continue one observation or record a separate trace with a link to the\ninitiating span. Choose a relationship that makes sense for the queue's timing\nand for the problem an operator needs to diagnose.\n\nThe design also needs a trust policy. Trace headers can arrive from systems the\napplication does not control. Validate what is used and decide where to start a\nnew internal trace. Avoid placing customer identifiers or confidential data into\npropagation fields. Use an agreed policy for outgoing connections so trace\ncontext is shared only where it has a clear operational purpose.\n\n## What it looks like in practice\n\nImagine a request that starts an export. The entry point accepts or starts a\ntrace, records the request span and injects context into its call to the export\nservice. That service can record its own operation with a parent relationship.\nWhen it reserves work for a queue, it can preserve selected correlation\ninformation so the worker can link back later. The product's durable job\nidentifier remains the way a user queries the export's status.\n\nTest the real request path. Send a controlled request through the frontend to\nthe API and watch for its span and the expected parent-child relationships.\nIntroduce an error in the downstream service and check which span records the\nfailure. Send a request with no incoming context and verify that the system\nfollows its policy for starting a trace. Then observe a queued retry and check\nthat the traces still describe what happened.\n\nEngineer's\n[first-party tracing case study](/portfolio/built-first-party-error-monitoring-and-tracing/)\ndocuments using OpenTelemetry to follow requests across the frontend, API and\ndatabase. The export exercise applies the same idea to a request with deferred\nwork. A useful trace makes the join between components visible and shows the\npath that actually ran, including the work performed after a request returns to\nthe user.\n\nAlso inspect where automatic instrumentation ends. A library might propagate\ncontext across ordinary client calls while a custom message publisher needs\nexplicit handling. Record which boundary supplied the context at that step. Use\na controlled fixture that records both the outgoing and incoming identifiers.\nVerify the parent relationships directly and check that the viewer groups each\noperation with the correct trace.\n\n## Where it goes wrong\n\nA trace can be fragmented when one component drops context, creates a new root\naccidentally or reuses context from an earlier request. Inspect the actual\npropagation path and check that request scopes are closed at the end of their\nwork. Test concurrent requests so a missing scope boundary does not silently mix\ntheir spans.\n\nAnother problem is expecting a trace from every propagated context. Sampling and\nexporter decisions influence what reaches the store, and some dependencies\ndecline incoming context. Use a trace as evidence about the spans actually\nretained. A broken link between two important services may require an\nindependent measurement to explain which instrumentation or sampling step was\ninvolved.\n\nA test can also check a round trip through an internal proxy. The proxy may\nforward headers faithfully while an application overwrites the context for a\nlater outgoing request. Inspect what each component extracted and injected. Keep\nthe fixture small enough to follow the precise expected sequence. Compare trace\nidentity, parent identity and the operation names together. A shared trace\nidentifier alone can group the work without describing the causal relationship\nthat helps a maintainer identify delay.\n\nFinally, keep the propagated information small and documented. Update the trust\npolicy when work crosses a new boundary and test the behaviour with invalid or\nabsent fields. Give operators enough context to diagnose real requests without\ncarrying unnecessary detail between systems. A well-understood trace context\nmakes relationships visible while leaving the product's own identifiers and user\noutcomes clear.\n\n## Further reading\n\n- [W3C Trace Context](https://www.w3.org/TR/trace-context/). Specifies\n  traceparent and tracestate for HTTP propagation.\n- [OpenTelemetry context propagation](https://opentelemetry.io/docs/concepts/context-propagation/).\n  Explains correlation across components and process boundaries.\n- [OpenTelemetry propagator APIs](https://opentelemetry.io/docs/specs/otel/context/api-propagators/).\n  Defines how instrumentation injects and extracts context.\n\n\u003chttps://engineer.company/glossary/trace-context/\u003e\n","date_modified":"2026-11-25T07:18:46Z","description":"Follow trace context through a request and a queued task, then verify parent relationships and edge handling.","formats":{"gemtext":"https://engineer.company/glossary/trace-context/index.gmi","gopher":"https://engineer.company/glossary/trace-context/gophermap","html":"https://engineer.company/glossary/trace-context/","json":"https://engineer.company/glossary/trace-context/index.json","markdown":"https://engineer.company/glossary/trace-context/index.md","pdf":"https://engineer.company/glossary/trace-context/index.pdf"},"kind":"page","language":"en","title":"What is trace context?","url":"https://engineer.company/glossary/trace-context/","version":1}