diff --git a/CHANGELOG.md b/CHANGELOG.md index 6553f0c..0a0087b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,20 @@ All user visible changes to this project will be documented in this file. This p +## [0.3.1] · 2023-01-?? +[0.3.1]: /../../tree/v0.3.1 + +[Diff](/../../compare/v0.3.0...v0.3.1) + +### Added + +- `build()`, `build_freezable()` and `build_frozen()` methods to `recorder::Builder`, allowing to build the resulting `metrics::Recorder` without installing it as `metrics::recorder()`. ([#4]) + +[#3]: /../../pull/4 + + + + ## [0.3.0] · 2022-12-11 [0.3.0]: /../../tree/v0.3.0 diff --git a/src/recorder/mod.rs b/src/recorder/mod.rs index e265e2d..eb6323a 100644 --- a/src/recorder/mod.rs +++ b/src/recorder/mod.rs @@ -720,6 +720,107 @@ impl Builder { }) } + /// Builds a [`Recorder`] out of this [`Builder`] and returns it being + /// wrapped into all the provided [`metrics::Layer`]s. + /// + /// # Usage + /// + /// Use this method if you want to: + /// - either install the built [`Recorder`] as [`metrics::recorder()`] + /// manually; + /// - or to compose the built [`Recorder`] with some other + /// [`metrics::Recorder`]s (like being able to write into multiple + /// [`prometheus::Registry`]s via [`metrics::layer::Fanout`], for + /// example). + /// + /// Otherwise, consider using the [`build_and_install()`] method instead. + /// + /// [`build_and_install()`]: Builder::build_and_install + /// [`metrics::layer::Fanout`]: metrics_util::layers::Fanout + /// [`metrics::Layer`]: Layer + pub fn build(self) -> >>::Output + where + S: failure::Strategy, + L: Layer>, + { + let Self { storage, failure_strategy, layers } = self; + let rec = Recorder { + metrics: Arc::new(metrics_util::registry::Registry::new( + storage.clone(), + )), + storage, + failure_strategy, + }; + layers.layer(rec) + } + + /// Builds a [`FreezableRecorder`] out of this [`Builder`] and returns it + /// being wrapped into all the provided [`metrics::Layer`]s. + /// + /// # Usage + /// + /// Use this method if you want to: + /// - either install the built [`FreezableRecorder`] as + /// [`metrics::recorder()`] manually; + /// - or to compose the built [`FreezableRecorder`] with some other + /// [`metrics::Recorder`]s (like being able to write into multiple + /// [`prometheus::Registry`]s via [`metrics::layer::Fanout`], for + /// example). + /// + /// Otherwise, consider using the [`build_freezable_and_install()`] method + /// instead. + /// + /// [`build_freezable_and_install()`]: Builder::build_freezable_and_install + /// [`metrics::layer::Fanout`]: metrics_util::layers::Fanout + /// [`metrics::Layer`]: Layer + /// [`FreezableRecorder`]: Freezable + pub fn build_freezable(self) -> >>::Output + where + S: failure::Strategy, + L: Layer>, + { + let Self { storage, failure_strategy, layers } = self; + let rec = freezable::Recorder::wrap(Recorder { + metrics: Arc::new(metrics_util::registry::Registry::new( + storage.clone(), + )), + storage, + failure_strategy, + }); + layers.layer(rec) + } + + /// Builds a [`FrozenRecorder`] out of this [`Builder`] and returns it being + /// wrapped into all the provided [`metrics::Layer`]s. + /// + /// # Usage + /// + /// Use this method if you want to: + /// - either install the built [`FrozenRecorder`] as [`metrics::recorder()`] + /// manually; + /// - or to compose the built [`FrozenRecorder`] with some other + /// [`metrics::Recorder`]s (like being able to write into multiple + /// [`prometheus::Registry`]s via [`metrics::layer::Fanout`], for + /// example). + /// + /// Otherwise, consider using the [`build_frozen_and_install()`] method + /// instead. + /// + /// [`build_frozen_and_install()`]: Builder::build_frozen_and_install + /// [`metrics::layer::Fanout`]: metrics_util::layers::Fanout + /// [`metrics::Layer`]: Layer + /// [`FrozenRecorder`]: Frozen + pub fn build_frozen(self) -> >>::Output + where + S: failure::Strategy, + L: Layer>, + { + let Self { storage, failure_strategy, layers } = self; + let rec = + frozen::Recorder { storage: (&storage).into(), failure_strategy }; + layers.layer(rec) + } + /// Builds a [`Recorder`] out of this [`Builder`] and tries to install it as /// [`metrics::recorder()`]. ///