The traceparent header: how one trace crosses services, and where it gets lost

9 min read

A user clicks "Pay" and gets an error. In your monitoring you find three things: an error in the browser, a slow request in your API, and a failed call in a billing service. Each has its own timestamp and its own duration. Nothing tells you that the three come from the same click.

What connects them is one HTTP header, traceparent. This post shows what is inside it and where it gets lost. At the end there is a check you can run in ten minutes to see if your system propagates the traceparent header correctly.

How separate timings become one trace

This post uses the terms of OpenTelemetry, an open standard for recording what your services do. Take an example with made-up names: a browser calls POST /checkout on your API, and the API calls POST /charge on a billing service.

Each service records its work as spans. A span is one timed operation with a name, a start and an end timestamp, such as the API's database query or its call to billing.

A trace is the set of spans that belong to one request. All of them share one trace ID, and each span records the ID of its parent (the span that caused it). From these two IDs a dashboard tool can draw the trace waterfall, a full end-to-end view of a trace's spans.

The first span of a trace has no parent and is called the root span. A new trace ID is created for each root span, and every span below it keeps that ID.

When the API calls billing, the trace ID and the ID of the calling span must travel with the request. This is called propagation. The API writes the two IDs into an HTTP header, a step called inject. Billing reads them back, a step called extract.

Billing's first span now has a remote parent: a parent created in another process. So billing continues the API's trace instead of starting a new one. Without the header you get two traces and nothing to link them.

What is inside traceparent

The header is defined by the W3C Trace Context specification. This is the example value from the spec:

traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01

It has four fields, separated by dashes, all in lowercase hex:

FieldIn the exampleCharactersWhat it is
version002The format version. 00 is the current one.
trace-id4bf92f3577b34da6a3ce929d0e0e473632The ID of the whole trace.
parent-id00f067aa0ba902b716The ID of the span that sent this request.
trace-flags012Flags. The right-most bit is the sampled flag.

To read a header from your own logs, paste it into the traceparent decoder. It shows the four fields, and the reason when a header is invalid.

A trace-id or parent-id of all zeros is invalid, and the receiver must ignore the header.

The sampled flag passes the caller's sampling decision to the next service. A value of 01 means the caller may have recorded (kept) the trace's spans. The flag is only a recommendation, so the next service can still decide for itself whether to keep its own spans. Sampling has its own section below.

When billing makes its own outgoing call, the trace-id stays the same and the parent-id changes to the ID of billing's current span.

Two other headers can travel with it. tracestate carries extra data for a specific tracing vendor. baggage carries key-value pairs that you choose, such as a customer account ID, through the whole request. Its risk is covered at the end of the next section.

Where the trace gets lost or misleads

A proxy or caller sends its own traceparent

What happens. Something in front of your service already sends a traceparent: a partner's system, another team's gateway, or a proxy. Your first span becomes a child of that remote parent, so it is no longer a root span. The parent span lives in the caller's system, and your tool never sees it.

How you notice. Your service's traces start with a parent that is missing. If a dashboard counts requests by counting root spans, it skips this traffic.

What to do. Decide which callers you trust. OpenTelemetry's documentation says to be cautious when accepting context from external sources. The spec lets a service at the entry to your network restart the trace, with a new trace-id, parent-id and flags. In NGINX, the otel_trace_context directive controls this, and its default is ignore. extract continues the incoming trace. inject adds a new context and overwrites existing headers, which restarts the trace.

Head sampling and tail sampling

Every request produces a trace, and sending and storing all of them is a lot of data. Most requests succeed, and their traces look the same and tell you little. Sampling means keeping only some traces, to cut what you send and store while keeping the ones that matter.

There are two ways to sample. Head sampling decides as early as possible, before the trace is complete. An error can happen later in the request, so head sampling cannot ensure that every trace with an error is kept. OpenTelemetry's default sampler, the part of the SDK that decides, is ParentBased. When the incoming parent is not sampled, it drops your spans as well by default. The caller's flag decides for your service.

Tail sampling decides after it has seen all or most of the spans in a trace. It can keep every trace with an error, but it has to wait. OpenTelemetry's Collector does tail sampling with a processor that waits 30 seconds by default.

What happens. The trace ID exists from the first span, and your code can write it into a log line at once. The decision to keep the trace comes later. So a stored trace ID can point at a trace that was not kept.

How you notice. You open a trace ID from a log line, and the tool cannot find the trace.

What to do. Know your sampling rules before you rely on a trace ID. If one type of request must always have a trace, add it to the rules.

Queues and background jobs

A queue holds work for later. One service, the producer, adds a message. A worker, the consumer, takes it out and does the work.

