Confirm the per-request root-span middleware works on actix-web 4 + otel 0.31 #136
Notifications
Due Date
No due date set.
Blocks
Reference: Apps/ImageApi#136
Reference in new issue
Block a user
Part of #135
Question
Which conventional Actix middleware gives us a per-request root span that (a) starts a
tracingspan for each HTTP request, (b) extracts an incoming W3Ctraceparentheader so upstream traces connect, and (c) works on our actix-web version +opentelemetry0.31.0?Candidates:
opentelemetry-instrumentation-actix-web(RequestTracing) — the OTel-native middleware. Check the version that targets otel 0.31 and whether it integrates withtracing(or needstracing-opentelemetryalongside).tracing-actix-web— known dead for OTel (its OTel layer stopped at otel 0.16); determine whether its plain tracing middleware is still useful, or fully displaced.Deliverable
The recommended option, exact crate + version (or hand-rolled shape), whether it extracts
traceparentand links to the OTLP tracer, and how handlers get the request span (#[instrument]or ambient). If the docs are ambiguous, a minimal compile-check prototype on a scratch branch is acceptable — link it as an asset.Resolution — use
tracing-actix-web0.7.25 with theopentelemetry_0_31featureDecision:
tracing-actix-web = { version = "0.7.25", features = ["opentelemetry_0_31"] }, registered asTracingLoggerin the actixApp. No hand-rolled middleware needed.Why it fits:
TracingLoggerwraps each request in atracingroot span; every child span created during the request nests under it automatically. No OTel↔tracing impedance.traceparent.set_otel_parent(itssrc/otel.rs) reads the request headers through the global text-map propagator and callsspan.set_parent(parent_context), so the root span links to the upstream trace (and recordstrace_id).opentelemetry_0_31feature pullsopentelemetry 0.31+tracing-opentelemetry 0.32— exactly the pair this repo needs. No OTel bump.actix/actix-extras; 0.7.25 is current and supports OTel through 0.32 via per-version feature flags.Correction to a prior assumption.
tracing-actix-webwas earlier believed dead for OTel > 0.16 (its OTel layer "stopped at 0.16"). That is stale: OTel 0.31 support landed in PR #144, and the crate tracks OTel per feature flag. Confirmed againstsrc/otel.rs+Cargo.tomlonactix/actix-extrasmain.Rejected alternative:
opentelemetry-instrumentation-actix-web(RequestTracing). It emits raw OTel spans, nottracingspans, and its 0.24 line dropped itstracingdependency and targets otel 0.32. Handing the root span to the raw OTel tracer while children come fromtracingwould need a reverse bridge that doesn't exist, so it does not compose with a tracing-native migration. It would also pull a second otel version.Required companion change (new fact for #138 and #139): the app currently never calls
opentelemetry::global::set_text_map_propagator(...)— it constructsTraceContextPropagator::new()ad hoc inotel::extract_context_from_request.tracing-actix-webreads the global propagator, so startup must now call:Without it,
get_text_map_propagatorreturns the default no-op propagator andtraceparentextraction silently no-ops.Wiring:
TracingLogger::default()in the actixApp(main.rs/service.rs).tracing_opentelemetry::OpenTelemetryLayerso the root span is exported and the parent set byset_otel_parenttakes effect.#[instrument]for named child spans or theRootSpanextractor to enrich it. The per-handlerextract_context_from_request+tracer.start_with_contextboilerplate is dropped.Verdict: conventional, tracing-native, exact-version-fit; adopt it and close this ticket.