pub struct SessionTelemetry { /* private fields */ }Expand description
Zero-overhead telemetry collector for speech-to-speech sessions.
Designed for the three-lane processor model:
- Fast lane (sync, <1ms): No telemetry calls — pure audio/text forwarding.
- Telemetry lane (async, debounced): Calls
record_*methods on every event. These use only atomic operations — no allocations, no locks, no syscalls. - Control lane (async): Calls
snapshot()at turn boundaries to get aggregated stats as a JSON value ready to send to the browser.
Implementations§
Source§impl SessionTelemetry
impl SessionTelemetry
Sourcepub fn record_audio_out(&self, byte_len: usize) -> Option<Duration>
pub fn record_audio_out(&self, byte_len: usize) -> Option<Duration>
Record an outgoing audio chunk. Called from the telemetry lane.
Returns the response latency when this chunk is the model’s first output after the user’s end of speech (or text send) — once per turn, via a CAS so only the first chunk wins.
Sourcepub fn record_vad_end(&self)
pub fn record_vad_end(&self)
Record VAD end (user stopped speaking).
Sourcepub fn record_text_send(&self)
pub fn record_text_send(&self)
Record that user sent a text message (for text-input latency tracking).
Sourcepub fn record_text_out(&self) -> Option<Duration>
pub fn record_text_out(&self) -> Option<Duration>
Record first model text output (TextDelta). Tracks text-input latency.
Returns the response latency when this delta is the model’s first output after a text send.
Sourcepub fn record_interruption(&self)
pub fn record_interruption(&self)
Record an interruption (barge-in).
Sourcepub fn record_turn_complete(&self)
pub fn record_turn_complete(&self)
Record turn completion for duration tracking.
Sourcepub fn record_usage(
&self,
total: Option<u32>,
prompt: Option<u32>,
response: Option<u32>,
cached: Option<u32>,
thoughts: Option<u32>,
)
pub fn record_usage( &self, total: Option<u32>, prompt: Option<u32>, response: Option<u32>, cached: Option<u32>, thoughts: Option<u32>, )
Record token usage from a UsageMetadata event.
Sourcepub fn mark_turn_start(&self)
pub fn mark_turn_start(&self)
Mark the beginning of a new turn (e.g., when model starts responding).
Sourcepub fn latency(&self) -> LatencyStats
pub fn latency(&self) -> LatencyStats
Per-turn response latency: end of user speech (or text send) to the model’s first output, as a distribution over the session so far.
Cheap enough to call once per turn (it sorts at most
LATENCY_RECENT_WINDOW samples); not for the audio hot path.
Sourcepub fn snapshot(&self) -> Value
pub fn snapshot(&self) -> Value
Snapshot all metrics as a JSON value.
The flat *_response_latency_ms keys are kept for existing dashboards;
response_latency carries the full LatencyStats (percentiles and
histogram included).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SessionTelemetry
impl RefUnwindSafe for SessionTelemetry
impl Send for SessionTelemetry
impl Sync for SessionTelemetry
impl Unpin for SessionTelemetry
impl UnwindSafe for SessionTelemetry
Blanket Implementations§
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> 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> 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 more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].