Skip to main content

layer

Function layer 

Source
pub fn layer<S>(
    endpoint: Option<&str>,
    service_name: Option<&str>,
    sample_percent: Option<u8>,
) -> Result<(Option<impl Layer<S>>, Option<SdkTracerProvider>), Box<dyn Error + Send + Sync + 'static>>
where S: Subscriber + for<'span> LookupSpan<'span>,
Expand description

Creates an OpenTelemetry layer if an endpoint is configured.

Returns (None, None) with ZERO overhead when endpoint is None - no SDK objects are created, no background tasks are spawned.

§Arguments

  • endpoint - OTLP HTTP endpoint URL (e.g., “http://localhost:4318”)
  • service_name - Service name for traces (defaults to “zebra”)
  • sample_percent - Sampling percentage between 0 and 100 (defaults to 100)

§Errors

Returns an error if the OTLP exporter fails to initialize.