Record LLM token usage on the current span
(
prompt_tokens: usize,
completion_tokens: usize,
total_tokens: usize,
stop_reason: Option<&str>,
)
| 67 | |
| 68 | /// Record LLM token usage on the current span |
| 69 | pub fn record_llm_usage( |
| 70 | prompt_tokens: usize, |
| 71 | completion_tokens: usize, |
| 72 | total_tokens: usize, |
| 73 | stop_reason: Option<&str>, |
| 74 | ) { |
| 75 | let span = tracing::Span::current(); |
| 76 | span.record(ATTR_LLM_PROMPT_TOKENS, prompt_tokens as i64); |
| 77 | span.record(ATTR_LLM_COMPLETION_TOKENS, completion_tokens as i64); |
| 78 | span.record(ATTR_LLM_TOTAL_TOKENS, total_tokens as i64); |
| 79 | if let Some(reason) = stop_reason { |
| 80 | span.record(ATTR_LLM_STOP_REASON, reason); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /// Record tool execution result on the current span |
| 85 | pub fn record_tool_result(exit_code: i32, duration: std::time::Duration) { |