-
Notifications
You must be signed in to change notification settings - Fork 734
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
Add opentelemetry source code attributes to spans #1411
Conversation
The opentelemetry specification calls for a number of attributes to correlate traces to their location in the code. They are documented here [1]. This commit adds support for the following fields based on the tracing span metadata (all relative to span creation): - `code.namespace`: Crate & module path (`my_crate::my_mod`) - `code.filepath`: Relative path to the source code file (`src/my_mod.rs`) - `code.lineno`: Line number in the file indicated by `code.filepath` (`72`) As written this will annotate all spans with these attributes. If we want to be a bit more conservative, I could add an instance variable to the Subscriber that allows users to opt-in or opt-out of this functionality. [1]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#source-code-attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me!
if let Some(line) = meta.line() { | ||
builder_attrs.push(KeyValue::new("code.lineno", line as i64)); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Looking at the existing benchmarks it appears this may have a performance impact for cases that don't have many fields. Perhaps worth adding a flag here? |
The opentelemetry specification calls for a number of attributes to correlate traces to their location in the code. They are documented here [1]. This commit adds support for the following fields based on the tracing span metadata (all relative to span creation): - `code.namespace`: Crate & module path (`my_crate::my_mod`) - `code.filepath`: Relative path to the source code file (`src/my_mod.rs`) - `code.lineno`: Line number in the file indicated by `code.filepath` (`72`) As written this will annotate all spans with these attributes. If we want to be a bit more conservative, I could add an instance variable to the Subscriber that allows users to opt-in or opt-out of this functionality. [1]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#source-code-attributes Co-authored-by: Lily Mara <lilymara@onesignal.com>
The opentelemetry specification calls for a number of attributes to correlate traces to their location in the code. They are documented here [1]. This commit adds support for the following fields based on the tracing span metadata (all relative to span creation): - `code.namespace`: Crate & module path (`my_crate::my_mod`) - `code.filepath`: Relative path to the source code file (`src/my_mod.rs`) - `code.lineno`: Line number in the file indicated by `code.filepath` (`72`) As written this will annotate all spans with these attributes. If we want to be a bit more conservative, I could add an instance variable to the Subscriber that allows users to opt-in or opt-out of this functionality. [1]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#source-code-attributes Co-authored-by: Lily Mara <lilymara@onesignal.com>
# 0.14.0 (July 9, 2021) ### Breaking Changes - Upgrade to `v0.15.0` of `opentelemetry` ([#1441]) For list of breaking changes in OpenTelemetry, see the [v0.14.0 changelog](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry/CHANGELOG.md#v0140). ### Added - Spans now include Opentelemetry `code.namespace`, `code.filepath`, and `code.lineno` attributes ([#1411]) ### Changed - Improve performance by pre-allocating attribute `Vec`s ([#1327]) Thanks to @Drevoed, @lilymara-onesignal, and @Folyd for contributing to this release!
# 0.14.0 (July 9, 2021) ### Breaking Changes - Upgrade to `v0.15.0` of `opentelemetry` ([#1441]) For list of breaking changes in OpenTelemetry, see the [v0.14.0 changelog](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry/CHANGELOG.md#v0140). ### Added - Spans now include Opentelemetry `code.namespace`, `code.filepath`, and `code.lineno` attributes ([#1411]) ### Changed - Improve performance by pre-allocating attribute `Vec`s ([#1327]) Thanks to @Drevoed, @lilymara-onesignal, and @Folyd for contributing to this release! Closes #1462
Is there any way to disable it ? |
…io-rs#1411) The opentelemetry specification calls for a number of attributes to correlate traces to their location in the code. They are documented here [1]. This commit adds support for the following fields based on the tracing span metadata (all relative to span creation): - `code.namespace`: Crate & module path (`my_crate::my_mod`) - `code.filepath`: Relative path to the source code file (`src/my_mod.rs`) - `code.lineno`: Line number in the file indicated by `code.filepath` (`72`) As written this will annotate all spans with these attributes. If we want to be a bit more conservative, I could add an instance variable to the Subscriber that allows users to opt-in or opt-out of this functionality. [1]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/span-general.md#source-code-attributes Co-authored-by: Lily Mara <lilymara@onesignal.com>
# 0.14.0 (July 9, 2021) ### Breaking Changes - Upgrade to `v0.15.0` of `opentelemetry` ([tokio-rs#1441]) For list of breaking changes in OpenTelemetry, see the [v0.14.0 changelog](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry/CHANGELOG.md#v0140). ### Added - Spans now include Opentelemetry `code.namespace`, `code.filepath`, and `code.lineno` attributes ([tokio-rs#1411]) ### Changed - Improve performance by pre-allocating attribute `Vec`s ([tokio-rs#1327]) Thanks to @Drevoed, @lilymara-onesignal, and @Folyd for contributing to this release! Closes tokio-rs#1462
Motivation
There is some more context in #1397 but the main idea is that we should be able to trace a Span back to the location in the code where it was created. Currently many crates have spans with very generic names (
h2
hassend_data
andreserve_capacity
) and this makes it very difficult to figure out where spans are coming from. This change will make it much easier to find the location in the code where spans are created.Solution
We can capture the location information using the existing location data on the
tracing::Span
.The opentelemetry specification calls for a number of attributes to correlate
traces to their location in the code. They are documented here 1. This commit
adds support for the following fields based on the tracing span metadata (all
relative to span creation):
code.namespace
: Crate & module path (my_crate::my_mod
)code.filepath
: Relative path to the source code file (src/my_mod.rs
)code.lineno
: Line number in the file indicated bycode.filepath
(72
)As written this will annotate all spans with these attributes. If we want to be
a bit more conservative, I could add an instance variable to the Subscriber that
allows users to opt-in or opt-out of this functionality.
Note
I saw that there is a requirement to add tests for new functionality, but I do not see any tests around the attributes that this crate adds to opentelemetry Spans and Events. I have not added any tests because I'm not sure how to write those or where they would go.