Skip to content

Commit 473a500

Browse files
authored
docs: add metrics layer attributes description (#49)
## Motivation * fix broken link in doc * update histogram metrics field prefix (`value` -> `histogram`) * add metrics layer attributes description #43
1 parent 42a3c73 commit 473a500

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//! * `otel.status_message`: Set the span status message.
2828
//!
2929
//! [span kinds]: opentelemetry::trace::SpanKind
30-
//! [span status codes]: opentelemetry::trace::StatusCode
30+
//! [span status codes]: opentelemetry::trace::Status
3131
//!
3232
//! ### Semantic Conventions
3333
//!
@@ -82,11 +82,13 @@
8282
//!
8383
//! ## Feature Flags
8484
//!
85-
//! - `metrics`: Enables the [`MetricsSubscriber`] type, a [subscriber] that
85+
//! - `metrics`: Enables the [`MetricsLayer`] type, a [layer] that
8686
//! exports OpenTelemetry metrics from specifically-named events. This enables
8787
//! the `metrics` feature flag on the `opentelemetry` crate. *Enabled by
8888
//! default*.
8989
//!
90+
//! [layer]: tracing_subscriber::layer
91+
//!
9092
//! ## Supported Rust Versions
9193
//!
9294
//! Tracing is built against the latest stable release. The minimum supported

src/metrics.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ impl<'a> Visit for MetricVisitor<'a> {
247247
/// - `monotonic_counter.` (non-negative numbers): Used when the counter should
248248
/// only ever increase
249249
/// - `counter.`: Used when the counter can go up or down
250-
/// - `value.`: Used for discrete data points (i.e., summing them does not make
251-
/// semantic sense)
250+
/// - `histogram.`: Used to report arbitrary values that are likely to be statistically meaningful
252251
///
253252
/// Examples:
254253
/// ```
@@ -260,9 +259,9 @@ impl<'a> Visit for MetricVisitor<'a> {
260259
/// info!(counter.baz = -1);
261260
/// info!(counter.xyz = 1.1);
262261
///
263-
/// info!(value.qux = 1);
264-
/// info!(value.abc = -1);
265-
/// info!(value.def = 1.1);
262+
/// info!(histogram.qux = 1);
263+
/// info!(histogram.abc = -1);
264+
/// info!(histogram.def = 1.1);
266265
/// ```
267266
///
268267
/// # Mixing data types
@@ -307,6 +306,19 @@ impl<'a> Visit for MetricVisitor<'a> {
307306
/// info!(counter.baz = (i64::MAX as u64) + 1)
308307
/// ```
309308
///
309+
/// # Attributes
310+
///
311+
/// When `MetricsLayer` outputs metrics, it converts key-value pairs into [Attributes] and associates them with metrics.
312+
///
313+
/// [Attributes]: https://opentelemetry.io/docs/specs/otel/common/#attribute
314+
///
315+
/// For example:
316+
/// ```
317+
/// # use tracing::info;
318+
/// // adds attributes bar="baz" and qux=2 to the `foo` counter.
319+
/// info!(monotonic_counter.foo = 1, bar = "baz", qux = 2);
320+
/// ```
321+
///
310322
/// # Implementation Details
311323
///
312324
/// `MetricsLayer` holds a set of maps, with each map corresponding to a

0 commit comments

Comments
 (0)