-
Notifications
You must be signed in to change notification settings - Fork 773
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
add tracing metrics layer for dependency logging #4979
Merged
AgeManning
merged 19 commits into
sigp:unstable
from
divagant-martian:deps-logging-metrics
Jan 16, 2024
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0087a0e
add metrics layer
divagant-martian 39b2533
add metrics
divagant-martian 57baf2d
simplify getting the target
divagant-martian 71ad6a0
make clippy happy
divagant-martian dc46e92
fix typos
divagant-martian b3e5ea0
unify deps under workspace
divagant-martian 94573c7
make import statement shorter, fix typos
divagant-martian a18c189
enable warn by default, mark flag as deprecated
divagant-martian 908ad21
do not exit on error when initializing logging fails
divagant-martian 9dd307d
revert exit on error
divagant-martian 9a6d862
adjust bootnode logging
divagant-martian 85deec7
use target as is by default
divagant-martian 46e0ec9
make libp2p events register correctly
divagant-martian c2b7423
Merge branch 'unstable' into deps-logging-metrics
divagant-martian f6c4d27
adjust repilcated cli help
divagant-martian c222b36
turn on debug logs by default, remove deprecation warning
divagant-martian e256953
Merge branch 'unstable' into deps-logging-metrics
divagant-martian 0d73f76
suppress output (#5)
divagant-martian 2616cd8
Merge latest unstable
AgeManning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//! Exposes [`MetricsLayer`]: A tracing layer that registers metrics of logging events. | ||
use lighthouse_metrics as metrics; | ||
use tracing_log::NormalizeEvent; | ||
|
||
lazy_static! { | ||
/// Count of `INFO` logs registered per enabled dependency. | ||
pub static ref DEP_INFOS_TOTAL: metrics::Result<metrics::IntCounterVec> = | ||
metrics::try_create_int_counter_vec( | ||
"dep_info_total", | ||
"Count of infos logged per enabled dependency", | ||
&["target"] | ||
); | ||
/// Count of `WARN` logs registered per enabled dependency. | ||
pub static ref DEP_WARNS_TOTAL: metrics::Result<metrics::IntCounterVec> = | ||
metrics::try_create_int_counter_vec( | ||
"dep_warn_total", | ||
"Count of warns logged per enabled dependency", | ||
&["target"] | ||
); | ||
/// Count of `ERROR` logs registered per enabled dependency. | ||
pub static ref DEP_ERRORS_TOTAL: metrics::Result<metrics::IntCounterVec> = | ||
metrics::try_create_int_counter_vec( | ||
"dep_error_total", | ||
"Count of errors logged per enabled dependency", | ||
&["target"] | ||
); | ||
} | ||
|
||
/// Layer that registers Prometheus metrics for `INFO`, `WARN` and `ERROR` logs emitted per dependency. | ||
/// Dependencies are enabled via the `RUST_LOG` env flag. | ||
pub struct MetricsLayer; | ||
|
||
impl<S: tracing_core::Subscriber> tracing_subscriber::layer::Layer<S> for MetricsLayer { | ||
fn on_event( | ||
&self, | ||
event: &tracing_core::Event<'_>, | ||
_ctx: tracing_subscriber::layer::Context<'_, S>, | ||
) { | ||
// get the event's normalized metadata | ||
// this is necessary to get the correct module path for libp2p events | ||
let normalized_meta = event.normalized_metadata(); | ||
let meta = normalized_meta.as_ref().unwrap_or_else(|| event.metadata()); | ||
|
||
if !meta.is_event() { | ||
// ignore tracing span events | ||
return; | ||
} | ||
|
||
let full_target = meta.module_path().unwrap_or_else(|| meta.target()); | ||
let target = full_target | ||
.split_once("::") | ||
.map(|(name, _rest)| name) | ||
.unwrap_or(full_target); | ||
let target = &[target]; | ||
match *meta.level() { | ||
tracing_core::Level::INFO => metrics::inc_counter_vec(&DEP_INFOS_TOTAL, target), | ||
tracing_core::Level::WARN => metrics::inc_counter_vec(&DEP_WARNS_TOTAL, target), | ||
tracing_core::Level::ERROR => metrics::inc_counter_vec(&DEP_ERRORS_TOTAL, target), | ||
_ => {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@AgeManning had to remove this to make the bootnode logging not panic. It seems to work alright, any idea why the rest of the lines were here?
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 they needed to be there in order to get the logs out to display inside slog.
If you run a boot node, do we still get logs to the terminal?
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.
yeah I get them alright. Sample:
first and last are slog ones, middle ones are tracing ones