---
title: "Trace ID vs span ID, decoded from a real traceparent header"
description: "A trace ID names 1 request in every service it reaches, and it stays the same. A span ID names 1 step, so each service makes a new one."
canonical: "https://logbrew.co/en/guides/trace-id"
last_updated: "2026-11-21"
---

# Trace ID vs span ID, decoded from a real traceparent header

A trace ID names 1 request in every service it reaches, and it stays the same. A span ID names 1 step, so each service makes a new one.

Tested on November 21, 2026 with Node.js 22.18.0, @logbrew/node 0.1.30, Python 3.13.9, FastAPI 0.165.0, uvicorn 0.54.0, logbrew-fastapi 0.1.14, curl 8.7.1, and logbrew CLI 0.1.96

By [Furkan Erday](https://github.com/furkanerday). Furkan Erday is the founder of LogBrew. He builds LogBrew with Claude Code and Codex every day.

Canonical: https://logbrew.co/en/guides/trace-id

## What each traceparent header did to the trace

| Header that curl sent | Kept the trace ID | Both logs share 1 trace ID |
| --- | --- | --- |
| Valid, flags `01` | Yes | Yes |
| Valid, flags `00` | Yes | Yes |
| Trace ID in uppercase | Yes, in lowercase | Yes |
| Trace ID of all zeros | New trace | Yes |
| Version `ff` | New trace | Yes |
| No header | New trace | Yes |

6 requests into a Node.js service that calls a FastAPI service, with @logbrew/node 0.1.30 and logbrew-fastapi 0.1.14.

## Decode the traceparent header

### Split the header at the dashes

`traceparent` holds 4 fields of lowercase hex, split by `-`. They are the version, the trace ID, the parent ID, and the trace flags. This is the header that curl sent to our `checkout` service.

Output

```text
checkout got traceparent: 00-9095c7b7bf222836f82c2c415bc2bd65-fe8e70882fecdf07-01
```

### Read the version

`00` is the only version in the W3C Trace Context Recommendation, and `ff` is invalid. When we sent `ff`, both SDKs ignored the header and started a new trace.

### Read the trace ID

The next 32 characters are the trace ID `9095c7b7bf222836f82c2c415bc2bd65`, 16 bytes in hex. It names the whole request, and every service passes it on with no change. A trace ID of all zeros is invalid.

### Read the parent ID

The next 16 characters are the parent ID `fe8e70882fecdf07`, 8 bytes in hex. It is the span ID of the caller's span, so it changes at every hop. A parent ID of all zeros is invalid.

### Read the trace flags

The last 2 characters are the flags, and only bit 0 has a meaning. `01` says that the caller can have recorded the trace, and `00` says that it did not. With `00`, both SDKs still sent their spans, and LogBrew showed the trace.

## Pass the trace from Node.js to Python

### Install the 2 SDKs

Our `checkout` service runs on Node.js with `@logbrew/node`. It calls `payments`, a FastAPI app with `logbrew-fastapi`. Use a server key of your LogBrew project in each.

```bash
npm install @logbrew/sdk @logbrew/node
python3 -m pip install logbrew-sdk logbrew-fastapi
```

### Wrap the Node.js server and its call

`withLogBrewHttpHandler()` reads `traceparent` from each request and starts a span. `fetchWithLogBrewSpan()` starts a child span for the call and writes a new `traceparent` with the ID of that span. The wrapper reads the key from `LOGBREW_SERVER_API_KEY`.

```bash
import { createServer } from "node:http";
import { fetchWithLogBrewSpan, withLogBrewHttpHandler } from "@logbrew/node";

const server = createServer(withLogBrewHttpHandler(async (req, res, logbrew) => {
  logbrew.client.log(`evt_checkout_${Date.now()}`, new Date().toISOString(), {
    message: "checkout started for order 1042",
    level: "info",
    logger: "checkout"
  });
  const reply = await fetchWithLogBrewSpan("http://127.0.0.1:28702/payments/1042", {
    method: "POST"
  }, {
    client: logbrew.client,
    trace: logbrew.trace,
    routeTemplate: "/payments/:orderId"
  });
  res.writeHead(reply.status, { "content-type": "application/json" });
  res.end(await reply.text());
}));

server.listen(28701, "127.0.0.1");
```

### Add LogBrew to the FastAPI app

`init_logbrew()` reads `traceparent` from each request and starts a child span. `logbrew.logging_handler` adds the trace ID and the span ID of the request to each log record.

```bash
import logging
import os

from fastapi import FastAPI
from logbrew_fastapi import init_logbrew

app = FastAPI()
logbrew = init_logbrew(
    app, api_key=os.environ["LOGBREW_SERVER_API_KEY"], service_name="payments"
)
logger = logging.getLogger("payments")
logger.setLevel(logging.INFO)
logger.addHandler(logbrew.logging_handler)


@app.post("/payments/{order_id}")
def authorize(order_id: str):
    logger.warning("card declined for order %s", order_id)
    return {"orderId": order_id, "status": "declined"}
```

## Find the trace of a log line

### Send 1 request through both services

curl sent a `traceparent`, as a browser or a gateway in front of `checkout` can do. Without the header, `checkout` starts a new trace.

```bash
curl -X POST http://127.0.0.1:28701/checkout \
  -H 'traceparent: 00-9095c7b7bf222836f82c2c415bc2bd65-fe8e70882fecdf07-01'
```

Output

```text
{"orderId":"1042","status":"declined"}
```

### Compare the header at each hop

We printed the header in each service. `checkout` kept the trace ID and put the ID of its call span, `1a95bcb4e3fcb3ce`, in the parent ID. `payments` read that header and started the span `bc7e3f490d4a4d00` under it.

Output

```text
checkout got traceparent: 00-9095c7b7bf222836f82c2c415bc2bd65-fe8e70882fecdf07-01
checkout sent traceparent: 00-9095c7b7bf222836f82c2c415bc2bd65-1a95bcb4e3fcb3ce-01
payments got traceparent: 00-9095c7b7bf222836f82c2c415bc2bd65-1a95bcb4e3fcb3ce-01
```

### Find every log of the trace

Copy the trace ID from any log line and pass it to `--trace`. The CLI returned the log of each service. In the dashboard, paste the trace ID into the search box of Logs.

```bash
logbrew read logs --project "<project_id>" --trace 9095c7b7bf222836f82c2c415bc2bd65
```

Output

```text
Logs (2)
- warning card declined for order 1042 service=payments trace=9095c7b7bf222836f82c2c415bc2bd65 [unversioned / production]
- info checkout started for order 1042 service=checkout trace=9095c7b7bf222836f82c2c415bc2bd65 [unversioned / production]
```

### Open the trace

The trace holds 3 spans, 2 from `checkout` and 1 from `payments`. In the dashboard, paste the trace ID into the search box of Explore, then open the trace.

```bash
logbrew read trace 9095c7b7bf222836f82c2c415bc2bd65 --project "<project_id>"
```

Output

```text
Trace 9095c7b7bf222836f82c2c415bc2bd65 spans=3 [unversioned / production]
- POST /payments/{order_id}
- POST /payments/:orderId
- POST /checkout
```

## What we saw when we tested it

We ran `checkout` on Node.js 22.18 with @logbrew/node 0.1.30, and `payments` on Python 3.13.9 with FastAPI 0.165.0, uvicorn 0.54.0, and logbrew-fastapi 0.1.14. Both sent to a local LogBrew server. curl sent 6 requests into `checkout`, 5 with a different `traceparent` and 1 with none.

In each request, the logs of both services shared 1 trace ID. When the header was valid, it was the trace ID that curl sent. When the header was invalid or missing, `checkout` started a new trace and passed it on.

|  | `span_id` | `parent_span_id` |
| --- | --- | --- |
| `checkout` request | `5569d78d6d163d95` | `fe8e70882fecdf07` |
| `checkout` call to `payments` | `1a95bcb4e3fcb3ce` | `5569d78d6d163d95` |
| `payments` request | `bc7e3f490d4a4d00` | `1a95bcb4e3fcb3ce` |

- `checkout`
  - `level`: `info`
  - Message: `checkout started for order 1042`
  - `trace_id`: `9095c7b7bf222836f82c2c415bc2bd65`
  - `span_id`: `5569d78d6d163d95`
- `payments`
  - `level`: `warning`
  - Message: `card declined for order 1042`
  - `trace_id`: `9095c7b7bf222836f82c2c415bc2bd65`
  - `span_id`: `bc7e3f490d4a4d00`

## Trace ID vs span ID

A trace ID is 16 bytes, written as 32 hex characters. A span ID is 8 bytes, written as 16. The OpenTelemetry trace API specification calls an ID valid only when at least 1 byte is not zero, and writes both in lowercase hex.

In OpenTelemetry, a span context holds the trace ID, the span ID, the trace flags, and the trace state. `traceparent` carries the first 3. The `tracestate` header carries the trace state, a list of up to 32 vendor entries. Neither LogBrew SDK writes `tracestate`.

|  | Trace ID | Span ID |
| --- | --- | --- |
| Hex characters | `32` | `16` |
| Same at every hop | Yes | No |
| Valid when all zeros | No | No |

## When the header is wrong

The Recommendation allows only lowercase hex, and it forbids the version `ff` and IDs of all zeros. A service that gets such a header must ignore it and start a new trace. Both SDKs did this for `ff` and for a trace ID or a parent ID of all zeros.

Both SDKs accepted a trace ID in uppercase and sent it on in lowercase. Send lowercase, because a strict service starts a new trace instead.

With no header, `checkout` started a trace with the flags `01`, and `payments` started one with `00`. LogBrew kept both traces.

| Kept the trace ID | `@logbrew/node` | `logbrew-fastapi` |
| --- | --- | --- |
| Trace ID in uppercase | Yes | Yes |
| Version `ff` | No | No |
| Trace ID of all zeros | No | No |
| Parent ID of all zeros | No | No |

## Questions people ask

### What is a trace ID?

A trace ID is a 16-byte ID, written as 32 lowercase hex characters. It names 1 request in every service that the request reaches. Each service passes it on in the `traceparent` header.

### What is the difference between a trace ID and a span ID?

The trace ID is the same in every service of 1 request. A span ID names 1 step in 1 service. Our request got 1 trace ID and 3 span IDs.

### What is the traceparent header?

`traceparent` is the HTTP header of the W3C Trace Context Recommendation. It holds the version, the trace ID, the span ID of the caller, and the trace flags, as in `00-9095c7b7bf222836f82c2c415bc2bd65-1a95bcb4e3fcb3ce-01`.

### What does 01 at the end of traceparent mean?

`01` sets the sampled flag, so the caller can have recorded the trace. `00` says that it did not. Both LogBrew SDKs passed on either value, and LogBrew kept the trace.

### How do I find all logs with the same trace ID?

Run `logbrew read logs --project "<project_id>" --trace <trace_id>`, or paste the trace ID into the search box of Logs in the LogBrew dashboard. Each log that the SDKs write during a request has the trace ID of that request.

### Is the traceparent header case sensitive?

Yes. The Recommendation allows only lowercase hex. Both LogBrew SDKs accepted a trace ID in uppercase and made it lowercase, but a strict service ignores the header.

## Find every log of a trace with 1 search

The LogBrew SDKs for Node.js and FastAPI read and send `traceparent`, and each log keeps the trace ID of its request. Start on the generous free tier, no card needed.

[Start Free](https://logbrew.co/en)

## Sources

- [W3C Recommendation, Trace Context, 3.2 Traceparent Header](https://www.w3.org/TR/trace-context/#traceparent-header)
- [W3C Recommendation, Trace Context, 4.3 A traceparent is received](https://www.w3.org/TR/trace-context/#a-traceparent-is-received)
- [@logbrew/node on npm](https://www.npmjs.com/package/@logbrew/node)
- [LogBrewCo/sdk, logbrew-fastapi README](https://github.com/LogBrewCo/sdk/blob/main/python/logbrew_fastapi/README.md)

## More guides for agents, Python, Node.js, and React

- [Claude Code MCP and Codex MCP server setup](https://logbrew.co/en/guides/mcp-server-claude-code-codex)
- [Use AGENTS.md in Claude Code and Codex](https://logbrew.co/en/guides/agents-md)
- [Fix the Claude overloaded error 529 and rate limit error 429](https://logbrew.co/en/guides/claude-overloaded-rate-limit-error)
- [Set up Python logging with the right log levels and exception capture](https://logbrew.co/en/guides/python-logging)
- [Structured logging with a log format and log levels you can search by field](https://logbrew.co/en/guides/structured-logging)
- [Set up the Pino logger or Winston in Node.js and keep every error](https://logbrew.co/en/guides/node-logging)
- [Set up Django logging and keep the traceback of every 500 error](https://logbrew.co/en/guides/django-logging)
- [Set up FastAPI logging and handle errors without losing the traceback](https://logbrew.co/en/guides/fastapi-logging)
- [Add a React error boundary and log the errors it misses](https://logbrew.co/en/guides/react-error-boundary)
- [How to fix errors and set up logs, traces, metrics & releases](https://logbrew.co/en/guides)
