about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-06-25T17·53+0300
committerflokli <flokli@flokli.de>2024-06-26T06·27+0000
commit89361b2a7fb33102f8a953c3f47b863210ba4eb0 (patch)
tree37552bfcf94f907e6a88e005e70841636ab2220b
parenta0993e7304ce388aea19f79847815c6ea05fecc1 (diff)
fix(tvix/tracing): make cargo check and clippy happy r/8310
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 <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Reviewed-by: Simon Hauser <simon.hauser@helsinki-systems.de>
-rw-r--r--tvix/tracing/src/propagate/tonic.rs18
1 files changed, 8 insertions, 10 deletions
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<B>(request: http::Request<B>) -> http::Request<B> {
         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<T>(mut request: tonic::Request<T>) -> Result<tonic::Request<T>, Status> {
+#[allow(unused_mut)]
+pub fn send_trace<T>(mut request: tonic::Request<T>) -> Result<tonic::Request<T>, 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()))
         });
     }