Skip to content

Commit 8cc9dab

Browse files
committed
Document better how metrics are supposed to work
Signed-off-by: Ryan Levick <[email protected]>
1 parent 85d66c1 commit 8cc9dab

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

crates/telemetry/src/metrics.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub(crate) fn otel_metrics_layer<S: Subscriber + for<'span> LookupSpan<'span>>(
6161
///
6262
/// The increment may only be an i64 or f64. You must not mix types for the same metric.
6363
///
64+
/// Takes advantage of counter support in [tracing-opentelemetry](https://docs.rs/tracing-opentelemetry/0.32.0/tracing_opentelemetry/struct.MetricsLayer.html).
65+
///
6466
/// ```no_run
6567
/// # use spin_telemetry::metrics::counter;
6668
/// counter!(spin.metric_name = 1, metric_attribute = "value");
@@ -76,6 +78,8 @@ macro_rules! counter {
7678
///
7779
/// The increment may only be an i64 or f64. You must not mix types for the same metric.
7880
///
81+
/// Takes advantage of histogram support in [tracing-opentelemetry](https://docs.rs/tracing-opentelemetry/0.32.0/tracing_opentelemetry/struct.MetricsLayer.html).
82+
///
7983
/// ```no_run
8084
/// # use spin_telemetry::metrics::histogram;
8185
/// histogram!(spin.metric_name = 1.5, metric_attribute = "value");
@@ -91,6 +95,8 @@ macro_rules! histogram {
9195
///
9296
/// The increment may only be a positive i64 or f64. You must not mix types for the same metric.
9397
///
98+
/// Takes advantage of monotonic counter support in [tracing-opentelemetry](https://docs.rs/tracing-opentelemetry/0.32.0/tracing_opentelemetry/struct.MetricsLayer.html).
99+
///
94100
/// ```no_run
95101
/// # use spin_telemetry::metrics::monotonic_counter;
96102
/// monotonic_counter!(spin.metric_name = 1, metric_attribute = "value");
@@ -101,6 +107,24 @@ macro_rules! monotonic_counter {
101107
}
102108
}
103109

110+
#[macro_export]
111+
/// Records an increment to the named monotonic counter with the given attributes.
112+
///
113+
/// The increment may only be a positive i64 or f64. You must not mix types for the same metric.
114+
///
115+
/// Takes advantage of gauge support in [tracing-opentelemetry](https://docs.rs/tracing-opentelemetry/0.32.0/tracing_opentelemetry/struct.MetricsLayer.html).
116+
///
117+
/// ```no_run
118+
/// # use spin_telemetry::metrics::gauge;
119+
/// gauge!(spin.metric_name = 1, metric_attribute = "value");
120+
/// ```
121+
macro_rules! gauge {
122+
($metric:ident $(. $suffixes:ident)* = $metric_value:expr $(, $attrs:ident=$values:expr)*) => {
123+
tracing::trace!(gauge.$metric $(. $suffixes)* = $metric_value $(, $attrs=$values)*);
124+
}
125+
}
126+
104127
pub use counter;
128+
pub use gauge;
105129
pub use histogram;
106130
pub use monotonic_counter;

0 commit comments

Comments
 (0)