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

Add opentelemetry source code attributes to spans #1411

Merged
merged 1 commit into from
May 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tracing-opentelemetry/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,22 @@ where
builder.trace_id = Some(self.tracer.new_trace_id());
}

let builder_attrs = builder.attributes.get_or_insert(Vec::new());

let meta = attrs.metadata();

if let Some(filename) = meta.file() {
builder_attrs.push(KeyValue::new("code.filepath", filename));
}

if let Some(module) = meta.module_path() {
builder_attrs.push(KeyValue::new("code.namespace", module));
}

if let Some(line) = meta.line() {
builder_attrs.push(KeyValue::new("code.lineno", line as i64));
}
Comment on lines +436 to +438
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if we want to only produce this attribute if the module_path or file values are present? a line number without a file or module name doesn't make a lot of sense.

on the other hand, the tracing macros will never generate metadata that has a line number without a filename or module path, and i'd be very surprised if any other instrumentation did that. so, it's not a big deal either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that we should try to be defensive and include the maximum possible amount of information on each span.


attrs.record(&mut SpanAttributeVisitor(&mut builder));
extensions.insert(builder);
}
Expand Down