From 89361b2a7fb33102f8a953c3f47b863210ba4eb0 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 25 Jun 2024 20:53:11 +0300 Subject: fix(tvix/tracing): make cargo check and clippy happy In case the otlp feature is not enabled, these generate warnings during `cargo check`. Fix by moving some imports into their functions, or using the fully-qualified name (and one #[allow(unused_mut)]) Change-Id: I5afd89dcd4c772b6002cebdd5d0469932eacfdac Reviewed-on: https://cl.tvl.fyi/c/depot/+/11873 Autosubmit: flokli Tested-by: BuildkiteCI Reviewed-by: Connor Brewster Reviewed-by: Simon Hauser --- tvix/tracing/src/propagate/tonic.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'tvix/tracing/src/propagate/tonic.rs') diff --git a/tvix/tracing/src/propagate/tonic.rs b/tvix/tracing/src/propagate/tonic.rs index af643eb70e36..75455c056617 100644 --- a/tvix/tracing/src/propagate/tonic.rs +++ b/tvix/tracing/src/propagate/tonic.rs @@ -1,9 +1,3 @@ -use tonic::{ - metadata::{MetadataKey, MetadataMap, MetadataValue}, - Status, -}; -use tracing::{warn, Span}; - #[cfg(feature = "otlp")] use opentelemetry::{global, propagation::Injector}; #[cfg(feature = "otlp")] @@ -22,17 +16,20 @@ pub fn accept_trace(request: http::Request) -> http::Request { let parent_context = global::get_text_map_propagator(|propagator| { propagator.extract(&HeaderExtractor(request.headers())) }); - Span::current().set_parent(parent_context); + tracing::Span::current().set_parent(parent_context); } request } #[cfg(feature = "otlp")] -struct MetadataInjector<'a>(&'a mut MetadataMap); +struct MetadataInjector<'a>(&'a mut tonic::metadata::MetadataMap); #[cfg(feature = "otlp")] impl Injector for MetadataInjector<'_> { fn set(&mut self, key: &str, value: String) { + use tonic::metadata::{MetadataKey, MetadataValue}; + use tracing::warn; + match MetadataKey::from_bytes(key.as_bytes()) { Ok(key) => match MetadataValue::try_from(&value) { Ok(value) => { @@ -47,11 +44,12 @@ impl Injector for MetadataInjector<'_> { /// Trace context propagation: send the trace context by injecting it into the metadata of the given /// request. This only injects the current span if the otlp feature is also enabled. -pub fn send_trace(mut request: tonic::Request) -> Result, Status> { +#[allow(unused_mut)] +pub fn send_trace(mut request: tonic::Request) -> Result, tonic::Status> { #[cfg(feature = "otlp")] { global::get_text_map_propagator(|propagator| { - let context = Span::current().context(); + let context = tracing::Span::current().context(); propagator.inject_context(&context, &mut MetadataInjector(request.metadata_mut())) }); } -- cgit 1.4.1