You can use this function to test that OpenTelemetry output is correctly generated for your package or application.
Value
A list with the output for each output type. Entries:
value
: value ofexpr
.traces
: the recorded spans, if requested inwhat
.metrics
: the recorded metrics measurements, if requested inwhat
.
Details
It evaluates the supplied expression, collects OpenTelemetry output from it and returns it.
Note: with_otel_record()
cannot record logs yet.
with_otel_record()
uses tracer_provider_memory and
meter_provider_memory internally.
Examples
spns <- with_otel_record({
trc <- otel::get_tracer("mytracer")
spn1 <- trc$start_local_active_span()
spn2 <- trc$start_local_active_span("my")
spn2$end()
spn1$end()
NULL
})
spns
#> $value
#> NULL
#>
#> $traces
#> $traces$my
#> <otel_span_data>
#> trace_id : 0e513154d0a0524107d89f759d551de3
#> span_id : 8b16d11dc55fb079
#> name : my
#> flags : +sampled -random
#> parent : 55a9dd20c10ac77e
#> description :
#> resource_attributes :
#> os.type : linux
#> process.owner : runner
#> process.pid : 9194
#> process.runtime.description : R version 4.5.1 (2025-06-13)
#> process.runtime.name : R
#> process.runtime.version : 4.5.1
#> service.name : unknown_service
#> telemetry.sdk.language : R
#> telemetry.sdk.name : opentelemetry
#> telemetry.sdk.version : 0.2.0
#> schema_url :
#> instrumentation_scope :
#> <otel_instrumentation_scope_data>
#> name : mytracer
#> version :
#> schema_url :
#> attributes :
#> kind : internal
#> status : unset
#> start_time : 2025-09-11 08:57:10
#> duration : 0.000145723
#> attributes :
#> events :
#> links :
#>
#> $traces$`<NA>`
#> <otel_span_data>
#> trace_id : 0e513154d0a0524107d89f759d551de3
#> span_id : 55a9dd20c10ac77e
#> name : <NA>
#> flags : +sampled -random
#> parent : 0000000000000000
#> description :
#> resource_attributes :
#> os.type : linux
#> process.owner : runner
#> process.pid : 9194
#> process.runtime.description : R version 4.5.1 (2025-06-13)
#> process.runtime.name : R
#> process.runtime.version : 4.5.1
#> service.name : unknown_service
#> telemetry.sdk.language : R
#> telemetry.sdk.name : opentelemetry
#> telemetry.sdk.version : 0.2.0
#> schema_url :
#> instrumentation_scope :
#> <otel_instrumentation_scope_data>
#> name : mytracer
#> version :
#> schema_url :
#> attributes :
#> kind : internal
#> status : unset
#> start_time : 2025-09-11 08:57:10
#> duration : 0.000664221
#> attributes :
#> events :
#> links :
#>
#>
#> $metrics
#> <otel_metrics_data>
#> <otel_resouce_metrics>
#> attributes:
#> os.type : linux
#> process.owner : runner
#> process.pid : 9194
#> process.runtime.description : R version 4.5.1 (2025-06-13)
#> process.runtime.name : R
#> process.runtime.version : 4.5.1
#> service.name : unknown_service
#> telemetry.sdk.language : R
#> telemetry.sdk.name : opentelemetry
#> telemetry.sdk.version : 0.2.0
#> scope_metric_data [0]:
#>
#>