Skip to content

Commit f9ad729

Browse files
committed
feat: [#1445] add logs for metrics initialization
1 parent ad782eb commit f9ad729

5 files changed

Lines changed: 10 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/metrics/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ serde = { version = "1", features = ["derive"] }
2121
serde_json = "1.0.140"
2222
thiserror = "2"
2323
torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" }
24+
tracing = "0.1.41"
2425

2526
[dev-dependencies]
2627
approx = "0.5.1"

packages/metrics/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub mod sample;
88
pub mod sample_collection;
99
pub mod unit;
1010

11+
pub const METRICS_TARGET: &str = "METRICS";
12+
1113
#[cfg(test)]
1214
mod tests {
1315
/// It removes leading and trailing whitespace from each line, and empty lines.

packages/metrics/src/metric_collection.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use super::prometheus::PrometheusSerializable;
1212
use crate::metric::description::MetricDescription;
1313
use crate::sample_collection::SampleCollection;
1414
use crate::unit::Unit;
15+
use crate::METRICS_TARGET;
1516

1617
// code-review: serialize in a deterministic order? For example:
1718
// - First the counter metrics ordered by name.
@@ -56,7 +57,8 @@ impl MetricCollection {
5657

5758
// Counter-specific methods
5859

59-
pub fn describe_counter(&mut self, name: &MetricName, _opt_unit: Option<Unit>, _opt_description: Option<MetricDescription>) {
60+
pub fn describe_counter(&mut self, name: &MetricName, opt_unit: Option<Unit>, opt_description: Option<MetricDescription>) {
61+
tracing::info!(target: METRICS_TARGET, type = "counter", name = name.to_string(), unit = ?opt_unit, description = ?opt_description);
6062
self.counters.ensure_metric_exists(name);
6163
}
6264

@@ -97,7 +99,8 @@ impl MetricCollection {
9799

98100
// Gauge-specific methods
99101

100-
pub fn describe_gauge(&mut self, name: &MetricName, _opt_unit: Option<Unit>, _opt_description: Option<MetricDescription>) {
102+
pub fn describe_gauge(&mut self, name: &MetricName, opt_unit: Option<Unit>, opt_description: Option<MetricDescription>) {
103+
tracing::info!(target: METRICS_TARGET, type = "gauge", name = name.to_string(), unit = ?opt_unit, description = ?opt_description);
101104
self.gauges.ensure_metric_exists(name);
102105
}
103106

packages/metrics/src/unit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! The `Unit` enum is used to specify the unit of measurement for metrics.
55
//!
66
//! They were copied from the `metrics` crate, to allow future compatibility.
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
78
pub enum Unit {
89
Count,
910
Percent,

0 commit comments

Comments
 (0)