EventBuilder

Struct EventBuilder 

Source
pub struct EventBuilder<P = Pull>
where P: PublishModel,
{ /* private fields */ }
Expand description

Creates instances of Event.

Required parameters:

  • name

Use Event::builder() to create a new instance of this builder.

See crate-level documentation for more details on how to create and use events.

Implementations§

Source§

impl<P> EventBuilder<P>
where P: PublishModel,

Source

pub fn name(self, name: impl Into<EventName>) -> Self

Sets the name of the event. This is a required property.

Recommended format: big_medium_small_units For example: net_http_connect_time_ns

§Example
use nm::Event;

thread_local! {
    static MY_EVENT: Event = Event::builder()
        .name("http_requests_duration_ms")
        .build();
}
Source

pub fn histogram(self, buckets: &'static [Magnitude]) -> Self

Sets the upper bounds (inclusive) of histogram buckets to use when creating a histogram of event magnitudes.

The default is to not create a histogram.

§Example
use nm::{Event, Magnitude};

const RESPONSE_TIME_BUCKETS_MS: &[Magnitude] = &[1, 10, 50, 100, 500, 1000];

thread_local! {
    static HTTP_RESPONSE_TIME_MS: Event = Event::builder()
        .name("http_response_time_ms")
        .histogram(RESPONSE_TIME_BUCKETS_MS)
        .build();
}
§Panics

Panics if bucket magnitudes are not in ascending order.

Panics if one of the values is Magnitude::MAX. You do not need to specify this bucket yourself - it is automatically synthesized for all histograms to catch values that exceed the user-defined buckets.

Source§

impl EventBuilder<Pull>

Source

pub fn pusher(self, pusher: &MetricsPusher) -> EventBuilder<Push>

Configures the event to be published using the push model, whereby a pusher is used to explicitly publish data for reporting purposes.

Any data from such an event will only reach reports after MetricsPusher::push() is called on the referenced pusher.

This can provide lower overhead than the pull model, which is the default, at the cost of delaying data updates until the pusher is invoked. Note that if nothing ever calls the pusher on a thread, the data from that thread will never be published.

§Example
use nm::{Event, MetricsPusher, Push};

let pusher = MetricsPusher::new();
let push_event: Event<Push> = Event::builder()
    .name("push_example")
    .pusher(&pusher)
    .build();
Source

pub fn pusher_local( self, pusher: &'static LocalKey<MetricsPusher>, ) -> EventBuilder<Push>

Configures the event to be published using the push model, whereby a pusher is used to explicitly publish data for reporting purposes.

Any data from such an event will only reach reports after MetricsPusher::push() is called on the referenced pusher.

This can provide lower overhead than the pull model, which is the default, at the cost of delaying data updates until the pusher is invoked. Note that if nothing ever calls the pusher on a thread, the data from that thread will never be published.

§Example
use nm::{Event, MetricsPusher, Push};

thread_local! {
    static PUSHER: MetricsPusher = MetricsPusher::new();

    static PUSH_EVENT: Event<Push> = Event::builder()
        .name("push_local_example")
        .pusher_local(&PUSHER)
        .build();
}
Source

pub fn build(self) -> Event<Pull>

Builds the event with the current configuration.

§Panics

Panics if a required parameter is not set.

Panics if an event with this name has already been registered on this thread. You can only create an event with each name once per thread.

Source§

impl EventBuilder<Push>

Source

pub fn build(self) -> Event<Push>

Builds the event with the current configuration.

§Panics

Panics if a required parameter is not set.

Panics if an event with this name has already been registered on this thread. You can only create an event with each name once per thread.

Trait Implementations§

Source§

impl<P> Debug for EventBuilder<P>
where P: PublishModel + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<P> Freeze for EventBuilder<P>

§

impl<P = Pull> !RefUnwindSafe for EventBuilder<P>

§

impl<P = Pull> !Send for EventBuilder<P>

§

impl<P = Pull> !Sync for EventBuilder<P>

§

impl<P> Unpin for EventBuilder<P>
where P: Unpin,

§

impl<P = Pull> !UnwindSafe for EventBuilder<P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.