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

subscriber: default event formatters don't honor explicit parents #766

Closed
hawkw opened this issue Jun 24, 2020 · 0 comments · Fixed by #767
Closed

subscriber: default event formatters don't honor explicit parents #766

hawkw opened this issue Jun 24, 2020 · 0 comments · Fixed by #767
Labels
crate/subscriber Related to the `tracing-subscriber` crate kind/bug Something isn't working

Comments

@hawkw
Copy link
Member

hawkw commented Jun 24, 2020

Currently, the event formatter implementations provided by tracing-subscriber's fmt module don't actually honor the explicitly-set parent of an event, if one is set. Instead, they will always format a context based on the current span.

See:

No, I tried that for quite a while before I understood that that cannot work: the span is closed, so the .scope() will not include it when iterating, so the span’s fields are not printed by some existing magic :-(

Hmm, after taking a look at format_event, you're right, but that's actually due to a bug in the format_event implementation for the default formatters. It looks like they always print the current span's scope as the context, even if the event has an explicitly set parent. We should fix that, and print the event's explicit parent's scope if one is set. Then, using new_child_of to create the synthesized event would include that span in the scope (since its data is only removed from the registry after on_close completes).

Originally posted by @hawkw in #761

It would be nice to fix this.

@hawkw hawkw added crate/subscriber Related to the `tracing-subscriber` crate kind/bug Something isn't working labels Jun 24, 2020
hawkw added a commit that referenced this issue Jun 24, 2020
## Motivation

Currently, the default formatter implementations in
`tracing-subscriber`'s `fmt` module do not handle explicitly set parent
spans for events, such as

```rust
let span = tracing::info_span!("some_interesting_span");
tracing::info!(parent: &span, "something is happening!");
```

Instead, when formatting the span context of an event, the context is
_always_ generated from the current span, even when the event has an
overridden parent. This is not correct.

## Solution

This branch changes the default context formatters to use the explicit
parent ID, if it is present. Otherwise, the contexual parent is used, as
it was previously.

I've also added tests ensuring that this works correctly, and removed
some workarounds for the previous incorrect behavior from the examples.

Fixes #766

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/subscriber Related to the `tracing-subscriber` crate kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant