pub struct ProviderRequestRecord {
pub provider: String,
pub model: String,
pub timestamp: DateTime<Utc>,
pub prompt_tokens: u64,
pub completion_tokens: u64,
pub input_tokens: u64,
pub output_tokens: u64,
pub latency_ms: u64,
pub ttft_ms: Option<u64>,
pub success: bool,
}Expand description
One LLM provider request. Push into super::ProviderMetrics via
super::ProviderMetrics::record.
Note: prompt_tokens / completion_tokens and input_tokens /
output_tokens carry the same numbers — the duplication exists because
different downstream consumers were written against different field names.
§Examples
use codetether_agent::telemetry::ProviderRequestRecord;
use chrono::Utc;
let r = ProviderRequestRecord {
provider: "anthropic".into(),
model: "claude-sonnet-4".into(),
timestamp: Utc::now(),
prompt_tokens: 1_000,
completion_tokens: 500,
input_tokens: 1_000,
output_tokens: 500,
latency_ms: 2_000,
ttft_ms: Some(300),
success: true,
};
assert!((r.tokens_per_second() - 250.0).abs() < 1e-6);Fields§
§provider: StringProvider name (e.g. "anthropic", "openai").
model: StringModel id (e.g. "claude-sonnet-4").
timestamp: DateTime<Utc>When the request started (or completed — callers are consistent).
prompt_tokens: u64Input tokens (provider’s prompt_tokens field).
completion_tokens: u64Output tokens (provider’s completion_tokens field).
input_tokens: u64Duplicate of prompt_tokens under the wire-format name.
output_tokens: u64Duplicate of completion_tokens under the wire-format name.
latency_ms: u64End-to-end latency in milliseconds.
ttft_ms: Option<u64>Time-to-first-token in milliseconds, when the provider streamed.
success: booltrue iff the provider returned a non-error response.
Implementations§
Source§impl ProviderRequestRecord
impl ProviderRequestRecord
Sourcepub fn tokens_per_second(&self) -> f64
pub fn tokens_per_second(&self) -> f64
Output tokens per second over the full request latency. Returns 0.0
when latency_ms is zero, never panics.
Trait Implementations§
Source§impl Clone for ProviderRequestRecord
impl Clone for ProviderRequestRecord
Source§fn clone(&self) -> ProviderRequestRecord
fn clone(&self) -> ProviderRequestRecord
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProviderRequestRecord
impl Debug for ProviderRequestRecord
Source§impl<'de> Deserialize<'de> for ProviderRequestRecord
impl<'de> Deserialize<'de> for ProviderRequestRecord
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ProviderRequestRecord
impl RefUnwindSafe for ProviderRequestRecord
impl Send for ProviderRequestRecord
impl Sync for ProviderRequestRecord
impl Unpin for ProviderRequestRecord
impl UnsafeUnpin for ProviderRequestRecord
impl UnwindSafe for ProviderRequestRecord
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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