feat(observability): propagate optional cost_usd on agent end
This commit is contained in:
parent
52a4c9d2b8
commit
8371f412f8
6 changed files with 15 additions and 1 deletions
|
|
@ -227,6 +227,7 @@ impl Observer for OtelObserver {
|
|||
ObserverEvent::AgentEnd {
|
||||
duration,
|
||||
tokens_used,
|
||||
cost_usd,
|
||||
} => {
|
||||
let secs = duration.as_secs_f64();
|
||||
let start_time = SystemTime::now()
|
||||
|
|
@ -243,6 +244,9 @@ impl Observer for OtelObserver {
|
|||
if let Some(t) = tokens_used {
|
||||
span.set_attribute(KeyValue::new("tokens_used", *t as i64));
|
||||
}
|
||||
if let Some(c) = cost_usd {
|
||||
span.set_attribute(KeyValue::new("cost_usd", *c));
|
||||
}
|
||||
span.end();
|
||||
|
||||
self.agent_duration.record(secs, &[]);
|
||||
|
|
@ -394,10 +398,12 @@ mod tests {
|
|||
obs.record_event(&ObserverEvent::AgentEnd {
|
||||
duration: Duration::from_millis(500),
|
||||
tokens_used: Some(100),
|
||||
cost_usd: Some(0.0015),
|
||||
});
|
||||
obs.record_event(&ObserverEvent::AgentEnd {
|
||||
duration: Duration::ZERO,
|
||||
tokens_used: None,
|
||||
cost_usd: None,
|
||||
});
|
||||
obs.record_event(&ObserverEvent::ToolCallStart {
|
||||
tool: "shell".into(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue