Skip to content

Commit 43d709c

Browse files
authored
add metrics counters for warn! and info! logs (#13552)
* add metrics counters for warn! and info! logs * move info/warn/err counting out of macro into handler thread
1 parent 8f3e991 commit 43d709c

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

crates/aptos-logger/src/aptos_logger.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use crate::{
1313
sample,
1414
sample::SampleRate,
1515
telemetry_log_writer::{TelemetryLog, TelemetryLogWriter},
16-
Event, Filter, Key, Level, LevelFilter, Metadata,
16+
Event, Filter, Key, Level, LevelFilter, Metadata, ERROR_LOG_COUNT, INFO_LOG_COUNT,
17+
WARN_LOG_COUNT,
1718
};
1819
use aptos_infallible::RwLock;
1920
use backtrace::Backtrace;
@@ -604,6 +605,12 @@ impl LoggerService {
604605
match event {
605606
LoggerServiceEvent::LogEntry(entry) => {
606607
PROCESSED_STRUCT_LOG_COUNT.inc();
608+
match entry.metadata.level() {
609+
Level::Error => ERROR_LOG_COUNT.inc(),
610+
Level::Warn => WARN_LOG_COUNT.inc(),
611+
Level::Info => INFO_LOG_COUNT.inc(),
612+
_ => {},
613+
}
607614

608615
if let Some(printer) = &mut self.printer {
609616
if self

crates/aptos-logger/src/counters.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ pub static PROCESSED_STRUCT_LOG_COUNT: Lazy<IntCounter> = Lazy::new(|| {
2020
.unwrap()
2121
});
2222

23-
/// Count of error!() logs
23+
/// Counts of logs
2424
pub static ERROR_LOG_COUNT: Lazy<IntCounter> =
2525
Lazy::new(|| register_int_counter!("aptos_error_log_count", "Count of error!() logs").unwrap());
26+
pub static WARN_LOG_COUNT: Lazy<IntCounter> =
27+
Lazy::new(|| register_int_counter!("aptos_warn_log_count", "Count of warn!() logs").unwrap());
28+
pub static INFO_LOG_COUNT: Lazy<IntCounter> =
29+
Lazy::new(|| register_int_counter!("aptos_info_log_count", "Count of info!() logs").unwrap());
2630

2731
/// Metric for when we fail to log during sending to the queue
2832
pub static STRUCT_LOG_QUEUE_ERROR_COUNT: Lazy<IntCounter> = Lazy::new(|| {

crates/aptos-logger/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,4 @@ pub use metadata::{Level, Metadata};
169169
pub use security::SecurityEvent;
170170

171171
mod counters;
172-
pub use counters::ERROR_LOG_COUNT;
172+
pub use counters::{ERROR_LOG_COUNT, INFO_LOG_COUNT, WARN_LOG_COUNT};

crates/aptos-logger/src/macros.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ macro_rules! log {
6060
concat!(file!(), ':', line!()),
6161
);
6262

63-
if METADATA.level() == $crate::Level::Error {
64-
$crate::ERROR_LOG_COUNT.inc();
65-
}
66-
6763
if METADATA.enabled() {
6864
$crate::Event::dispatch(
6965
&METADATA,

0 commit comments

Comments
 (0)