diff options
author | Simon Hauser <simon.hauser@helsinki-systems.de> | 2024-06-27T08·27+0200 |
---|---|---|
committer | Simon Hauser <simon.hauser@helsinki-systems.de> | 2024-07-02T13·43+0000 |
commit | 618aacaa61972c3e25b8c996abfa1d4dc475154e (patch) | |
tree | 7fc41bff9ed6e21b36d6768ffd457590f89dba6e /tvix/tracing/src | |
parent | 7f8da5e6a9926170be2fefc1db847166e5631f16 (diff) |
feat(tvix/tracing): http trace propagation r/8339
Introduces a helper function within tvix-tracing that returns a reqwest tracing middleware that will ingest the traceparent if otlp is enabled. It is feature flagged in tvix-tracing so not every consumer of that library automatically has reqwest in its dependencies. Tested using netcat to verify that the `traceparent` header is there if otlp is enabled and missing if otlp feature is disabled. Change-Id: I5abccae777b725f5ff7382e3686165383c477a39 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11886 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/tracing/src')
-rw-r--r-- | tvix/tracing/src/lib.rs | 1 | ||||
-rw-r--r-- | tvix/tracing/src/propagate/mod.rs | 4 | ||||
-rw-r--r-- | tvix/tracing/src/propagate/reqwest.rs | 13 |
3 files changed, 15 insertions, 3 deletions
diff --git a/tvix/tracing/src/lib.rs b/tvix/tracing/src/lib.rs index b914408ff4c7..35fdcda5a88a 100644 --- a/tvix/tracing/src/lib.rs +++ b/tvix/tracing/src/lib.rs @@ -17,7 +17,6 @@ use opentelemetry_sdk::{ #[cfg(feature = "tracy")] use tracing_tracy::TracyLayer; -#[cfg(feature = "tonic")] // TODO or http pub mod propagate; lazy_static! { diff --git a/tvix/tracing/src/propagate/mod.rs b/tvix/tracing/src/propagate/mod.rs index 42c532e9d8cf..9a7e4332b637 100644 --- a/tvix/tracing/src/propagate/mod.rs +++ b/tvix/tracing/src/propagate/mod.rs @@ -1,8 +1,8 @@ #[cfg(feature = "tonic")] pub mod tonic; -// TODO: Helper library for reqwest. We could use -// https://github.com/TrueLayer/reqwest-middleware/tree/main/reqwest-tracing to realise this +#[cfg(feature = "reqwest")] +pub mod reqwest; // TODO: Helper library for axum or another http server, see // https://github.com/hseeberger/hello-tracing-rs/blob/main/hello-tracing-common/src/otel/http.rs diff --git a/tvix/tracing/src/propagate/reqwest.rs b/tvix/tracing/src/propagate/reqwest.rs new file mode 100644 index 000000000000..e2afb3e948c7 --- /dev/null +++ b/tvix/tracing/src/propagate/reqwest.rs @@ -0,0 +1,13 @@ +use reqwest_tracing::{SpanBackendWithUrl, TracingMiddleware}; + +/// Returns a new tracing middleware which can be used with reqwest_middleware. +/// It will then write the `traceparent` in the header on the request and additionally records the +/// `url` into `http.url`. +/// +/// If otlp feature is disabled, this will not insert a `traceparent` into the header. It will +/// basically function as a noop. +/// +/// `traceparent` => https://www.w3.org/TR/trace-context/#trace-context-http-headers-format +pub fn tracing_middleware() -> TracingMiddleware<SpanBackendWithUrl> { + TracingMiddleware::<SpanBackendWithUrl>::new() +} |