Learn R Programming

otel (version 0.2.0)

is_tracing_enabled: Check if tracing is active

Description

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

Usage

is_tracing_enabled(tracer = NULL)

Value

TRUE is OpenTelemetry tracing is active, FALSE otherwise.

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.

Details

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

See Also

Other OpenTelemetry trace API: Zero Code Instrumentation, end_span(), local_active_span(), start_local_active_span(), start_span(), tracing-constants, with_active_span()

Examples

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

Run the code above in your browser using DataLab