Skip to content

Calls get_default_tracer_provider() to get the default tracer provider. Then calls its $get_tracer() method to create a new tracer.

Usage

get_tracer(
  name = NULL,
  version = NULL,
  schema_url = NULL,
  attributes = NULL,
  ...,
  provider = NULL
)

Arguments

name

Name of the new tracer. If missing, then deduced automatically using default_tracer_name(). Make sure you read the manual page of default_tracer_name() before using this argument.

version

Optional. Specifies the version of the instrumentation scope if the scope has a version (e.g. R package version). Example value: "1.0.0".

schema_url

Optional. Specifies the Schema URL that should be recorded in the emitted telemetry.

attributes

Optional. Specifies the instrumentation scope attributes to associate with emitted telemetry.

...

Additional arguments are passed to the get_tracer() method of the provider.

provider

Tracer provider to use. If NULL, then it uses get_default_tracer_provider() to get a tracer provider.

Value

An OpenTelemetry tracer, an otel_tracer object.

Details

Usually you do not need to call this function directly, because start_local_active_span() calls it for you.

Calling get_tracer() multiple times with the same name (or same auto-deduced name) will return the same (internal) tracer object. (Even if the R external pointer objects representing them are different.)

A tracer is only deleted if its tracer provider is deleted and garbage collected.

Examples

myfun <- function() {
  trc <- otel::get_tracer()
  spn <- trc$start_span()
  on.exit(otel::end_span(spn), add = TRUE)
  otel::local_active_span(spn, end_on_exit = TRUE)
}
myfun()