metrics_prometheus/
lib.rs

1// These links overwrite the ones in `README.md`
2// to become proper intra-doc links in Rust docs.
3//! [`.freeze()`]: FreezableRecorder::freeze()
4//! [`Arc`]: std::sync::Arc
5//! [`arc-swap`]: arc_swap
6//! [`AtomicBool`]: std::sync::atomic::AtomicBool
7//! [`Describable`]: metric::Describable
8//! [`failure::strategy`]: failure::strategy
9//! [`failure::Strategy`]: failure::Strategy
10//! [`FreezableRecorder`]: FreezableRecorder
11//! [`FrozenRecorder`]: FrozenRecorder
12//! [`HashMap`]: std::collections::HashMap
13//! [`metrics`]: metrics
14//! [`metrics::Counter`]: metrics::Counter
15//! [`metrics::Counter::noop()`]: metrics::Counter::noop()
16//! [`metrics::Gauge`]: metrics::Gauge
17//! [`metrics::Histogram`]: metrics::Histogram
18//! [`metrics::Recorder`]: metrics::Recorder
19//! [`metrics::Registry`]: metrics_util::registry::Registry
20//! [`metrics::Unit`]: metrics::Unit
21//! [`PanicInDebugNoOpInRelease`]: failure::strategy::PanicInDebugNoOpInRelease
22//! [`prometheus`]: prometheus
23//! [`prometheus::Error`]: prometheus::Error
24//! [`prometheus::Gauge`]: prometheus::Gauge
25//! [`prometheus::GaugeVec`]: prometheus::GaugeVec
26//! [`prometheus::Histogram`]: prometheus::Histogram
27//! [`prometheus::HistogramVec`]: prometheus::HistogramVec
28//! [`prometheus::IntCounter`]: prometheus::IntCounter
29//! [`prometheus::IntCounterVec`]: prometheus::IntCounterVec
30//! [`prometheus::MetricVec`]: prometheus::core::MetricVec
31//! [`prometheus::Registry`]: prometheus::Registry
32//! [`read`-lock]: std::sync::RwLock::read()
33//! [`Recorder`]: Recorder
34#![cfg_attr(any(doc, test), doc = include_str!("../README.md"))]
35#![cfg_attr(not(any(doc, test)), doc = env!("CARGO_PKG_NAME"))]
36#![doc(
37    html_logo_url = "https://raw.githubusercontent.com/instrumentisto\
38                     /metrics-prometheus-rs\
39                     /80bcffc2096f9ff213ec84833a9d8dd81a115cd5/logo.png",
40    html_favicon_url = "https://raw.githubusercontent.com/instrumentisto\
41                        /metrics-prometheus-rs\
42                        /80bcffc2096f9ff213ec84833a9d8dd81a115cd5/logo.png"
43)]
44#![deny(nonstandard_style, rustdoc::all, trivial_casts, trivial_numeric_casts)]
45#![forbid(non_ascii_idents, unsafe_code)]
46#![warn(
47    clippy::absolute_paths,
48    clippy::allow_attributes,
49    clippy::allow_attributes_without_reason,
50    clippy::as_conversions,
51    clippy::as_pointer_underscore,
52    clippy::as_ptr_cast_mut,
53    clippy::assertions_on_result_states,
54    clippy::branches_sharing_code,
55    clippy::cfg_not_test,
56    clippy::clear_with_drain,
57    clippy::clone_on_ref_ptr,
58    clippy::collection_is_never_read,
59    clippy::create_dir,
60    clippy::dbg_macro,
61    clippy::debug_assert_with_mut_call,
62    clippy::decimal_literal_representation,
63    clippy::default_union_representation,
64    clippy::derive_partial_eq_without_eq,
65    clippy::doc_include_without_cfg,
66    clippy::empty_drop,
67    clippy::empty_structs_with_brackets,
68    clippy::equatable_if_let,
69    clippy::empty_enum_variants_with_brackets,
70    clippy::exit,
71    clippy::expect_used,
72    clippy::fallible_impl_from,
73    clippy::filetype_is_file,
74    clippy::float_cmp_const,
75    clippy::fn_to_numeric_cast_any,
76    clippy::get_unwrap,
77    clippy::if_then_some_else_none,
78    clippy::imprecise_flops,
79    clippy::infinite_loop,
80    clippy::iter_on_empty_collections,
81    clippy::iter_on_single_items,
82    clippy::iter_over_hash_type,
83    clippy::iter_with_drain,
84    clippy::large_include_file,
85    clippy::large_stack_frames,
86    clippy::let_underscore_untyped,
87    clippy::literal_string_with_formatting_args,
88    clippy::lossy_float_literal,
89    clippy::map_err_ignore,
90    clippy::map_with_unused_argument_over_ranges,
91    clippy::mem_forget,
92    clippy::missing_assert_message,
93    clippy::missing_asserts_for_indexing,
94    clippy::missing_const_for_fn,
95    clippy::missing_docs_in_private_items,
96    clippy::module_name_repetitions,
97    clippy::multiple_inherent_impl,
98    clippy::multiple_unsafe_ops_per_block,
99    clippy::mutex_atomic,
100    clippy::mutex_integer,
101    clippy::needless_collect,
102    clippy::needless_pass_by_ref_mut,
103    clippy::needless_raw_strings,
104    clippy::non_zero_suggestions,
105    clippy::nonstandard_macro_braces,
106    clippy::option_if_let_else,
107    clippy::or_fun_call,
108    clippy::panic_in_result_fn,
109    clippy::partial_pub_fields,
110    clippy::pathbuf_init_then_push,
111    clippy::pedantic,
112    clippy::precedence_bits,
113    clippy::print_stderr,
114    clippy::print_stdout,
115    clippy::pub_without_shorthand,
116    clippy::rc_buffer,
117    clippy::rc_mutex,
118    clippy::read_zero_byte_vec,
119    clippy::redundant_clone,
120    clippy::redundant_type_annotations,
121    clippy::renamed_function_params,
122    clippy::ref_patterns,
123    clippy::rest_pat_in_fully_bound_structs,
124    clippy::return_and_then,
125    clippy::same_name_method,
126    clippy::semicolon_inside_block,
127    clippy::set_contains_or_insert,
128    clippy::shadow_unrelated,
129    clippy::significant_drop_in_scrutinee,
130    clippy::significant_drop_tightening,
131    clippy::single_option_map,
132    clippy::str_to_string,
133    clippy::string_add,
134    clippy::string_lit_as_bytes,
135    clippy::string_lit_chars_any,
136    clippy::string_slice,
137    clippy::string_to_string,
138    clippy::suboptimal_flops,
139    clippy::suspicious_operation_groupings,
140    clippy::suspicious_xor_used_as_pow,
141    clippy::tests_outside_test_module,
142    clippy::todo,
143    clippy::too_long_first_doc_paragraph,
144    clippy::trailing_empty_array,
145    clippy::transmute_undefined_repr,
146    clippy::trivial_regex,
147    clippy::try_err,
148    clippy::undocumented_unsafe_blocks,
149    clippy::unimplemented,
150    clippy::uninhabited_references,
151    clippy::unnecessary_safety_comment,
152    clippy::unnecessary_safety_doc,
153    clippy::unnecessary_self_imports,
154    clippy::unnecessary_struct_initialization,
155    clippy::unused_peekable,
156    clippy::unused_result_ok,
157    clippy::unused_trait_names,
158    clippy::unwrap_in_result,
159    clippy::unwrap_used,
160    clippy::use_debug,
161    clippy::use_self,
162    clippy::useless_let_if_seq,
163    clippy::verbose_file_reads,
164    clippy::while_float,
165    clippy::wildcard_enum_match_arm,
166    ambiguous_negative_literals,
167    closure_returning_async_block,
168    future_incompatible,
169    impl_trait_redundant_captures,
170    let_underscore_drop,
171    macro_use_extern_crate,
172    meta_variable_misuse,
173    missing_copy_implementations,
174    missing_debug_implementations,
175    missing_docs,
176    redundant_lifetimes,
177    rust_2018_idioms,
178    single_use_lifetimes,
179    unit_bindings,
180    unnameable_types,
181    unreachable_pub,
182    unstable_features,
183    unused,
184    variant_size_differences
185)]
186
187pub mod failure;
188pub mod metric;
189pub mod recorder;
190pub mod storage;
191
192#[doc(inline)]
193pub use self::{
194    metric::Metric,
195    recorder::{
196        Freezable as FreezableRecorder, Frozen as FrozenRecorder, Recorder,
197    },
198};
199
200/// Tries to install a default [`Recorder`] (backed by the
201/// [`prometheus::default_registry()`]) with the
202/// [`metrics::set_global_recorder()`].
203///
204/// # Errors
205///
206/// If the [`Recorder`] fails to be installed with the
207/// [`metrics::set_global_recorder()`].
208pub fn try_install() -> Result<Recorder, metrics::SetRecorderError<Recorder>> {
209    Recorder::builder().try_build_and_install()
210}
211
212/// Tries to install a default [`FreezableRecorder`] (backed by the
213/// [`prometheus::default_registry()`]) with the
214/// [`metrics::set_global_recorder()`].
215///
216/// # Errors
217///
218/// If the [`FreezableRecorder`] fails to be installed with the
219/// [`metrics::set_global_recorder()`].
220pub fn try_install_freezable()
221-> Result<FreezableRecorder, metrics::SetRecorderError<FreezableRecorder>> {
222    Recorder::builder().try_build_freezable_and_install()
223}
224
225/// Installs a default [`Recorder`] (backed by the
226/// [`prometheus::default_registry()`]) with the
227/// [`metrics::set_global_recorder()`].
228///
229/// # Panics
230///
231/// If the [`Recorder`] fails to be installed with the
232/// [`metrics::set_global_recorder()`].
233#[expect( // intentional
234    clippy::must_use_candidate,
235    reason = "`#[must_use]` is omitted here, to avoid forcing library users \
236              using the returned `Recorder` directly"
237)]
238pub fn install() -> Recorder {
239    Recorder::builder().build_and_install()
240}
241
242/// Installs a default [`FreezableRecorder`] (backed by the
243/// [`prometheus::default_registry()`]) with the
244/// [`metrics::set_global_recorder()`].
245///
246/// # Panics
247///
248/// If the [`FreezableRecorder`] fails to be installed with the
249/// [`metrics::set_global_recorder()`].
250#[expect( // intentional
251    clippy::must_use_candidate,
252    reason = "`#[must_use]` is omitted here, to avoid forcing library users \
253              using the returned `Recorder` directly"
254)]
255pub fn install_freezable() -> FreezableRecorder {
256    Recorder::builder().build_freezable_and_install()
257}