Skip to content

Commit

Permalink
opentelemetry: use static strings for event targets
Browse files Browse the repository at this point in the history
This changes the `tracing-opentelemetry` subscriber to use
`&'static str`s for event targets when possible, similarly to how we did
this for source locations in #1911.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw committed Feb 9, 2022
1 parent 2db3750 commit 4ac91f6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tracing-opentelemetry/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,23 @@ where
let meta = normalized_meta.as_ref().unwrap_or_else(|| event.metadata());
#[cfg(not(feature = "tracing-log"))]
let meta = event.metadata();

let target = Key::new("target");

#[cfg(feature = "tracing-log")]
let target = if normalized_meta.is_some() {
target.string(meta.target().to_owned())
} else {
target.string(event.metadata().target())
};

#[cfg(not(feature = "tracing-log"))]
let target = target.string(meta.target());

let mut otel_event = otel::Event::new(
String::new(),
SystemTime::now(),
vec![
Key::new("level").string(meta.level().to_string()),
Key::new("target").string(meta.target().to_string()),
],
vec![Key::new("level").string(meta.level().to_string()), target],
0,
);
event.record(&mut SpanEventVisitor(&mut otel_event));
Expand Down

0 comments on commit 4ac91f6

Please sign in to comment.