diff options
Diffstat (limited to 'tvix/tracing')
-rw-r--r-- | tvix/tracing/Cargo.toml | 8 | ||||
-rw-r--r-- | tvix/tracing/default.nix | 2 | ||||
-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 |
5 files changed, 23 insertions, 5 deletions
diff --git a/tvix/tracing/Cargo.toml b/tvix/tracing/Cargo.toml index bc9a8c3c7792..80892bf7a09f 100644 --- a/tvix/tracing/Cargo.toml +++ b/tvix/tracing/Cargo.toml @@ -22,6 +22,8 @@ opentelemetry-http = { version = "0.11.0", optional = true } tonic = { version = "0.11.0", optional = true } http = { version = "0.2.11", optional = true } +reqwest-tracing = { version = "0.4.8", default-features = false, optional = true } + [features] default = [] otlp = [ @@ -29,7 +31,8 @@ otlp = [ "dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry_sdk", - "dep:opentelemetry-http" + "dep:opentelemetry-http", + "reqwest-tracing?/opentelemetry_0_22", ] tracy = [ "dep:tracing-tracy" @@ -38,6 +41,9 @@ tonic = [ "dep:tonic", "dep:http", ] +reqwest = [ + "dep:reqwest-tracing", +] [lints] workspace = true diff --git a/tvix/tracing/default.nix b/tvix/tracing/default.nix index dd7dc200f2c6..a4ac9de1c8bc 100644 --- a/tvix/tracing/default.nix +++ b/tvix/tracing/default.nix @@ -6,6 +6,6 @@ meta.ci.targets = lib.filter (x: lib.hasPrefix "with-features" x || x == "no-features") (lib.attrNames passthru); passthru = depot.tvix.utils.mkFeaturePowerset { inherit (old) crateName; - features = [ "otlp" "tracy" ]; + features = [ "otlp" "tracy" "tonic" "reqwest" ]; }; }) 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() +} |