Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opentelemetry: forward event metadata #1911

Merged
merged 6 commits into from Feb 9, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 23 additions & 11 deletions tracing-opentelemetry/src/subscriber.rs
@@ -1,7 +1,7 @@
use crate::{OtelData, PreSampledTracer};
use opentelemetry::{
trace::{self as otel, noop, TraceContextExt},
Context as OtelContext, Key, KeyValue,
Context as OtelContext, Key, KeyValue, Value,
};
#[cfg(not(feature = "tracing-log"))]
use std::borrow::Cow;
Expand Down Expand Up @@ -571,17 +571,29 @@ where

if self.event_location {
let builder_attrs = builder.attributes.get_or_insert(Vec::new());
if let Some(file) = meta.file() {
#[cfg(feature = "tracing-log")]
builder_attrs.push(KeyValue::new("code.filepath", file.to_owned()));
#[cfg(not(feature = "tracing-log"))]
builder_attrs.push(KeyValue::new("code.filepath", Cow::Borrowed(file)));

#[cfg(feature = "tracing-log")]
let (file, module) = match &normalized_meta {
Some(meta) => (
meta.file().map(|s| Value::from(s.to_owned())),
meta.module_path().map(|s| Value::from(s.to_owned())),
),
None => (
event.metadata().file().map(|s| Value::from(s)),
hawkw marked this conversation as resolved.
Show resolved Hide resolved
event.metadata().module_path().map(|s| Value::from(s)),
hawkw marked this conversation as resolved.
Show resolved Hide resolved
),
};
#[cfg(not(feature = "tracing-log"))]
let (file, module) = (
event.metadata().file().map(|s| Value::from(s)),
event.metadata().module_path().map(|s| Value::from(s)),
hawkw marked this conversation as resolved.
Show resolved Hide resolved
);

if let Some(file) = file {
builder_attrs.push(KeyValue::new("code.filepath", file));
}
if let Some(module) = meta.module_path() {
#[cfg(feature = "tracing-log")]
builder_attrs.push(KeyValue::new("code.namespace", module.to_owned()));
#[cfg(not(feature = "tracing-log"))]
builder_attrs.push(KeyValue::new("code.namespace", Cow::Borrowed(module)));
if let Some(module) = module {
builder_attrs.push(KeyValue::new("code.namespace", module));
}
if let Some(line) = meta.line() {
builder_attrs.push(KeyValue::new("code.lineno", line as i64));
Expand Down