pub fn init_tracer<F>(
resource: Resource,
transform: F,
) -> Result<SdkTracerProvider, InitTracerError>
Expand description
Initializes an OpenTelemetry tracer provider with OTLP exporter configuration.
This function creates a fully configured tracer provider with an OTLP exporter that reads configuration from environment variables. It supports both HTTP and gRPC protocols and allows for custom transformation of the tracer provider builder.
§Environment Variables
The function reads configuration from the following environment variables:
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
/OTEL_EXPORTER_OTLP_ENDPOINT
: Exporter endpointOTEL_EXPORTER_OTLP_TRACES_PROTOCOL
/OTEL_EXPORTER_OTLP_PROTOCOL
: Protocol (grpc, http, http/protobuf)OTEL_EXPORTER_OTLP_TRACES_TIMEOUT
/OTEL_EXPORTER_OTLP_TIMEOUT
: Timeout in millisecondsOTEL_EXPORTER_OTLP_HEADERS
/OTEL_EXPORTER_OTLP_TRACES_HEADERS
: Additional headersOTEL_TRACES_SAMPLER
: Sampling strategy configurationOTEL_TRACES_SAMPLER_ARG
: Sampling rate for ratio-based samplers
§Arguments
resource
: OpenTelemetry resource containing service metadatatransform
: Function to customize the tracer provider builder before building
§Returns
A configured TracerProvider
on success, or an InitTracerError
on failure
§Examples
use opentelemetry_sdk::Resource;
use telemetry_rust::otlp::{identity, init_tracer};
let resource = Resource::builder().build();
let tracer_provider = init_tracer(resource, identity)?;