trace: When a span's explicit parent is disabled, the parent should probably be contextual #88
Labels
crate/tracing
Related to the `tracing` crate
kind/feature
New feature or request
meta/breaking
This is a breaking change, and should wait until the next breaking release.
Milestone
In
tokio-trace
, when constructing a span usingSpan::child_of
, we accept a type that can provide us anOption<&Id>
as the span's parent. This allows writing code like this:It's necessary to take an
Option<&Id>
here rather than just&Id
, as the parent span may not be enabled --- for example, in the snippet above, we might have a filter set that accepts spans withLevel::DEBUG
and lower, sofoo
would be disabled.Currently, if the parent span is disabled, we call
Attributes::new_root
:https://github.com/tokio-rs/tokio/blob/84d5a7f5a0660dbe1e2be0e831e715f13cb59a2b/tokio-trace/src/span.rs#L251-L254
I think this behaviour is fairly surprising. Consider the following:
If we run this code with the max verbosity level set to
INFO
,bar
is disabled, sobaz
's parent isNone
, making it the root of a new trace tree. This seems incorrect to me --- I'd only expect a span to be a root if I explicitly set it to not have a parent. Instead, in the case where the explicitly set parent is disabled, I'd expect the span to have a contextual parent.The text was updated successfully, but these errors were encountered: