Add the per-request root span (middleware) and drop per-handler boilerplate #139
Notifications
Due Date
No due date set.
Reference: Apps/ImageApi#139
Reference in new issue
Block a user
Part of #135
Work
Apply the middleware chosen in "Confirm the per-request root-span middleware works on actix-web 4 + otel 0.31" so every request gets a root span plus incoming
traceparentextraction, then remove the per-handlerextract_context_from_request+tracer.start_with_contextboilerplate.main.rs/service.rs).#[instrument]where they still need a named span; drop the manual context threading into handlers.Resolution
How the root span is created, and confirmation the per-handler boilerplate is gone.
Resolved on
feature/tracing-migration(commit350b748).What was done
tracing-actix-web0.7.25 added with theopentelemetry_0_31feature;TracingLogger::default()registered as the outermost Actix middleware inmain.rs. It creates one OTel server span per request and extracts an incoming W3Ctraceparentonto it via the global text-map propagator (installed in #138).extract_context_from_requestnow delegates: it sources the parent from the root span (tracing::Span::current().context()) instead of re-parsing the header. Existing per-handler operation spans therefore nest under the root span (one trace tree) rather than duplicating it as a sibling. Header parsing stays as a fallback for handlers invoked without the middleware (e.g. direct tests).#[instrument]in the LLM (#140) and DAO (#141) migrations, where the&Contextthreading disappears entirely.Verification
tests/otel_traceparent.rs(new, end-to-end): an incomingtraceparent'strace_idpropagates to the request, the root span is parented on the caller's remote span, and the operation span nests under the root span (not a sibling). Confirmed captured spans: rootGET /ophasparent=<remote>/remote=true;test.operationhasparent=<root span id>, both sharing the caller'strace_id.cargo clippy --all-targets: 0 warnings.Note: a startup smoke-run of the full binary couldn't bind in this environment because
main.rsalso binds a fixedlocalhost:8088(held by the running production server); the integration test exercises the middleware at runtime and is the authoritative check.