pub struct TokenBurnMeter { /* private fields */ }Expand description
Token-burn instruments built from an OTel [Meter].
When constructed via TokenBurnMeter::global the process-global OTel
meter is used, which is a no-op meter unless an SDK meter provider has been
registered (e.g. by init_telemetry). Recording is therefore always safe:
it never blocks or panics, and silently does nothing when no exporter is
configured or the otel feature is off.
Implementations§
Source§impl TokenBurnMeter
impl TokenBurnMeter
Sourcepub fn global() -> TokenBurnMeter
pub fn global() -> TokenBurnMeter
Build from the process-global OTel meter (no-op when no provider set).
Sourcepub fn from_meter(meter: Meter) -> TokenBurnMeter
pub fn from_meter(meter: Meter) -> TokenBurnMeter
Build from an explicit meter — the test seam, used with a local SDK meter provider so recording can be asserted hermetically.
Sourcepub fn record_prompt(&self, model: &str, tenant: Option<u64>, count: u64)
pub fn record_prompt(&self, model: &str, tenant: Option<u64>, count: u64)
Record prompt tokens consumed by tokenizing a request.
Sourcepub fn record_generated(&self, model: &str, tenant: Option<u64>, count: u64)
pub fn record_generated(&self, model: &str, tenant: Option<u64>, count: u64)
Record generated tokens produced by a completed request.
Sourcepub fn record_request_total(&self, model: &str, tenant: Option<u64>, total: u64)
pub fn record_request_total(&self, model: &str, tenant: Option<u64>, total: u64)
Record the per-request token total (prompt + generated) on the histogram.
Sourcepub fn record_speculative(
&self,
model: &str,
tenant: Option<u64>,
accepted: u64,
rejected: u64,
)
pub fn record_speculative( &self, model: &str, tenant: Option<u64>, accepted: u64, rejected: u64, )
Record MTP self-speculative draft outcomes for a completed request.
Integer draft counts only — never token IDs or text (#1253). Each kind is skipped when zero so non-speculative requests add no points.
Auto Trait Implementations§
impl Freeze for TokenBurnMeter
impl !RefUnwindSafe for TokenBurnMeter
impl Send for TokenBurnMeter
impl Sync for TokenBurnMeter
impl Unpin for TokenBurnMeter
impl UnsafeUnpin for TokenBurnMeter
impl !UnwindSafe for TokenBurnMeter
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request