Skip to content

Commit

Permalink
chore: cleanup MetadataInjector
Browse files Browse the repository at this point in the history
  • Loading branch information
hseeberger committed Aug 19, 2023
1 parent e7265cf commit 3200f48
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions hello-tracing-common/src/otel/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tonic::{
metadata::{MetadataKey, MetadataMap, MetadataValue},
Request, Status,
};
use tracing::{error, Span};
use tracing::{warn, Span};
use tracing_opentelemetry::OpenTelemetrySpanExt;

/// Trace context propagation: send the trace context by injecting it into the metadata of the given
Expand All @@ -22,23 +22,15 @@ struct MetadataInjector<'a>(&'a mut MetadataMap);
impl Injector for MetadataInjector<'_> {
fn set(&mut self, key: &str, value: String) {
match MetadataKey::from_bytes(key.as_bytes()) {
Ok(name) => match MetadataValue::try_from(&value) {
Ok(key) => match MetadataValue::try_from(&value) {
Ok(value) => {
self.0.insert(name, value);
self.0.insert(key, value);
}

Err(error) => error!(
value,
error = format!("{error:#}"),
"parse value as metadata value"
),
Err(error) => warn!(value, error = format!("{error:#}"), "parse metadata value"),
},

Err(error) => error!(
key,
error = format!("{error:#}"),
"parse key as metadata value"
),
Err(error) => warn!(key, error = format!("{error:#}"), "parse metadata key"),
}
}
}

0 comments on commit 3200f48

Please sign in to comment.