-
Notifications
You must be signed in to change notification settings - Fork 754
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
Remove default impl of Collect::current_span #1268
Remove default impl of Collect::current_span #1268
Conversation
We could also add a re-export of |
I keep forgetting to run |
9a832b7
to
2c64332
Compare
tracing/tests/support/collector.rs
Outdated
fn current_span(&self) -> tracing_core::span::Current { | ||
todo!() | ||
} |
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.
Why's this one todo'd, whereas all the others are unknown?
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.
the test collector probably should actually implement this, it knows the ID of the current span:
current: Mutex<Vec<Id>>, |
and it can look up spans by ID:
spans: Mutex<HashMap<Id, SpanState>>, |
similar to the sloggish
example collector, we would need to add the metadata to the stored span data to implement this properly. in this case, the stored span data is the SpanState
struct:
tracing/tracing/tests/support/collector.rs
Lines 36 to 39 in f867e83
struct SpanState { | |
name: &'static str, | |
refs: usize, | |
} |
we could pretty easily add a &'static Metadata<'static>
to that, allowing us to actually return the current span.
i think this is somewhat important; even though none of the tests currently use the mock collector's current_span
method, it should probably implement the behavior correctly so that we're not surprised when writing future tests that expect it to work...
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.
this feels like a good start. i think there's a few places where we probably ought to add real current_span
implementations instead of just returning unknown
. once that's taken care of, I'll be happy to merge this!
@@ -265,4 +266,8 @@ impl Collect for SloggishCollector { | |||
// TODO: GC unneeded spans. | |||
false | |||
} | |||
|
|||
fn current_span(&self) -> Current { | |||
Current::unknown() |
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.
in this example, the collector does know the current span's ID:
current: CurrentSpanPerThread, |
so, maybe this should return that span? this would require a slightly larger change, modifying the Span
struct to also include a &'static Metadata<'static>
that's stored in new_span
, but then we could write something like this:
Current::unknown() | |
if let Some(id) = self.current.id() { | |
let metadata = self.spans | |
.lock() | |
.unwrap() | |
.get(id) | |
.unwrap_or_else(|| panic!("no metadata stored for span with ID {:?}", id)) | |
.metadata; | |
return Current::new(id, metadata); | |
} | |
Current::none() |
tracing-core/src/dispatch.rs
Outdated
@@ -853,6 +857,10 @@ impl Collect for NoCollector { | |||
|
|||
fn enter(&self, _span: &span::Id) {} | |||
fn exit(&self, _span: &span::Id) {} | |||
|
|||
fn current_span(&self) -> span::Current { | |||
span::Current::unknown() |
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.
nit, this doesn't really matter: i think it might be more correct for the no-op collector to return none
rather than unknown
— the intended semantics is that all spans are disabled when there's no collector, so we are never in a span. with that said, it doesn't really make a difference in practice.
tracing/tests/support/collector.rs
Outdated
fn current_span(&self) -> tracing_core::span::Current { | ||
todo!() | ||
} |
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.
the test collector probably should actually implement this, it knows the ID of the current span:
current: Mutex<Vec<Id>>, |
and it can look up spans by ID:
spans: Mutex<HashMap<Id, SpanState>>, |
similar to the sloggish
example collector, we would need to add the metadata to the stored span data to implement this properly. in this case, the stored span data is the SpanState
struct:
tracing/tracing/tests/support/collector.rs
Lines 36 to 39 in f867e83
struct SpanState { | |
name: &'static str, | |
refs: usize, | |
} |
we could pretty easily add a &'static Metadata<'static>
to that, allowing us to actually return the current span.
i think this is somewhat important; even though none of the tests currently use the mock collector's current_span
method, it should probably implement the behavior correctly so that we're not surprised when writing future tests that expect it to work...
5639206
to
87a6b13
Compare
Sorry, I should have marked this as WIP earlier. I'll try to implement current_span properly where it makes sense but it might take me a while. I don't want to take up too much of your resources or block the release of 0.2 so feel free work on it yourself in the meantime. |
654b790
to
4eeb779
Compare
Okay, I think I implemented all suggestions. From my side there is only one open question: #1268 (comment) |
@dignati Sorry for the delay in responding.
I think we can keep this as-is for now and not worry about it. If you could rebase again the master branch (or I can do it for you!), then I think we're clear to merge this in. |
When we remove the default implementation of `Collect::current_span` implementers of `Collect` that previously relied on the default behaviour will need to use this method.
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
1931e2d
to
76e6462
Compare
No worries! I rebased without any conflicts. |
Is this PR still relevant? I can rebase again if needed, otherwise feel free to close this. |
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 --- thanks for the ping!
Ah, it looks like, post-rebase, the build is failing now because new tracing/tracing-core/src/collect.rs Lines 559 to 691 in 44d3558
We should add |
Thanks for working on this and sorry for the delay in merging! |
Motivation
This removes the default implementation of
tracing_core::Collect::current_span
, which implements part one of #1262.Solution
tracing_core::span::Current::unknown
public so that implementers ofCollect
can use it if they didn't implementcurrent_span()
before.Collect