Correlating logs with request ID
Learn how to carry a request id into every log line of one request with tracing spans, follow one request through JSON logs, and keep two requests apart
Correlating logs with a request id means making every log line of one request carry the same label, so the whole story of that request can be found with one search. The label is a short unique string, the request id, and it travels in a header called x-request-id. A client sends it or the server generates it, and from then on every log line the request produces carries it, in the span context and in the JSON output. Two requests running at the same time get two different labels, and their log lines never mix.
Where This Fits
The request span already groups log lines by method and path, and the JSON formatter already prints that span as searchable keys. The request id adds the one field the span cannot supply on its own: an identity that is unique to a single request. A path groups thousands of requests together. An id picks out one. The span is the vehicle and the id is the passenger, and this page is about putting the passenger in the vehicle so every line it carries can be traced back to one request.
Think of a hospital ward where every patient wears a wristband with a number. The nurses write the number on every chart entry, every medicine log, every test result. Finding the full story of one patient means searching for one number, not reading every chart on the ward. The request id is the wristband number, and the log lines are the chart entries.
The Request Id in One Sentence
The id itself is covered by the layer that creates it, so this page states it once and moves on. Two layers do the job: SetRequestIdLayer makes sure an id exists, generating a random UUID when the client sent none and keeping the one the client sent, and PropagateRequestIdLayer copies the id onto the response so the client can see it. Both live in the tower_http::request_id module, behind the request-id feature, and the header they use is x-request-id. A handler reads the id as a typed value with Extension<RequestId>. That is the whole id layer, and the rest of this page is about what happens after the id exists: getting it into the logs.
The Smallest Working Version
The smallest version of this page is a server with the two id layers, a tracing layer that reads the id from the header and records it on the request span, and a handler that logs two lines. Every line the request produces carries the id, and nothing in the handler mentions the id at all.
Create a project with cargo new request-log-demo and replace the generated Cargo.toml with this one:
[package]
name = "request-log-demo"
version = "0.1.0"
edition = "2021"
[dependencies]
axum = "=0.8.9"
tokio = { version = "=1.54.1", features = ["full"] }
tower = { version = "0.5", features = ["util"] }
tower-http = { version = "=0.7.1", features = ["trace", "request-id", "util"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
serde_json = "1"
The tower dependency with the util feature provides ServiceBuilder, the helper that stacks the layers in order. The trace feature provides the tracing layer, and the request-id feature provides the two id layers.
Here is the whole program:
use axum::{extract::Extension, routing::get, Router};
use tower::ServiceBuilder;
use tower_http::{
request_id::{MakeRequestUuid, PropagateRequestIdLayer, RequestId, SetRequestIdLayer},
trace::TraceLayer,
};
async fn order(Extension(id): Extension<RequestId>) -> String {
tracing::info!("validating order");
tracing::info!("order confirmed");
format!("order placed, request id {}", id.header_value().to_str().unwrap())
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.json()
.with_max_level(tracing::Level::DEBUG)
.init();
let app = Router::new()
.route("/order", get(order))
.layer(
ServiceBuilder::new()
.layer(SetRequestIdLayer::x_request_id(MakeRequestUuid))
.layer(
TraceLayer::new_for_http().make_span_with(
|request: &axum::extract::Request| {
let request_id = request
.headers()
.get("x-request-id")
.and_then(|value| value.to_str().ok())
.unwrap_or("no-request-id");
tracing::info_span!(
"request",
method = %request.method(),
uri = %request.uri(),
request_id = request_id,
)
},
),
)
.layer(PropagateRequestIdLayer::x_request_id()),
);
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await
.unwrap();
println!("server listening on http://127.0.0.1:3000");
axum::serve(listener, app).await.unwrap();
}
Run the server, then send a request with an id of your own choosing:
curl -H "x-request-id: req-alpha" http://127.0.0.1:3000/order
The response is order placed, request id req-alpha. The server terminal shows seven JSON lines for that one request, verified by running this program. The handler lines are shown here in full, and the layer lines follow the same shape:
{"timestamp":"2026-11-14T11:48:27.453165Z","level":"INFO","fields":{"message":"validating order"},"target":"t15","span":{"method":"GET","request_id":"req-alpha","uri":"/order","name":"request"},"spans":[{"method":"GET","request_id":"req-alpha","uri":"/order","name":"request"}]}
{"timestamp":"...","level":"INFO","fields":{"message":"order confirmed"},"target":"t15","span":{"method":"GET","request_id":"req-alpha","uri":"/order","name":"request"},"spans":[{"method":"GET","request_id":"req-alpha","uri":"/order","name":"request"}]}
The handler never wrote the id into either line. Both tracing::info! calls pass only a message. The id arrived through the span: the tracing layer read the x-request-id header when the request arrived, recorded it as a span field called request_id, and the JSON formatter printed that field on every line written inside the span. The target reads t15 here because that was the name of the test program that produced the output. In your project it reads your crate name.
How to tell correlation is working:
Send a request with an id you chose, such as req-alpha, and search the server output for that string. If the id appears on the handler lines and on the layer lines, correlation is working. If it appears only in the response header, the id layers work and the span is not carrying the id yet, which is the ordering problem below.
How the Id Gets into the Span
Three pieces do the work, and each one has a single job. The first piece is the setter layer, which runs before anything else and makes sure the request carries an id in its header. The second piece is the span maker, the closure passed to make_span_with, which reads that header and records the value as a span field. The third piece is the formatter, which prints the span fields on every line written inside the span. The handler sits in the middle and does nothing special. Its log calls gain the id for free, because they run inside the span.
The span maker closure deserves a closer look, because it is the only new code on this page. It receives a reference to the incoming request, reads the x-request-id header, and turns the header value into a string. The chain has three steps. The .get("x-request-id") call looks the header up in the header map and returns nothing when the header is absent. The .and_then(|value| value.to_str().ok()) call turns the header value into a string slice, and returns nothing when the value is not valid text. The .unwrap_or("no-request-id") call supplies a fallback string when either step returned nothing, so the field is always present and always searchable. A missing id then shows up in the logs as no-request-id, which is a visible signal, instead of a missing key, which is silent.
The span is created with tracing::info_span!, not the default span maker. The default span maker builds a DEBUG level span, and a DEBUG span is invisible under a plain INFO subscriber, which would hide the id from the logs in production. The info_span! call builds an INFO level span, so the span and its request_id field survive an INFO maximum. The field list is the method, the URI, and the request id. The version field from the default span is gone, because this span maker replaces the default entirely. Every field the span should carry must be listed here, and nothing is inherited from the default.
The % sign before request.method() and request.uri() tells tracing to format those values with their Display form, which prints GET and /order as plain text. The request_id field has no % sign, because it is already a plain string slice, and a string slice prints as itself. In the JSON output the value appears as "request_id":"req-alpha", a plain string, which is what a search tool wants.
The span maker runs once per request, before the handler:
The closure passed to make_span_with runs when the request arrives, before any handler code. It cannot see anything the handler computes, and it cannot read the response. It can only read the request: the method, the path, and the headers. That is why the id comes from the header here, and why the handler reads the typed RequestId value when it needs the id itself.
Why the Layer Order Decides Everything
The setter must run before the tracing layer. The span maker reads the id from the request header at the moment the span is created, and the header only carries the generated id after the setter has run. If the tracing layer runs first, the span is built before the id exists, and the span records the fallback no-request-id instead.
In a ServiceBuilder, the first layer listed runs first. The smallest example lists the setter first, the tracing layer second, and the propagator last, which is the correct order. The propagator runs last on the way in and first on the way out, so it sees the id the setter produced and copies it onto the response.
This ordering failure is silent, which is what makes it expensive. The server still answers, the response still carries the generated id in its header, and the handler still reads the id from its extension. Only the logs are wrong, and they are wrong in a way that looks like a missing feature rather than a bug. The fingerprint of the bug is specific, and it was verified by running the same server with the layers in the wrong order. A request with a client supplied id still shows the id in the span, because that id was already on the request when the span was built. A request with no id shows no-request-id in the span, even though the response header carries a freshly generated UUID. The two cases together point straight at the order: the span maker ran before the setter.
curl -H "x-request-id: client-999" http://127.0.0.1:3000/order
With the layers reversed, this request still logs request_id as client-999 in the span, because the client supplied the id before the server touched the request. But a plain curl http://127.0.0.1:3000/order with no header logs request_id as no-request-id in the span, while the response header carries a generated UUID such as b3a4f4fc-07cb-4fae-9e90-19626353ef53. That split is the fingerprint. If the id is missing from the logs only for clients that send no id, check the layer order first.
Wrong order fails silently and only for generated ids:
A tracing layer running before the setter records no-request-id for every generated id, with no error and no log line, while client supplied ids keep working. That combination hides the bug in every test that sends its own id. Always test with a request that sends no id at all. That single request is the test that catches this mistake.
Two Requests Stay Separate
Correlation only earns its name when two requests run at the same time and their lines stay apart. The test for that is two requests with two different ids, sent one after the other, and then a search for each id in the log output. This was run live against the smallest example, with req-alpha and req-beta, and then a third request with no id at all.
The req-alpha request produced seven lines, and every one of them carried "request_id":"req-alpha" in both the span and the spans objects. The req-beta request produced seven lines, and every one carried "request_id":"req-beta". The two sets of lines interleave in the file in the order the requests arrived, but a search for one id returns only its own seven lines, and never a line from the other request. The counts were checked with jq:
grep '^{' server-logs.jsonl | jq -r 'select(.span.request_id == "req-alpha")' | grep -c timestamp
That command printed 7, the full set of lines for the first request. The same command with req-beta printed 7 as well. A search for one id never returns a line from the other request, because the id is recorded on the span when the request arrives, and each request gets its own span.
The third request sent no id, and the setter generated one, 13471b01-3e94-43b8-a836-42aacfb3db8c. Every one of its seven lines carried that UUID in the span, and the response header carried the same UUID. The generated case works exactly like the client supplied case, which is the point of the setter: the logs do not care who made the id, only that one exists before the span is built.
Reading the logs for one request is then one command:
grep '^{' server-logs.jsonl | jq -r 'select(.span.request_id == "req-alpha") | .fields.message'
Against the live run this printed the messages of the req-alpha request in order: started processing request, validating order, order validated with explicit field, charging payment method, order confirmed, finished processing request, end of stream. That list is the whole story of one request, from arrival to response, with nothing from any other request mixed in.
Following One Request Through the Logs
A reader who receives an id from a client follows it in three steps, and each step is a search, not a reading of the whole file. First, search the log for the id itself, which returns every line the request produced, in time order. Second, read the target values on those lines to see who wrote each one: the handler lines carry the crate name, and the layer lines carry tower_http::trace::on_request and tower_http::trace::on_response. Third, read the fields values for the detail: the latency and status on the response line, the user id and action on the handler lines, and the error message on any error line.
The response line is usually the most informative single line, because it carries the outcome. Its fields hold the latency as a string, such as "0 ms", and the status as a number, such as 200. A request that failed shows a status of 500 on that line, and the error line just before it, if the handler logged one, names the failure. The id ties those two lines together even when thousands of other requests sit between them in the file.
The same id also ties the server log to the client log. When a client reports a failure, it quotes the id from its response header. The server operator searches for that id and finds the matching request, even when the client and the server logs live in different systems. That handoff is the reason the propagator exists: without it, the client never learns the id, and the two logs cannot be joined.
The Id as an Explicit Log Field
The span approach puts the id on every line automatically, and it is the right default. Sometimes one line needs the id even when no span is active, for example a line written in a spawned task that runs after the request finished, or a line written before the span was created. The fix is to pass the id as an explicit field on that one log call, using the typed value the handler reads.
async fn order(Extension(id): Extension<RequestId>) -> String {
let id_str = id.header_value().to_str().unwrap().to_string();
tracing::info!("validating order");
tracing::info!(request_id = %id_str, "order validated with explicit field");
tracing::debug!("charging payment method");
tracing::info!("order confirmed");
format!("order placed, request id {}", id_str)
}
The handler reads the id once, turns it into an owned string, and then uses it in two places: the response body and the explicit field on the second log line. The % sign before id_str formats the string with Display, so the JSON output shows "request_id":"req-alpha" inside fields, next to the message. The run against this handler produced a line that carries the id twice, once in fields and once in the span:
{"timestamp":"...","level":"INFO","fields":{"message":"order validated with explicit field","request_id":"req-alpha"},"target":"t15","span":{"method":"GET","request_id":"req-alpha","uri":"/order","name":"request"},"spans":[{"method":"GET","request_id":"req-alpha","uri":"/order","name":"request"}]}
The duplication is harmless and the search still works, because both keys hold the same value. The explicit field is a backup for lines that leave the span, not a replacement for the span. A handler that writes the id explicitly on every line is doing by hand what the span does automatically, and it will miss a line the first time a helper function logs without the field. Use the span for the request, and the explicit field for the lines that escape it, such as a spawned task that carries the id string with it.
A spawned task leaves the span behind:
A task started with tokio::spawn runs outside the request span, because the span belongs to the request handling future, not to the detached task. Log lines inside the task carry no request_id in their span, even though the request had one. Clone the id string into the task and log it as an explicit field, or the task failures become unlinkable to the request that caused them.
Recording the Id on the Span Later
There is a third way to put the id on the span, for the case where the id is not known when the span is created. The span is built with the request_id field declared as an empty placeholder, and the handler fills it in once it knows the value. The placeholder is tracing::field::Empty, and the fill-in call is Span::current().record.
let trace_layer = TraceLayer::new_for_http().make_span_with(
|request: &axum::extract::Request| {
tracing::info_span!(
"request",
method = %request.method(),
uri = %request.uri(),
request_id = tracing::field::Empty,
)
},
);
The handler then records the value it read from the extension:
async fn order(Extension(id): Extension<RequestId>) -> String {
tracing::Span::current().record(
"request_id",
id.header_value().to_str().unwrap(),
);
tracing::info!("order validated");
format!("order placed, request id {}", id.header_value().to_str().unwrap())
}
A field can only be recorded if the span was created with that field present, even as an empty placeholder. Without the placeholder, the record call silently does nothing, and the id never appears. With it, the handler line and every later line carry the id. This was verified by running the program with the id rec-77: the handler line and the response line carried "request_id":"rec-77", while the started processing request line, which was written before the handler ran, carried no request_id at all.
That timing gap is the cost of this approach. Lines written before the record call cannot carry a value that did not exist yet. The header reading approach from the smallest example has no such gap, because the id is known when the span is created. Use record only when the id genuinely arrives late, for example when the handler computes it from the request body instead of reading it from a header. When the id comes from a header, read the header in the span maker and skip the record entirely.
Keeping the Id Visible at the INFO Level
The smallest example runs the subscriber at DEBUG maximum, which shows every line, including the layer own DEBUG events. A production server usually runs at INFO maximum, which hides the DEBUG events but must keep the id on the handler lines. The info_span! call in the span maker is what makes that work. The span is INFO level, so it survives an INFO maximum, and the handler INFO lines keep their span context.
This was verified by running the same program with .with_max_level(tracing::Level::INFO) instead of DEBUG, and sending a request with the id info-max-1. The output was three lines, all INFO, all carrying the id:
{"timestamp":"2026-11-14T11:50:32.778471Z","level":"INFO","fields":{"message":"validating order"},"target":"t15_info","span":{"method":"GET","request_id":"info-max-1","uri":"/order","name":"request"},"spans":[{"method":"GET","request_id":"info-max-1","uri":"/order","name":"request"}]}
{"timestamp":"...","level":"INFO","fields":{"message":"order validated with explicit field","request_id":"info-max-1"},"target":"t15_info","span":{"method":"GET","request_id":"info-max-1","uri":"/order","name":"request"},"spans":[{"method":"GET","request_id":"info-max-1","uri":"/order","name":"request"}]}
{"timestamp":"...","level":"INFO","fields":{"message":"order confirmed"},"target":"t15_info","span":{"method":"GET","request_id":"info-max-1","uri":"/order","name":"request"},"spans":[{"method":"GET","request_id":"info-max-1","uri":"/order","name":"request"}]}
The DEBUG lines are gone: the started processing request line, the charging payment method line, and the finished processing request line. The three INFO handler lines remain, and each carries the full span with the id. That is the production shape for this page. The id survives, the noise does not, and the only change from the development setup is the level and the span maker using info_span!.
If the span maker had used the default span maker instead, the same INFO maximum would have hidden the span entirely, and the three handler lines would have carried no id at all. The span level and the subscriber maximum must be chosen together. A DEBUG span needs a DEBUG subscriber to be seen. An INFO span is seen by an INFO subscriber. Pick the pair that matches where the server runs.
The Flow of One Id
The whole journey, from the client to the log file, has six stops:
client sends request, with or without x-request-id
|
v
SetRequestIdLayer keeps the id or generates a UUID
|
v
TraceLayer builds the request span and records request_id from the header
|
v
handler runs, logs lines inside the span, reads the id from Extension
|
v
PropagateRequestIdLayer copies the id onto the response
|
v
JSON formatter prints request_id on every line of the request
Every stop depends on the one before it. The setter must run before the span maker, or the span records the fallback. The span must be built before the handler, or the handler lines have no context. The propagator must run after the handler, or the client never learns the id. The formatter prints whatever the span holds, and nothing more. When the id is missing from the logs, walk this chain from the top and find the first stop that is out of order or missing.
Testing That the Id Reaches the Logs
A test can check the whole chain without a running server. It sends a request through the router with oneshot, asserts the response carries the id, and then reads the JSON log file the subscriber wrote and asserts every line carries the same id in its span. The subscriber writes to a file so the test can read it back, and it is installed with set_default, which returns a guard that restores the previous subscriber when dropped.
use axum::{
body::Body,
extract::Extension,
http::{Request, StatusCode},
routing::get,
Router,
};
use std::fs::File;
use tower::ServiceBuilder;
use tower::ServiceExt;
use tower_http::{
request_id::{MakeRequestUuid, PropagateRequestIdLayer, RequestId, SetRequestIdLayer},
trace::TraceLayer,
};
async fn order(Extension(id): Extension<RequestId>) -> String {
tracing::info!("validating order");
id.header_value().to_str().unwrap().to_string()
}
fn app() -> Router {
Router::new()
.route("/order", get(order))
.layer(
ServiceBuilder::new()
.layer(SetRequestIdLayer::x_request_id(MakeRequestUuid))
.layer(
TraceLayer::new_for_http().make_span_with(
|request: &Request<Body>| {
let request_id = request
.headers()
.get("x-request-id")
.and_then(|value| value.to_str().ok())
.unwrap_or("no-request-id");
tracing::info_span!(
"request",
method = %request.method(),
uri = %request.uri(),
request_id = request_id,
)
},
),
)
.layer(PropagateRequestIdLayer::x_request_id()),
)
}
#[tokio::test]
async fn request_id_appears_in_response_and_in_every_log_line() {
let path = "target/test-request-id-logs.jsonl";
let file = File::create(path).unwrap();
let subscriber = tracing_subscriber::fmt()
.json()
.with_writer(file)
.with_max_level(tracing::Level::DEBUG)
.finish();
let _guard = tracing::subscriber::set_default(subscriber);
let response = app()
.oneshot(
Request::builder()
.uri("/order")
.header("x-request-id", "test-req-1")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.headers().get("x-request-id").unwrap().to_str().unwrap(),
"test-req-1"
);
drop(_guard);
let text = std::fs::read_to_string(path).unwrap();
assert!(!text.is_empty());
for line in text.lines() {
let value: serde_json::Value = serde_json::from_str(line).unwrap();
assert_eq!(value["span"]["request_id"], "test-req-1", "line: {}", line);
}
}
The test needs tower with the util feature as a dev dependency, which provides the oneshot method, and serde_json, which is listed in the Cargo.toml of the final complete example below. The drop(_guard) line matters: the guard holds the subscriber, and dropping it releases the file writer, so the file is complete before the test reads it. Run it with cargo test, and the output ends with test result: ok. This exact test was run and passed.
A second test worth writing sends a request with no id at all and asserts the response carries an id anyway. That is the test that catches the ordering bug, because a propagator running before the setter drops generated ids from the response. A test that only ever sends its own id cannot catch it.
Common Beginner Mistakes
Reading the id from the header in every handler
// Wrong - works, but breaks the moment the header name changes
let id = request.headers().get("x-request-id").unwrap();
A header lookup works, until the header name changes and every handler needs editing. The typed Extension<RequestId> value keeps working when the name changes, because the setter stores the same value no matter which header carries it. Read the typed value in handlers, and read the header only in the span maker, where the header is the only source available.
Putting meaningful data in the id
// Wrong - the id is a label, not a data field
tracing::info!(user_id = 42, request_id = "user-42-order-9");
The id is an opaque correlator, a label with no meaning of its own. Encoding a user id or an order number into it lets anyone who sees a log line guess other requests, and it breaks the moment the format changes. Keep the user id and the order number in their own fields, and let the request id stay random.
Logging the id only in the handler
// Wrong - the layer lines and the error lines miss the id
async fn order() -> &'static str {
tracing::info!(request_id = "req-1", "handling order");
"ok"
}
An explicit field on one log call covers that one call. The layer lines, the error lines from other functions, and the lines from helper functions three calls deep never see it. The span carries the id to all of them at once. Use the explicit field only for lines that escape the span.
Using the name RequestIdLayer
// Wrong - this type does not exist in tower-http 0.7
use tower_http::request_id::RequestIdLayer;
There is no type called RequestIdLayer in tower-http 0.7. The compiler reports that it does not exist. The work is split across SetRequestIdLayer and PropagateRequestIdLayer, and the value they pass around is called RequestId. Using the wrong name is a compile error, which is the loud kind of mistake: it fails at build time, not silently at runtime.
Forgetting the request-id feature
// Wrong - the module does not exist without the feature
use tower_http::request_id::SetRequestIdLayer;
Without "request-id" in the tower-http features in Cargo.toml, the tower_http::request_id module does not exist and the import fails. The error points at the import, not at the Cargo.toml, which is why this mistake takes a while to track down. Add the feature and the module appears.
Final Complete Example
This example pulls the page together: the two id layers, the tracing layer with the id in the span, JSON output at DEBUG maximum for development, a handler that reads the typed id and logs an explicit field on one line, and the propagator returning the id to the client.
use axum::{extract::Extension, routing::get, Router};
use tower::ServiceBuilder;
use tower_http::{
request_id::{MakeRequestUuid, PropagateRequestIdLayer, RequestId, SetRequestIdLayer},
trace::TraceLayer,
};
async fn order(Extension(id): Extension<RequestId>) -> String {
let id_str = id.header_value().to_str().unwrap().to_string();
tracing::info!("validating order");
tracing::info!(request_id = %id_str, "order validated with explicit field");
tracing::debug!("charging payment method");
tracing::info!("order confirmed");
format!("order placed, request id {}", id_str)
}
async fn health() -> &'static str {
tracing::debug!("health check answered");
"OK"
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.json()
.with_max_level(tracing::Level::DEBUG)
.init();
let app = Router::new()
.route("/order", get(order))
.route("/health", get(health))
.layer(
ServiceBuilder::new()
.layer(SetRequestIdLayer::x_request_id(MakeRequestUuid))
.layer(
TraceLayer::new_for_http().make_span_with(
|request: &axum::extract::Request| {
let request_id = request
.headers()
.get("x-request-id")
.and_then(|value| value.to_str().ok())
.unwrap_or("no-request-id");
tracing::info_span!(
"request",
method = %request.method(),
uri = %request.uri(),
request_id = request_id,
)
},
),
)
.layer(PropagateRequestIdLayer::x_request_id()),
);
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await
.unwrap();
println!("server listening on http://127.0.0.1:3000");
axum::serve(listener, app).await.unwrap();
}
[package]
name = "request-log-demo"
version = "0.1.0"
edition = "2021"
[dependencies]
axum = "=0.8.9"
tokio = { version = "=1.54.1", features = ["full"] }
tower = { version = "0.5", features = ["util"] }
tower-http = { version = "=0.7.1", features = ["trace", "request-id", "util"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
serde_json = "1"
Try it from a second terminal:
curl -H "x-request-id: req-alpha" http://127.0.0.1:3000/order
curl -H "x-request-id: req-beta" http://127.0.0.1:3000/order
curl http://127.0.0.1:3000/order
The first two answers carry the ids you sent, and the third answers with a generated UUID. Every log line of each request carries its own id in the span, and a search for one id returns only its own lines. For production, change the subscriber maximum to INFO, or read the level from RUST_LOG, and the id stays on the handler lines while the DEBUG layer lines go quiet, because the span is INFO level.
Summary
The decision this page teaches is where the id lives, and the answer is the span, not the log calls. A span field is written once, when the request arrives, and it appears on every line the request produces, including lines from helper functions that never heard of the id. An explicit field is written on one line, and it covers one line.
The framework for the rest is a short chain with one rule: the setter runs before the tracing layer, the tracing layer reads the header into an INFO level span, and the propagator returns the id to the client. When the id is missing from the logs, the chain tells you where to look. A client supplied id that appears and a generated id that does not means the order is wrong. An id that appears nowhere means the span level is below the subscriber maximum. An id that appears on one line only means the line escaped the span and needs an explicit field. Get the chain right once, and every request in the system carries its own name through every log it writes.