feat(tvix/tracing): http trace propagation
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>
This commit is contained in:
parent
7f8da5e6a9
commit
618aacaa61
10 changed files with 302 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
13
tvix/tracing/src/propagate/reqwest.rs
Normal file
13
tvix/tracing/src/propagate/reqwest.rs
Normal file
|
|
@ -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()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue