-
Notifications
You must be signed in to change notification settings - Fork 731
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
Conversation
The MSRV failure seems unrelated? |
Yeah, it appears a dependency change broke our MSRV. I'll take care of that. |
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.
overall, this looks good to me; i had some minor suggestions.
09ba39a
to
7304921
Compare
@djc FYI, in general, you don't need to force push to your PRs; we merge PRs by squashing anyway, so it's not necessary to squash your work in progress commits. Generally it's a little easier for me to review PRs that don't rewrite their own history and just make work-in-progress changes as separate commits, so don't worry about force pushing. |
Ah, sorry, yes. |
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 think if we're going to use Cow
s for non-log
events, we should do this even if the tracing-log
feature is enabled; a majority of the events are probably still going to be coming from tracing
and have 'static
metadata, even when the log
support is enabled.
(The nightly failures seem unrelated.) |
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.
okay, this looks good to me --- your approach to handling the tracing-log
feature flag is much nicer than my mess of if
statements 👍
clippy complains about some redundant closures, so i left suggestions for fixing the lints, but besides that, this looks good to me!
Not totally sure what's up with the nightly build failures (that looks wrong to me, possibly a compiler regression of some kind?) but you're right that it's not related to this change. |
CI failure looks like a regression on nightly; I reported an upstream issue rust-lang/rust#93821. AFAICT, there's nothing we should do about fixing it, so I'm going to go ahead and merge this PR despite the nightly build failure. |
Can I get this into a release? I can backport, bump version and add a change log entry. |
@djc normally I take care of all that stuff, but if you'd like to, go ahead! I'll try to get a release out today in any case! |
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>
btw, i noticed some additional allocations we could get rid of: #1917 |
## Motivation Currently, the `tracing-opentelemetry` subscriber will allocate several strings for opentelemetry key-value fields in its `on_event` implementation. Some of these allocations are not necessary, since `opentelemetry::Value::String` can take a `Cow`, allowing `&'static str`s to be used without allocating a new `String`. Since this happens for _every_ event that's recorded to opentelemetry, this probably has a meaningful performance impact. ## Solution This branch makes two primary changes: + Change the `on_event` method to subscriber to use `&'static str`s for event targets when possible, similarly to how we did this for source locations in #1911. This way, when events were not recorded via the `tracing-log` adapter, we will use the `&'static` tracing metadata string for their targets, rather than allocating a new `String`. New `String`s are only allocated when an event came from the `log` crate and its target is not valid for the `'static` lifetime. * Use `Level::as_str` for the `Level` key-value field, instead of `Level::to_string`. `to_string` calls `fmt::Display` and returns a `String`, while `as_str` returns an `&'static str`. This way, levels will never allocate a `String`.
This branch adds the source code file, module path, and line number to OpenTelemetry events as the OpenTelemetry `code.filepath`, `code.namespace`, and `code.lineno` fields, respectively, if they are set in the `tracing` event's metadata. Fixes #1910
## Motivation Currently, the `tracing-opentelemetry` subscriber will allocate several strings for opentelemetry key-value fields in its `on_event` implementation. Some of these allocations are not necessary, since `opentelemetry::Value::String` can take a `Cow`, allowing `&'static str`s to be used without allocating a new `String`. Since this happens for _every_ event that's recorded to opentelemetry, this probably has a meaningful performance impact. ## Solution This branch makes two primary changes: + Change the `on_event` method to subscriber to use `&'static str`s for event targets when possible, similarly to how we did this for source locations in #1911. This way, when events were not recorded via the `tracing-log` adapter, we will use the `&'static` tracing metadata string for their targets, rather than allocating a new `String`. New `String`s are only allocated when an event came from the `log` crate and its target is not valid for the `'static` lifetime. * Use `Level::as_str` for the `Level` key-value field, instead of `Level::to_string`. `to_string` calls `fmt::Display` and returns a `String`, while `as_str` returns an `&'static str`. This way, levels will never allocate a `String`.
This branch adds the source code file, module path, and line number to OpenTelemetry events as the OpenTelemetry `code.filepath`, `code.namespace`, and `code.lineno` fields, respectively, if they are set in the `tracing` event's metadata. Fixes #1910
## Motivation Currently, the `tracing-opentelemetry` subscriber will allocate several strings for opentelemetry key-value fields in its `on_event` implementation. Some of these allocations are not necessary, since `opentelemetry::Value::String` can take a `Cow`, allowing `&'static str`s to be used without allocating a new `String`. Since this happens for _every_ event that's recorded to opentelemetry, this probably has a meaningful performance impact. ## Solution This branch makes two primary changes: + Change the `on_event` method to subscriber to use `&'static str`s for event targets when possible, similarly to how we did this for source locations in #1911. This way, when events were not recorded via the `tracing-log` adapter, we will use the `&'static` tracing metadata string for their targets, rather than allocating a new `String`. New `String`s are only allocated when an event came from the `log` crate and its target is not valid for the `'static` lifetime. * Use `Level::as_str` for the `Level` key-value field, instead of `Level::to_string`. `to_string` calls `fmt::Display` and returns a `String`, while `as_str` returns an `&'static str`. This way, levels will never allocate a `String`.
This branch adds the source code file, module path, and line number to OpenTelemetry events as the OpenTelemetry `code.filepath`, `code.namespace`, and `code.lineno` fields, respectively, if they are set in the `tracing` event's metadata. Fixes #1910
## Motivation Currently, the `tracing-opentelemetry` subscriber will allocate several strings for opentelemetry key-value fields in its `on_event` implementation. Some of these allocations are not necessary, since `opentelemetry::Value::String` can take a `Cow`, allowing `&'static str`s to be used without allocating a new `String`. Since this happens for _every_ event that's recorded to opentelemetry, this probably has a meaningful performance impact. ## Solution This branch makes two primary changes: + Change the `on_event` method to subscriber to use `&'static str`s for event targets when possible, similarly to how we did this for source locations in #1911. This way, when events were not recorded via the `tracing-log` adapter, we will use the `&'static` tracing metadata string for their targets, rather than allocating a new `String`. New `String`s are only allocated when an event came from the `log` crate and its target is not valid for the `'static` lifetime. * Use `Level::as_str` for the `Level` key-value field, instead of `Level::to_string`. `to_string` calls `fmt::Display` and returns a `String`, while `as_str` returns an `&'static str`. This way, levels will never allocate a `String`.
# 0.17.1 (February 11, 2022) ### Added - `OpenTelemetryLayer` can now add detailed location information to forwarded events (defaults to on) ([#1911]) - `OpenTelemetryLayer::with_event_location` to control whether source locations are recorded ([#1911]) ### Changed - Avoid unnecessary allocations to improve performance when recording events ([#1917]) Thanks to @djc for contributing to this release! [#1917]: #1917 [#1911]: #1911 Closes #1919
# 0.17.1 (February 11, 2022) ### Added - `OpenTelemetryLayer` can now add detailed location information to forwarded events (defaults to on) ([#1911]) - `OpenTelemetryLayer::with_event_location` to control whether source locations are recorded ([#1911]) ### Changed - Avoid unnecessary allocations to improve performance when recording events ([#1917]) Thanks to @djc for contributing to this release! [#1917]: #1917 [#1911]: #1911 Closes #1919
# 0.17.1 (February 11, 2022) ### Added - `OpenTelemetryLayer` can now add detailed location information to forwarded events (defaults to on) ([#1911]) - `OpenTelemetryLayer::with_event_location` to control whether source locations are recorded ([#1911]) ### Changed - Avoid unnecessary allocations to improve performance when recording events ([#1917]) Thanks to @djc for contributing to this release! [#1917]: tokio-rs/tracing#1917 [#1911]: tokio-rs/tracing#1911 Closes #1919
This branch adds the source code file, module path, and line number to OpenTelemetry events as the OpenTelemetry `code.filepath`, `code.namespace`, and `code.lineno` fields, respectively, if they are set in the `tracing` event's metadata. Fixes tokio-rs#1910
…1917) ## Motivation Currently, the `tracing-opentelemetry` subscriber will allocate several strings for opentelemetry key-value fields in its `on_event` implementation. Some of these allocations are not necessary, since `opentelemetry::Value::String` can take a `Cow`, allowing `&'static str`s to be used without allocating a new `String`. Since this happens for _every_ event that's recorded to opentelemetry, this probably has a meaningful performance impact. ## Solution This branch makes two primary changes: + Change the `on_event` method to subscriber to use `&'static str`s for event targets when possible, similarly to how we did this for source locations in tokio-rs#1911. This way, when events were not recorded via the `tracing-log` adapter, we will use the `&'static` tracing metadata string for their targets, rather than allocating a new `String`. New `String`s are only allocated when an event came from the `log` crate and its target is not valid for the `'static` lifetime. * Use `Level::as_str` for the `Level` key-value field, instead of `Level::to_string`. `to_string` calls `fmt::Display` and returns a `String`, while `as_str` returns an `&'static str`. This way, levels will never allocate a `String`.
# 0.17.1 (February 11, 2022) ### Added - `OpenTelemetryLayer` can now add detailed location information to forwarded events (defaults to on) ([tokio-rs#1911]) - `OpenTelemetryLayer::with_event_location` to control whether source locations are recorded ([tokio-rs#1911]) ### Changed - Avoid unnecessary allocations to improve performance when recording events ([tokio-rs#1917]) Thanks to @djc for contributing to this release! [tokio-rs#1917]: tokio-rs#1917 [tokio-rs#1911]: tokio-rs#1911 Closes tokio-rs#1919
Fixes #1910.