@@ -32,6 +32,36 @@ pub struct Exemplar<S, V> {
32
32
/// counter_with_exemplar.inc_by(1, Some(vec![("user_id".to_string(), "42".to_string())]));
33
33
/// let _value: (u64, _) = counter_with_exemplar.get();
34
34
/// ```
35
+ /// You can also use exemplars with families. Just wrap the exemplar in a Family.
36
+ /// ```
37
+ /// # use prometheus_client::metrics::exemplar::CounterWithExemplar;
38
+ /// # use prometheus_client::metrics::histogram::exponential_buckets;
39
+ /// # use prometheus_client::metrics::family::Family;
40
+ /// # use prometheus_client_derive_encode::Encode;
41
+ /// #[derive(Clone, Hash, PartialEq, Eq, Encode, Debug, Default)]
42
+ /// pub struct ResultLabel {
43
+ /// pub result: String,
44
+ /// }
45
+ ///
46
+ /// #[derive(Clone, Hash, PartialEq, Eq, Encode, Debug, Default)]
47
+ /// pub struct TraceLabel {
48
+ /// pub trace_id: String,
49
+ /// }
50
+ ///
51
+ /// let latency: Family<ResultLabel, CounterWithExemplar<TraceLabel>> =
52
+ /// Family::default();
53
+ ///
54
+ /// latency
55
+ /// .get_or_create(&ResultLabel {
56
+ /// result: "success".to_owned(),
57
+ /// })
58
+ /// .inc_by(
59
+ /// 1,
60
+ /// Some(TraceLabel {
61
+ /// trace_id: "3a2f90c9f80b894f".to_owned(),
62
+ /// }),
63
+ /// );
64
+ /// ```
35
65
#[ cfg( not( any( target_arch = "mips" , target_arch = "powerpc" ) ) ) ]
36
66
#[ derive( Debug ) ]
37
67
pub struct CounterWithExemplar < S , N = u64 , A = AtomicU64 > {
@@ -127,6 +157,38 @@ impl<S, N: Clone, A: counter::Atomic<N>> CounterWithExemplar<S, N, A> {
127
157
/// let histogram = HistogramWithExemplars::new(exponential_buckets(1.0, 2.0, 10));
128
158
/// histogram.observe(4.2, Some(vec![("user_id".to_string(), "42".to_string())]));
129
159
/// ```
160
+ /// You can also use exemplars with families. Just wrap the exemplar in a Family.
161
+ /// ```
162
+ /// # use prometheus_client::metrics::exemplar::HistogramWithExemplars;
163
+ /// # use prometheus_client::metrics::histogram::exponential_buckets;
164
+ /// # use prometheus_client::metrics::family::Family;
165
+ /// # use prometheus_client_derive_encode::Encode;
166
+ /// #[derive(Clone, Hash, PartialEq, Eq, Encode, Debug, Default)]
167
+ /// pub struct ResultLabel {
168
+ /// pub result: String,
169
+ /// }
170
+ ///
171
+ /// #[derive(Clone, Hash, PartialEq, Eq, Encode, Debug, Default)]
172
+ /// pub struct TraceLabel {
173
+ /// pub trace_id: String,
174
+ /// }
175
+ ///
176
+ /// let latency: Family<ResultLabel, HistogramWithExemplars<TraceLabel>> =
177
+ /// Family::new_with_constructor(|| {
178
+ /// HistogramWithExemplars::new(exponential_buckets(1.0, 2.0, 10))
179
+ /// });
180
+ ///
181
+ /// latency
182
+ /// .get_or_create(&ResultLabel {
183
+ /// result: "success".to_owned(),
184
+ /// })
185
+ /// .observe(
186
+ /// 0.001345422,
187
+ /// Some(TraceLabel {
188
+ /// trace_id: "3a2f90c9f80b894f".to_owned(),
189
+ /// }),
190
+ /// );
191
+ /// ```
130
192
#[ derive( Debug ) ]
131
193
pub struct HistogramWithExemplars < S > {
132
194
// TODO: Not ideal, as Histogram has a Mutex as well.
0 commit comments