Skip to main content

Histogram

Struct Histogram 

Source
pub struct Histogram<N: HistogramValue = f64> { /* private fields */ }
Expand description

A histogram for tracking value distributions such as request latencies or payload sizes. See the module documentation.

Declare as a module-level static. Service-scoped by default unless marked shared or global; see scope.

Implementations§

Source§

impl<N: HistogramValue> Histogram<N>

Source

pub const fn new(name: &'static str) -> Self

Declares a histogram with the given name. Names must start with a letter and contain only letters, digits, _, ., -, and /. name must be a string literal so Encore can parse it statically.

Source

pub const fn shared(self) -> Self

Declares the histogram with shared app-wide scope rather than service scope. Any service may record to it, and each service that does is tracked as a user. See scope.

Source

pub const fn global(self) -> Self

Declares the histogram with global app-wide scope so any code (including shared libraries outside any service) may record to it without per-service tracking. See scope.

Source

pub const fn unit(self, unit: &'static str) -> Self

Sets the exported unit of the histogram (using UCUM notation such as "s", "By", or "{request}").

Source

pub const fn description(self, description: &'static str) -> Self

Sets the description of the histogram when no doc comment is present.

Source

pub const fn tag(self, _key: &'static str, _value: &'static str) -> Self

Attaches a key/value tag to the histogram (for example, .tag("data", "pii")) for policy and governance tooling. Call once per tag with unique keys. Both key and value must be string literals so Encore can parse them statically. Keys must start with a letter, contain only lowercase letters, digits, _, and -, and must not start with encore (reserved for Encore’s own tags). Values use the same character set or may be empty. Each key and value is at most 63 characters, and a histogram may have at most 32 tags.

Tags classify the metric declaration itself and are distinct from recorded metric labels.

Source

pub const fn buckets(self, bounds: &'static [f64]) -> Self

Sets explicit increasing upper bucket boundaries.

Each recorded value is counted in the first bucket whose upper bound is greater than or equal to the value (or in an overflow bucket if larger than all bounds). If omitted, OpenTelemetry’s default bucket boundaries are used.

Source

pub fn reference(&self) -> &Self

Returns a reference to this histogram that can be passed to helper functions taking &Histogram.

Calling reference() explicitly signals to Encore’s static analyzer that the calling service records to this metric.

Source

pub fn record(&self, value: N)

Records a single observation value.

Source§

impl<N: HistogramValue> Histogram<N>

Source

pub const fn named(name: &'static str) -> Self

Binds a shared or global histogram named name that was declared elsewhere (for example, in another service or language). It inherits the declaration’s kind, scope, unit, description, and buckets, and is exported as name without a service prefix. name must be a string literal so Encore can parse it statically.

Auto Trait Implementations§

§

impl<N = f64> !Freeze for Histogram<N>

§

impl<N = f64> !RefUnwindSafe for Histogram<N>

§

impl<N = f64> !UnwindSafe for Histogram<N>

§

impl<N> Forget for Histogram<N>

§

impl<N> Move for Histogram<N>

§

impl<N> Send for Histogram<N>
where &'static str: Send, &'static [f64]: Send, RawVecInner: Send, BoxRaw<str>: Send, Arc<str>: Send, OnceLock<Histogram<N>>: Send,

§

impl<N> Sync for Histogram<N>
where RawVecInner: Sync, BoxRaw<str>: Sync, Arc<str>: Sync, OnceLock<Histogram<N>>: Sync,

§

impl<N> Unpin for Histogram<N>
where &'static str: Unpin, &'static [f64]: Unpin, *const u8 is !null: Unpin, Box<str>: Unpin, Arc<str>: Unpin, Align4<u32>: Unpin, Arc<dyn SyncInstrument<N> + Sync + Send>: Unpin,

§

impl<N> UnsafeUnpin for Histogram<N>
where &'static str: UnsafeUnpin, &'static [f64]: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<KeyValue>: UnsafeUnpin, Align4<u32>: UnsafeUnpin, *const ArcInner<dyn SyncInstrument<N> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn SyncInstrument<N> + Sync + Send>>: UnsafeUnpin, PhantomData<Histogram<N>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U