-
Notifications
You must be signed in to change notification settings - Fork 701
Logging (1/2): new delay detector #9540
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
Conversation
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.
🥇
use tracing_subscriber::Layer; | ||
|
||
#[derive(Default)] | ||
pub(crate) struct DelayDetectorLayer {} |
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.
How about TracingSpanDurationLogger or Subscriber?
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.
Thank you for the suggestion. SpanDurationLogger
should be clear enough.
let mut extensions = span.extensions_mut(); | ||
if let Some(timings) = extensions.get_mut::<Timings>() { | ||
let now = Instant::now(); | ||
timings.idle += (now - timings.last).as_nanos() as u64; |
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.
Use Instant::duration_since
, or preferably checked_duration_since
. Although Instant
should never go backwards, that unfortunately does not always hold experimentally, and we would rather not have neard crash because of a debugging feature.
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.
duration_since()
doesn't panic given a timestamp later than self
, but saturates: https://doc.rust-lang.org/std/time/struct.Instant.html#method.duration_since
let span = ctx.span(&id).expect("Span not found, this is a bug"); | ||
let extensions = span.extensions(); | ||
if let Some(Timings { busy, mut idle, last }) = extensions.get::<Timings>() { | ||
idle += (Instant::now() - *last).as_nanos() as u64; |
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 would perhaps add a method to Timings
along the lines of
impl Timings {
fn observe_idle(&mut self) {
let previous = std::mem::replace(self.last, Instant::now());
self.idle += self.last.checked_duration_since(previous).map_or(0, |d| d.as_nanos());
}
}
Thus reusing the logic between this and on_enter
.
The `lib.rs` file accumulated structs and functionality from different areas. Split the file into several smaller files.
The `lib.rs` file accumulated structs and functionality from different areas. Split the file into several smaller files.
The `lib.rs` file accumulated structs and functionality from different areas. Split the file into several smaller files.
* Logging: New delay detector * Logging: New delay detector * Logging: New delay detector * Logging: New delay detector * Rename to SpanDurationLogger * Use Durations instead of nanoseconds * refactor: Tracing (#9544) The `lib.rs` file accumulated structs and functionality from different areas. Split the file into several smaller files. * Logging: New delay detector * Rename to SpanDurationLogger * Use Durations instead of nanoseconds * Use Durations instead of nanoseconds * refactor: Tracing (#9544) The `lib.rs` file accumulated structs and functionality from different areas. Split the file into several smaller files. * Logging: New delay detector * refactor: Tracing (#9544) The `lib.rs` file accumulated structs and functionality from different areas. Split the file into several smaller files. * Use Durations instead of nanoseconds
Continues #9540 Deletes the `DelayDetector` class and replaces the uses of it with spans. --------- Co-authored-by: Anton Puhach <anton@near.org> Co-authored-by: Simonas Kazlauskas <git@kazlauskas.me> Co-authored-by: Jakob Meier <mail@jakobmeier.ch>
* Logging: New delay detector * Logging: New delay detector * Logging: New delay detector * Logging: New delay detector * Rename to SpanDurationLogger * Use Durations instead of nanoseconds * refactor: Tracing (#9544) The `lib.rs` file accumulated structs and functionality from different areas. Split the file into several smaller files. * Logging: New delay detector * Rename to SpanDurationLogger * Use Durations instead of nanoseconds * Use Durations instead of nanoseconds * refactor: Tracing (#9544) The `lib.rs` file accumulated structs and functionality from different areas. Split the file into several smaller files. * Logging: New delay detector * refactor: Tracing (#9544) The `lib.rs` file accumulated structs and functionality from different areas. Split the file into several smaller files. * Use Durations instead of nanoseconds
Continues #9540 Deletes the `DelayDetector` class and replaces the uses of it with spans. --------- Co-authored-by: Anton Puhach <anton@near.org> Co-authored-by: Simonas Kazlauskas <git@kazlauskas.me> Co-authored-by: Jakob Meier <mail@jakobmeier.ch>
* Logging: New delay detector * Logging: New delay detector * Logging: New delay detector * Logging: New delay detector * Rename to SpanDurationLogger * Use Durations instead of nanoseconds * refactor: Tracing (#9544) The `lib.rs` file accumulated structs and functionality from different areas. Split the file into several smaller files. * Logging: New delay detector * Rename to SpanDurationLogger * Use Durations instead of nanoseconds * Use Durations instead of nanoseconds * refactor: Tracing (#9544) The `lib.rs` file accumulated structs and functionality from different areas. Split the file into several smaller files. * Logging: New delay detector * refactor: Tracing (#9544) The `lib.rs` file accumulated structs and functionality from different areas. Split the file into several smaller files. * Use Durations instead of nanoseconds
Continues #9540 Deletes the `DelayDetector` class and replaces the uses of it with spans. --------- Co-authored-by: Anton Puhach <anton@near.org> Co-authored-by: Simonas Kazlauskas <git@kazlauskas.me> Co-authored-by: Jakob Meier <mail@jakobmeier.ch>
Continues #9540 Deletes the `DelayDetector` class and replaces the uses of it with spans. --------- Co-authored-by: Anton Puhach <anton@near.org> Co-authored-by: Simonas Kazlauskas <git@kazlauskas.me> Co-authored-by: Jakob Meier <mail@jakobmeier.ch>
Improves the logging system to automatically export durations of spans as metrics and detect spans taking too long.
This PR compliments the functionality Grafana Tempo.
Changes:
Performance impact should be minimal.
Memory usage increase is minimal.