Learn R Programming

otel (version 0.2.0)

is_measuring_enabled: Check whether OpenTelemetry metrics collection is active

Description

This is useful for avoiding computation when metrics collection is inactive.

Usage

is_measuring_enabled(meter = NULL)

Value

TRUE is OpenTelemetry metrics collection is active, FALSE otherwise.

Arguments

meter

Meter object (otel_meter), or a meter name, the instrumentation scope, to pass to get_meter().

Details

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

See Also

Other OpenTelemetry metrics API: counter_add(), gauge_record(), histogram_record(), up_down_counter_add()

Examples

Run this code
fun <- function() {
  if (otel::is_measuring_enabled()) {
    xattr <- calculate_some_extra_attributes()
    otel::counter_add("sessions", 1, attributes = xattr)
  }
  # ...
}

Run the code above in your browser using DataLab