Spans created with start_local_active_span()
end automatically by
default. You must end every other span manually, by calling end_span
,
or using the end_on_exit
argument of local_active_span()
or
with_active_span()
.
See also
Other OpenTelemetry trace API:
Zero Code Instrumentation
,
is_tracing_enabled()
,
local_active_span()
,
start_local_active_span()
,
start_span()
,
tracing-constants
,
with_active_span()
Examples
fun <- function() {
# start span, do not activate
spn <- otel::start_span("myfun")
# do not leak resources
on.exit(otel::end_span(spn), add = TRUE)
myfun <- function() {
# activate span for this function
otel::local_active_span(spn)
# create child span
spn2 <- otel::start_local_active_span("myfun/2")
}
myfun2 <- function() {
# activate span for this function
otel::local_active_span(spn)
# create child span
spn3 <- otel::start_local_active_span("myfun/3")
}
myfun()
myfun2()
end_span(spn)
}
fun()