Creates a new span within the current trace, evaluates the expression,
and ends the span. The span is available via current_span()
during evaluation.
Thread Safety
The context stack is process-global, following R's standard single-threaded
assumption. Parallel workers spawned via future, callr, or
parallel receive isolated copies of the stack, so spans created in
those workers will not appear in the parent trace. This is consistent
with how options(), par(), and Sys.setenv() behave in
base R.
Examples
# Use with_span inside a trace
with_trace("example", {
result <- with_span("compute", type = "tool", {
sqrt(144)
})
result
})
#> [1] 12