about summary refs log tree commit diff
path: root/tvix/tracing/src/propagate
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/tracing/src/propagate')
-rw-r--r--tvix/tracing/src/propagate/mod.rs4
-rw-r--r--tvix/tracing/src/propagate/reqwest.rs13
2 files changed, 15 insertions, 2 deletions
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()
+}