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

add metrics counters for warn! and info! logs #13552

Merged
merged 11 commits into from
Jun 21, 2024
9 changes: 8 additions & 1 deletion crates/aptos-logger/src/aptos_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use crate::{
sample,
sample::SampleRate,
telemetry_log_writer::{TelemetryLog, TelemetryLogWriter},
Event, Filter, Key, Level, LevelFilter, Metadata,
Event, Filter, Key, Level, LevelFilter, Metadata, ERROR_LOG_COUNT, INFO_LOG_COUNT,
WARN_LOG_COUNT,
};
use aptos_infallible::RwLock;
use backtrace::Backtrace;
Expand Down Expand Up @@ -604,6 +605,12 @@ impl LoggerService {
match event {
LoggerServiceEvent::LogEntry(entry) => {
PROCESSED_STRUCT_LOG_COUNT.inc();
match entry.metadata.level() {
Level::Error => ERROR_LOG_COUNT.inc(),
Level::Warn => WARN_LOG_COUNT.inc(),
Level::Info => INFO_LOG_COUNT.inc(),
_ => {},
}

if let Some(printer) = &mut self.printer {
if self
Expand Down
6 changes: 5 additions & 1 deletion crates/aptos-logger/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ pub static PROCESSED_STRUCT_LOG_COUNT: Lazy<IntCounter> = Lazy::new(|| {
.unwrap()
});

/// Count of error!() logs
/// Counts of logs
pub static ERROR_LOG_COUNT: Lazy<IntCounter> =
Lazy::new(|| register_int_counter!("aptos_error_log_count", "Count of error!() logs").unwrap());
pub static WARN_LOG_COUNT: Lazy<IntCounter> =
Lazy::new(|| register_int_counter!("aptos_warn_log_count", "Count of warn!() logs").unwrap());
pub static INFO_LOG_COUNT: Lazy<IntCounter> =
Lazy::new(|| register_int_counter!("aptos_info_log_count", "Count of info!() logs").unwrap());

/// Metric for when we fail to log during sending to the queue
pub static STRUCT_LOG_QUEUE_ERROR_COUNT: Lazy<IntCounter> = Lazy::new(|| {
Expand Down
2 changes: 1 addition & 1 deletion crates/aptos-logger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ pub use metadata::{Level, Metadata};
pub use security::SecurityEvent;

mod counters;
pub use counters::ERROR_LOG_COUNT;
pub use counters::{ERROR_LOG_COUNT, INFO_LOG_COUNT, WARN_LOG_COUNT};
4 changes: 0 additions & 4 deletions crates/aptos-logger/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ macro_rules! log {
concat!(file!(), ':', line!()),
);

if METADATA.level() == $crate::Level::Error {
$crate::ERROR_LOG_COUNT.inc();
}

if METADATA.enabled() {
$crate::Event::dispatch(
&METADATA,
Expand Down
Loading