Skip to contents

pin_trace() saves a module's execution traces (timing, token use, cost and, optionally, prompts and outputs) to a pins board, together with a summary from summarize_traces(). Use it to keep a record of a run for later analysis.

Usage

pin_trace(
  board,
  name,
  module,
  include_prompts = FALSE,
  include_outputs = FALSE,
  description = NULL,
  ...
)

Arguments

board

A pins board.

name

Name of the pin.

module

A module that has been run.

include_prompts

Whether to include the full prompts (default FALSE).

include_outputs

Whether to include the full outputs (default FALSE).

description

Optional pin description.

...

Further arguments passed to pins::pin_write().

Value

name, invisibly.

Details

The pin is a list with traces (from export_traces()), summary and metadata (module class, number of traces, creation time and the include flags). A module without traces is not pinned; a warning is raised instead.

Examples

board <- pins::board_temp()
shout <- module_fn("text -> out", function(text) list(out = toupper(text)))
run(shout, text = "hello")
#> $out
#> [1] "HELLO"
#> 
pin_trace(board, "shout-traces", shout, include_outputs = TRUE)
#> Creating new version '20261126T011031Z-98f5d'
#> Writing to pin 'shout-traces'
#> ✔ Pinned 1 trace: "shout-traces"
#> ℹ Total tokens: 0
pins::pin_read(board, "shout-traces")$summary
#> 
#> ── 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{
board <- pins::board_folder("pins")
classifier <- module(signature("text -> sentiment"))
run(
  classifier,
  text = c("Great!", "Terrible."),
  .llm = ellmer::chat_openai(model = "gpt-6-luna")
)

pin_trace(
  board,
  "sentiment-traces",
  classifier,
  include_prompts = TRUE,
  description = "Production run traces"
)
pins::pin_read(board, "sentiment-traces")$summary
} # }