What happens. If the producer does not put the trace context into the message, the consumer starts a new trace. OpenTelemetry's messaging conventions say a producer should attach a creation context to each message: the trace context from the moment the message was created.

A consumer often reads a batch of messages that come from many traces, and a span can have only one parent. So the conventions use span links by default. A link points from one span to one or more other spans and says they caused it, without making them its parents. For example, one span that processes ten messages can link to the ten requests that queued them.

A cron job, a task that runs on a schedule, is a different case. No request starts it, so its first span is a root span and starts a new trace. That is correct, not a lost trace.

How you notice. A worker's traces start at the worker, with no link to the request that queued the job.

What to do. Check that your queue library's instrumentation writes the context into each message. If it does not, call your SDK's inject and extract on the message yourself. To follow a job back to its request, look for a link, not a parent.

Browser to API across origins

What happens. Say your frontend runs on app.example.com and your API on api.example.com. These are different origins, and CORS is the set of browser rules for requests between origins. Only a short list of request headers is CORS-safelisted, and traceparent is not on it. So the browser first sends a preflight, an OPTIONS request, and the API answers with Access-Control-Allow-Headers, the headers it accepts. The Trace Context spec warns that single-page apps typically make cross-origin calls, and that these headers may fail on calls that Access-Control-Allow-Headers restricts.

OpenTelemetry's browser instrumentation adds trace headers to same-origin requests, and to other origins only when the URL matches propagateTraceHeaderCorsUrls. So by default the trace stops at the browser.

How you notice. Browser spans and API spans are in separate traces. Or, after you enable propagation, API calls fail with CORS errors in the browser console.

What to do. In the API's CORS settings, add traceparent, and tracestate if you send it, to Access-Control-Allow-Headers. In propagateTraceHeaderCorsUrls, list only your own API origins.

Baggage reaching third parties

What happens. Instrumentation is the library that records spans for you. OpenTelemetry's Node.js HTTP instrumentation injects propagation headers into every outgoing request that its ignoreOutgoingRequestHook does not exclude. It does not check the destination host. The Python requests instrumentation does the same, except for URLs listed in OTEL_PYTHON_REQUESTS_EXCLUDED_URLS. So a user ID or an email address in baggage also reaches your payment provider and your email API. OpenTelemetry's documentation warns that sensitive baggage can be shared with unintended resources, like third-party APIs.

How you notice. Log the headers of one call to an external API in a test environment, and look for baggage.

What to do. Keep personal and confidential data out of baggage. The W3C baggage spec says the same: keep confidential information out of it, or keep baggage off requests that cross trust boundaries. Exclude external hosts with the hook in Node.js or the excluded URLs setting in Python.

A ten-minute check

Run these in a test or staging environment.

  1. Log the headers your first service receives, for example with console.log(req.headers) in a Node.js handler. A traceparent that none of your code sent comes from your host, a proxy or the caller. Decide if you continue that trace or restart it. Paste the value into the traceparent decoder to check that it is valid.
  2. Ask your monitoring tool if it counts requests whose first span already has a parent.
  3. Find one request's trace ID in the logs of two services. If the IDs differ, check that the call between them carries a traceparent.
  4. Open a trace ID from a log line that is a few days old. If the trace is missing, find out whether sampling or retention removed it.
  5. Queue one job and check that the worker's trace links back to the request that queued it.
  6. In the browser's developer tools, on the Network tab, look for a traceparent header on one API call and an OPTIONS request before it.
  7. Look for baggage on one call to an external API.

Where Vigilon fits

You do not need to know OpenTelemetry, or anything in this post, to use Vigilon. Vigilon is built on OpenTelemetry. On Node.js the setup is one start flag and an API key, and there is no sample rate to set. Here is how some cases above look with it.

  • Background jobs. Each run you wrap in withJobMonitor (Node.js) or with_job_monitor (Python) is reported as a job run with its own trace, even when a web request starts it. Its database queries and outgoing calls belong to that run.
  • The browser. Vigilon's browser SDK sends errors only. It adds no trace header to your app's requests, so your API needs no CORS change for it. Traces start at your backend.
  • Next.js. With withVigilon() in next.config, Next.js writes the request's traceparent into a meta tag in the page's HTML, through its experimental clientTraceMetadata option. The browser SDK reads the trace ID from that tag. A browser error captured before the first client-side navigation then links to the server trace that rendered the page.
  • Sampling. Vigilon keeps the full trace for every request that errors, every request slower than one second and every job run, plus a sample of fast, successful requests. Traffic, latency and error-rate charts count every request, before any sampling.

Sources

All checked on 25 November 2026.

Get started

Start free for two months.

Pick a plan, add the SDK, and Vigilon starts watching your app. Starter is free for your first two months, with no card needed.