Skip to content

Commit 5877c82

Browse files
Malletscursoragent
andcommitted
Update labels docs to reflect both static and dynamic usage
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 1ff8cdd commit 5877c82

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

quickwit/quickwit-metrics/src/labels.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414

1515
//! Reusable label templates for metric extension.
1616
//!
17-
//! [`LabelNames<N>`] holds label *names* at compile time; pair them with
18-
//! values via the [`label_values!`] macro to get a [`Labels<N>`] that
19-
//! the `labels:` macro arm can consume. This avoids repeating the same
20-
//! label names at every call site and lets a single `Labels<N>` be
21-
//! shared across counter, gauge, and histogram extensions.
17+
//! Labels can be created in two ways:
18+
//!
19+
//! - **[`labels!`]** — inline key-value pairs. Keys are always static
20+
//! literals; values can be static literals (const-compatible, zero
21+
//! allocation) or dynamic expressions (`Into<SharedString>`).
22+
//!
23+
//! - **[`label_names!`] + [`label_values!`]** — separate the label *names*
24+
//! (a const [`LabelNames<N>`]) from the *values*. This avoids repeating
25+
//! the same label names at every call site and lets a single
26+
//! [`Labels<N>`] be shared across counter, gauge, and histogram
27+
//! extensions.
2228
2329
use metrics::SharedString;
2430

@@ -69,15 +75,21 @@ macro_rules! label_values {
6975
};
7076
}
7177

72-
/// Creates a const `Labels` from all-static key-value pairs.
78+
/// Creates a [`Labels<N>`] from key-value pairs.
7379
///
74-
/// Every key and value must be `&'static str` literals. The result is a
75-
/// `const` value — zero allocation, zero runtime cost.
80+
/// Keys are always `&'static str` literals. Values can be either
81+
/// string literals (const-compatible, zero allocation) or arbitrary
82+
/// expressions convertible to `SharedString` (dynamic, allocated at
83+
/// runtime).
7684
///
77-
/// # Example
85+
/// # Examples
7886
///
7987
/// ```rust,ignore
88+
/// // All-static — const-compatible, zero allocation:
8089
/// const LABELS: Labels<2> = labels!("env" => "prod", "region" => "us-east-1");
90+
///
91+
/// // Dynamic values — any expression that implements Into<SharedString>:
92+
/// let labels = labels!("env" => "prod", "node_id" => node_id.to_string());
8193
/// ```
8294
#[macro_export]
8395
macro_rules! labels {

0 commit comments

Comments
 (0)