Skip to main content

init

Function init 

Source
pub fn init(
    otlp: Option<OtlpConfig>,
    fmt_default_filter: &str,
    otel_default_filter: &str,
    tracer_name: &str,
) -> Result<TelemetryGuard, TelemetryError>
Expand description

Install the global tracing subscriber.

The subscriber has a stdout JSON fmt layer. When otlp is Some, the subscriber also has a batch OTLP export layer.

  • fmt_default_filter: the fmt layer’s filter when RUST_LOG is unset.
  • otel_default_filter: the OTLP layer’s filter when KRABKA_OTLP_FILTER is unset.
  • tracer_name: the name that this function passes to TracerProvider::tracer(...).

You must call this function exactly one time, and from inside the tokio runtime. The gRPC exporter captures the current runtime handle.

§Errors

Returns TelemetryError::Exporter when an OTLP exporter cannot be built. On wasm32-wasip1, returns TelemetryError::Unsupported for any OTLP configuration and installs nothing.