Struct Builder

Source
pub struct Builder<S = ByName, E = ByMessage> { /* private fields */ }
Expand description

Builder for TimingSubscriber instances.

This type implements the builder pattern. It lets you easily configure and construct a new TimingSubscriber subscriber. See the individual methods for details. To start, use Builder::default:

use tracing_timing::{Builder, Histogram};
let builder = Builder::default();
let subscriber = builder.build(|| Histogram::new(3).unwrap());

See the various new_* methods on Histogram for how to construct an appropriate histogram in the first place. All samples recorded by the subscriber returned from Builder::build will be recorded into histograms as returned by the provided constructor. You can also construct the histograms based on the span and event group it will be tracking by using Builder::build_informed.

Implementations§

Source§

impl<S, E> Builder<S, E>

Source

pub fn spans<S2>(self, span_group: S2) -> Builder<S2, E>

Set the mechanism used to divide spans into groups.

See SpanGroup and the group module for details.

Source

pub fn events<E2>(self, event_group: E2) -> Builder<S, E2>

Set the mechanism used to divide events into per-span groups.

See EventGroup and the group module for details.

Source

pub fn time(self, time: Clock) -> Builder<S, E>

Set the time source to use for time measurements.

Source

pub fn no_span_recursion(self) -> Self

By default, a TimingSubscriber will record the time since the last event in any child span:

| span foo
| - event a
| | span bar
| | - event b
| - event c

What time is recorded for event c? The default is t_c - t_b. With no_span_recursion, event c will have t_c - t_a. event b will record the time since the start of span bar.

Source

pub fn span_close_events(self) -> Self

By default, a TimingSubscriber or TimingLayer won’t record a span closure as an event.

| span foo
| - event a
| | span bar
| | - (bar closed)
| - event c

Without span close events, event c will record t_c - t_a. With span_close_events, event c will record t_c - t_bar_close.

Source

pub fn build_informed<F>(self, new_histogram: F) -> TimingSubscriber<S, E>
where S: SpanGroup, E: EventGroup, S::Id: Hash + Eq, E::Id: Hash + Eq, F: FnMut(&S::Id, &E::Id) -> Histogram<u64> + Send + Sync + 'static,

Construct a TimingSubscriber that uses the given function to construct new histograms.

This is equivalent to [build], except that the passed function is also told which span/event group the histogram is for.

Note that you may run into weird lifetime errors from the compiler when using this method with a closure. This is a known compiler issue. You can work around it by adding a slight type hint to the arguments passed to the closure as follows (note the : &_):

use tracing_timing::{Builder, Histogram};
let builder = Builder::default();
let subscriber = builder.build_informed(|s: &_, e: &_| Histogram::new(3).unwrap());
Source

pub fn build<F>(self, new_histogram: F) -> TimingSubscriber<S, E>
where S: SpanGroup, E: EventGroup, S::Id: Hash + Eq, E::Id: Hash + Eq, F: FnMut() -> Histogram<u64> + Send + Sync + 'static,

Construct a TimingSubscriber that uses the given function to construct new histograms.

Source

pub fn layer_informed<F>(self, new_histogram: F) -> TimingLayer<S, E>
where S: SpanGroup, E: EventGroup, S::Id: Hash + Eq, E::Id: Hash + Eq, F: FnMut(&S::Id, &E::Id) -> Histogram<u64> + Send + Sync + 'static,

Construct a TimingLayer that uses the given function to construct new histograms.

This is equivalent to [layer], except that the passed function is also told which span/event group the histogram is for.

Note that you may run into weird lifetime errors from the compiler when using this method with a closure. This is a known compiler issue. You can work around it by adding a slight type hint to the arguments passed to the closure as follows (note the : &_):

use tracing_timing::{Builder, Histogram};
let builder = Builder::default();
let layer = builder.layer_informed(|s: &_, e: &_| Histogram::new(3).unwrap());
Source

pub fn layer<F>(self, new_histogram: F) -> TimingLayer<S, E>
where S: SpanGroup, E: EventGroup, S::Id: Hash + Eq, E::Id: Hash + Eq, F: FnMut() -> Histogram<u64> + Send + Sync + 'static,

Construct a TimingSubscriber that uses the given function to construct new histograms.

Trait Implementations§

Source§

impl Default for Builder<ByName, ByMessage>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S, E> Freeze for Builder<S, E>
where S: Freeze, E: Freeze,

§

impl<S, E> RefUnwindSafe for Builder<S, E>

§

impl<S, E> Send for Builder<S, E>
where S: Send, E: Send,

§

impl<S, E> Sync for Builder<S, E>
where S: Sync, E: Sync,

§

impl<S, E> Unpin for Builder<S, E>
where S: Unpin, E: Unpin,

§

impl<S, E> UnwindSafe for Builder<S, E>
where S: UnwindSafe, E: UnwindSafe,

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.