MCPcopy Index your code
hub / github.com/AI45Lab/Code / record_llm_usage

Function record_llm_usage

core/src/telemetry.rs:69–82  ·  view source on GitHub ↗

Record LLM token usage on the current span

(
    prompt_tokens: usize,
    completion_tokens: usize,
    total_tokens: usize,
    stop_reason: Option<&str>,
)

Source from the content-addressed store, hash-verified

67
68/// Record LLM token usage on the current span
69pub 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
85pub fn record_tool_result(exit_code: i32, duration: std::time::Duration) {

Callers 8

send_requestMethod · 0.85
send_streamingMethod · 0.85
send_requestMethod · 0.85
send_streamingMethod · 0.85
complete_llm_turnMethod · 0.85

Calls 1

recordMethod · 0.45