summarize_traces() totals a module's traces: the number of calls,
tokens, cost and latency, and the calls per model. Printing the result
gives a short report.
Value
A list of class dsprrr_trace_summary with n_traces,
total_tokens, total_latency_ms and total_cost (in US dollars, NA
when a cost is unknown). For a module with traces, it also has
total_input_tokens, total_output_tokens, total_cached_tokens,
total_duration_s, avg_latency_ms, avg_tokens_per_request,
token_breakdown (input and output totals and their ratio) and
model_usage (a data frame of calls per model).
See also
Other inspection:
accessors,
clear_prompt_history(),
clear_traces(),
export_traces(),
get_last_prompt(),
inspect_history(),
session_cost()
Examples
shout <- module_fn(
"text -> out",
function(text) list(out = toupper(text))
)
run(shout, text = "hello")
#> $out
#> [1] "HELLO"
#>
summarize_traces(shout)
#>
#> ── Module Trace Summary ──
#>
#> ── Usage Metrics
#> • 1 request
#> • 0 total tokens
#> • Input/Output ratio: NA
#> • Total cost: $NA
#>
#> ── Performance
#> • Average latency: 0ms
#> • Total time: 0s
#> • Tokens/request: NaN
if (FALSE) { # \dontrun{
qa <- module(signature("question -> answer"))
run(qa, question = "What is 2 + 2?", .llm = ellmer::chat_openai(model = "gpt-6-luna"))
summarize_traces(qa)
} # }