Skip to content

Checks whether OpenTelemetry tracing is active. This can be useful to avoid unnecessary computation when tracing is inactive.

Usage

is_tracing_enabled(tracer = NULL)

Arguments

tracer

Tracer object (otel_tracer). It can also be a tracer name, the instrumentation scope, or NULL for determining the tracer name automatically. Passed to get_tracer() if not a tracer object.

Value

TRUE is OpenTelemetry tracing is active, FALSE otherwise.

Details

It calls get_tracer() with name and then it calls the tracer's $is_enabled() method.

Examples

fun <- function() {
  if (otel::is_tracing_enabled()) {
    xattr <- calculate_some_extra_attributes()
    otel::start_local_active_span("fun", attributes = xattr)
  }
  # ...
}