### TonicExporterBuilder Usage Examples Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.TonicExporterBuilder.html?search=u32+-%3E+bool Examples demonstrating how to use TonicExporterBuilder with different exporter types (span, metric, log) and configurations. ```APIDOC ## TonicExporterBuilder ### Description Configuration for the tonic OTLP GRPC exporter. It allows you to add additional metadata, set TLS config, and specify custom channels. ### Examples #### Span Exporter ```rust use opentelemetry_sdk::metrics::Temporality; // Create a span exporter you can use to when configuring tracer providers let span_exporter = opentelemetry_otlp::SpanExporter::builder().with_tonic().build()?; ``` #### Metric Exporter ```rust use opentelemetry_sdk::metrics::Temporality; // Create a metric exporter you can use when configuring meter providers let metric_exporter = opentelemetry_otlp::MetricExporter::builder() .with_tonic() .with_temporality(Temporality::default()) .build()?; ``` #### Log Exporter ```rust // Create a log exporter you can use when configuring logger providers let log_exporter = opentelemetry_otlp::LogExporter::builder().with_tonic().build()?; ``` ``` -------------------------------- ### TonicExporterBuilder Usage Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.TonicExporterBuilder.html?search=std%3A%3Avec Examples demonstrating how to create span, metric, and log exporters using TonicExporterBuilder. ```APIDOC ## TonicExporterBuilder Configuration for the tonic OTLP GRPC exporter. It allows you to: * add additional metadata * set tls config (via the `tls-ring`, `tls-aws-lc`, or `tls-provider-agnostic` features) * specify custom channels ### Examples ```rust use opentelemetry_sdk::metrics::Temporality; // Create a span exporter you can use to when configuring tracer providers let span_exporter = opentelemetry_otlp::SpanExporter::builder().with_tonic().build()?; // Create a metric exporter you can use when configuring meter providers let metric_exporter = opentelemetry_otlp::MetricExporter::builder() .with_tonic() .with_temporality(Temporality::default()) .build()?; // Create a log exporter you can use when configuring logger providers let log_exporter = opentelemetry_otlp::LogExporter::builder().with_tonic().build()?; ``` ``` -------------------------------- ### Metric Search Examples Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.MetricExporter.html?search= Demonstrates various ways to search for metrics using different patterns and types. ```APIDOC ## Metric Search This section provides examples of how to search for metrics. ### Example Searches - `std::vec` - `u32 -> bool` - `Option, (T -> U) -> Option` ``` -------------------------------- ### Run Prometheus with OTLP Receiver Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/index.html?search=u32+-%3E+bool Start a Prometheus Docker container with OTLP receiver enabled and a configuration file mounted. An empty prometheus.yml is sufficient. ```bash docker run -p 9090:9090 -v ./prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml --web.enable-otlp-receiver ``` -------------------------------- ### Create a new LogExporterBuilder Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.LogExporterBuilder.html Initializes a new LogExporterBuilder with default settings. This is the starting point for configuring a LogExporter. ```rust pub fn new() -> Self ``` -------------------------------- ### Build Span, Metrics, and Log Exporters with HttpExporterBuilder Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.HttpExporterBuilder.html?search= Demonstrates how to create span, metrics, and log exporters using the HttpExporterBuilder. The metrics exporter includes an example of setting the temporality. ```rust use opentelemetry_sdk::metrics::Temporality; // Create a span exporter you can use when configuring tracer providers let span_exporter = opentelemetry_otlp::SpanExporter::builder().with_http().build()?; // Create a metrics exporter you can use when configuring meter providers let metrics_exporter = opentelemetry_otlp::MetricExporter::builder() .with_http() .with_temporality(Temporality::default()) .build()?; // Create a log exporter you can use when configuring logger providers let log_exporter = opentelemetry_otlp::LogExporter::builder().with_http().build()?; ``` -------------------------------- ### MetricExporterBuilder::new Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.MetricExporterBuilder.html Creates a new MetricExporterBuilder with default settings. This is the starting point for configuring a MetricExporter. ```APIDOC ## new() ### Description Create a new MetricExporterBuilder with default settings. ### Signature ```rust pub fn new() -> Self ``` ``` -------------------------------- ### LogExporterBuilder::new Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.LogExporterBuilder.html Creates a new LogExporterBuilder with default settings. This is the starting point for configuring a LogExporter. ```APIDOC ## LogExporterBuilder::new ### Description Create a new LogExporterBuilder with default settings. ### Method `new()` ### Returns `Self` - A new instance of LogExporterBuilder. ``` -------------------------------- ### SpanExporterBuilder::new Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.SpanExporterBuilder.html Creates a new SpanExporterBuilder with default settings. This is the starting point for configuring an OTLP span exporter. ```APIDOC ## SpanExporterBuilder::new ### Description Create a new SpanExporterBuilder with default settings. ### Method `new()` ### Returns - `Self`: A new instance of SpanExporterBuilder. ``` -------------------------------- ### Configure OTLP Exporters for Traces, Metrics, and Logs Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/index.html?search=u32+-%3E+bool Demonstrates setting up OTLP exporters for traces, metrics, and logs using the builder pattern. Common configurations like endpoint and timeout are applied across all signals. Ensure the correct builder entry point and signal-specific environment variables are used. ```rust use opentelemetry_otlp::{WithExportConfig, WithTonicConfig}; use opentelemetry_sdk::{ trace::SdkTracerProvider, metrics::SdkMeterProvider, logs::SdkLoggerProvider, Resource, }; use std::time::Duration; let resource = Resource::builder() .with_service_name("my-service") .build(); // Traces let span_exporter = opentelemetry_otlp::SpanExporter::builder() .with_tonic() .with_endpoint("http://my-collector:4317") .with_timeout(Duration::from_secs(5)) .build() .expect("Failed to build SpanExporter"); let tracer_provider = SdkTracerProvider::builder() .with_resource(resource.clone()) .with_batch_exporter(span_exporter) .build(); // Metrics let metric_exporter = opentelemetry_otlp::MetricExporter::builder() .with_tonic() .with_endpoint("http://my-collector:4317") .with_timeout(Duration::from_secs(5)) .build() .expect("Failed to build MetricExporter"); let meter_provider = SdkMeterProvider::builder() .with_resource(resource.clone()) .with_periodic_exporter(metric_exporter) .build(); // Logs let log_exporter = opentelemetry_otlp::LogExporter::builder() .with_tonic() .with_endpoint("http://my-collector:4317") .with_timeout(Duration::from_secs(5)) .build() .expect("Failed to build LogExporter"); let logger_provider = SdkLoggerProvider::builder() .with_resource(resource) .with_batch_exporter(log_exporter) .build(); ``` -------------------------------- ### Basic Exporter Configuration with Tonic Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/trait.WithTonicConfig.html?search= Demonstrates setting up a SpanExporter builder with Tonic support and enabling Gzip compression. This is useful for configuring the exporter's communication protocol. ```rust use opentelemetry_otlp::{WithExportConfig, WithTonicConfig}; let exporter_builder = opentelemetry_otlp::SpanExporter::builder() .with_tonic() .with_compression(opentelemetry_otlp::Compression::Gzip); ``` -------------------------------- ### Any::type_id Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.SpanExporterBuilder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the TypeId of the value. ```APIDOC ## fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more ``` -------------------------------- ### Initialize OTLP Exporter and Export Metrics Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/index.html?search=u32+-%3E+bool Configure and initialize an OTLP metric exporter using the HTTP binary protocol and export metrics. Ensure the meter provider is shut down to trigger the final export. ```rust use opentelemetry::global; use opentelemetry::metrics::Meter; use opentelemetry::KeyValue; use opentelemetry_otlp::Protocol; use opentelemetry_otlp::WithExportConfig; fn main() -> Result<(), Box> { // Initialize OTLP exporter using HTTP binary protocol let exporter = opentelemetry_otlp::MetricExporter::builder() .with_http() .with_protocol(Protocol::HttpBinary) .with_endpoint("http://localhost:9090/api/v1/otlp/v1/metrics") .build()?; // Create a meter provider with the OTLP Metric exporter let meter_provider = opentelemetry_sdk::metrics::SdkMeterProvider::builder() .with_periodic_exporter(exporter) .build(); global::set_meter_provider(meter_provider.clone()); // Get a meter let meter = global::meter("my_meter"); // Create a metric let counter = meter.u64_counter("my_counter").build(); counter.add(1, &[KeyValue::new("key", "value")]); // Shutdown the meter provider. This will trigger an export of all metrics. meter_provider.shutdown()?; Ok(()) } ``` -------------------------------- ### Any::type_id Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.LogExporterBuilder.html?search=u32+-%3E+bool Gets the `TypeId` of the LogExporterBuilder. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Returns - `TypeId`: The unique identifier for the type of `self`. ``` -------------------------------- ### TonicExporterBuilderSet::type_id Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.TonicExporterBuilderSet.html?search=u32+-%3E+bool Gets the `TypeId` of `self`. ```APIDOC ### fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more ``` -------------------------------- ### Any for T Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.MetricExporterBuilder.html?search=u32+-%3E+bool Provides a method to get the TypeId of a type. ```APIDOC ## fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. ### Method type_id ### Parameters - `&self`: A reference to the object. ### Returns The `TypeId` of the object. ``` -------------------------------- ### impl Any for T Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/enum.Protocol.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `type_id` method to get the `TypeId` of an object. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ``` -------------------------------- ### type_id Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.LogExporter.html?search= Gets the `TypeId` of `self`. This is a fundamental method for type introspection. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method N/A (associated function) ### Parameters None ### Response #### Success Response - **TypeId**: The unique identifier for the type of `self`. ``` -------------------------------- ### Configure gRPC Exporter with Metadata and Compression Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/index.html?search=u32+-%3E+bool Set custom gRPC metadata (headers) and compression for the exporter. Metadata is additive. Ensure the correct compression feature (e.g., `gzip-tonic`) is enabled. ```rust use opentelemetry_otlp::{WithExportConfig, WithTonicConfig, Compression}; use std::time::Duration; use tonic::metadata::MetadataMap; // ── gRPC metadata (custom request headers) ─────────────────────────────── // MetadataMap carries per-call key/value pairs sent as HTTP/2 headers. // with_metadata() is additive: calling it multiple times merges entries. let mut metadata = MetadataMap::with_capacity(3); metadata.insert("x-host", "example.com".parse().unwrap()); metadata.insert("x-api-key", "secret".parse().unwrap()); metadata.insert_bin("trace-proto-bin", tonic::metadata::MetadataValue::from_bytes(b"[bin]")); let exporter = opentelemetry_otlp::SpanExporter::builder() .with_tonic() // Target gRPC endpoint. Defaults to http://localhost:4317. // Env var: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT (or OTEL_EXPORTER_OTLP_ENDPOINT). .with_endpoint("http://my-collector:4317") // Per-export timeout. Defaults to 10 s. // Env var: OTEL_EXPORTER_OTLP_TRACES_TIMEOUT (or OTEL_EXPORTER_OTLP_TIMEOUT). .with_timeout(Duration::from_secs(5)) // Custom gRPC metadata (auth tokens, routing headers, …). // Env var: OTEL_EXPORTER_OTLP_TRACES_HEADERS (or OTEL_EXPORTER_OTLP_HEADERS). .with_metadata(metadata) // Compression. Requires the `gzip-tonic` or `zstd-tonic` feature. // Env var: OTEL_EXPORTER_OTLP_TRACES_COMPRESSION (or OTEL_EXPORTER_OTLP_COMPRESSION). .with_compression(Compression::Gzip) .build() .expect("Failed to build SpanExporter"); ``` -------------------------------- ### fn type_id(&self) -> TypeId Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.NoExporterBuilderSet.html?search= Gets the `TypeId` of `self`. This method is part of the `Any` trait implementation. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters None ### Response #### Success Response - **TypeId**: The unique identifier for the type of `self`. ``` -------------------------------- ### Configuring Span Exporter with HTTP Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/trait.WithHttpConfig.html Demonstrates how to initialize a SpanExporter builder and configure it to use HTTP with custom headers. ```rust use crate::opentelemetry_otlp::WithHttpConfig; let exporter_builder = opentelemetry_otlp::SpanExporter::builder() .with_http() .with_headers(std::collections::HashMap::new()); ``` -------------------------------- ### Configure gRPC OTLP Exporter without Tokio (Rust) Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/index.html Initializes an OTLP span exporter using gRPC (Tonic) and manually manages a Tokio runtime. Use this if you cannot use `#[tokio::main]`. ```rust use opentelemetry::{global, trace::Tracer}; fn main() -> Result<(), Box> { // Initialize OTLP exporter using gRPC (Tonic) let rt = tokio::runtime::Runtime::new()?; let tracer_provider = rt.block_on(async { let exporter = opentelemetry_otlp::SpanExporter::builder() .with_tonic() .build() .expect("Failed to create span exporter"); opentelemetry_sdk::trace::SdkTracerProvider::builder() .with_batch_exporter(exporter) .build() }); // Set it as the global provider global::set_tracer_provider(tracer_provider); // Get a tracer and create spans let tracer = global::tracer("my_tracer"); tracer.in_span("doing_work", |_cx| { // Your application logic here... }); // Ensure the runtime (`rt`) remains active until the program ends Ok(()) } ``` -------------------------------- ### Creating Tonic Exporters Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.TonicExporterBuilder.html Demonstrates how to create span, metric, and log exporters using TonicExporterBuilder. Ensure the `grpc-tonic` feature is enabled. For metric exporters, you can also specify temporality. ```rust use opentelemetry_sdk::metrics::Temporality; // Create a span exporter you can use to when configuring tracer providers let span_exporter = opentelemetry_otlp::SpanExporter::builder().with_tonic().build()?; // Create a metric exporter you can use when configuring meter providers let metric_exporter = opentelemetry_otlp::MetricExporter::builder() .with_tonic() .with_temporality(Temporality::default()) .build()?; // Create a log exporter you can use when configuring logger providers let log_exporter = opentelemetry_otlp::LogExporter::builder().with_tonic().build()?; ``` -------------------------------- ### Configure OTLP Exporter via gRPC without Tokio::main Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/index.html?search=u32+-%3E+bool Initializes an OTLP span exporter using gRPC without relying on the `#[tokio::main]` attribute. This requires manually creating and managing a Tokio runtime. ```rust use opentelemetry::{ global, trace::Tracer }; fn main() -> Result<(), Box> { // Initialize OTLP exporter using gRPC (Tonic) let rt = tokio::runtime::Runtime::new()?; let tracer_provider = rt.block_on(async { let exporter = opentelemetry_otlp::SpanExporter::builder() .with_tonic() .build() .expect("Failed to create span exporter"); opentelemetry_sdk::trace::SdkTracerProvider::builder() .with_batch_exporter(exporter) .build() }); // Set it as the global provider global::set_tracer_provider(tracer_provider); // Get a tracer and create spans let tracer = global::tracer("my_tracer"); tracer.in_span("doing_work", |_cx| { // Your application logic here... }); // Ensure the runtime (`rt`) remains active until the program ends Ok(()) } ``` -------------------------------- ### with_current_subscriber Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.LogExporter.html?search= Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper. Simplifies telemetry setup. ```APIDOC ## fn with_current_subscriber(self) -> WithDispatch ### Description Attaches the current default `Subscriber` to this type, returning a `WithDispatch` wrapper. ### Method N/A (associated function) ### Parameters None ### Response #### Success Response - **WithDispatch** - A wrapper type containing the original value and the current default subscriber. ``` -------------------------------- ### Configure OTLP Exporter via HTTP Binary Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/index.html?search=u32+-%3E+bool Initializes an OTLP span exporter using the HTTP binary protocol. Ensure the OpenTelemetry Collector is running and accessible. ```rust use opentelemetry::global; use opentelemetry::trace::Tracer; use opentelemetry_otlp::Protocol; use opentelemetry_otlp::WithExportConfig; fn main() -> Result<(), Box> { // Initialize OTLP exporter using HTTP binary protocol let otlp_exporter = opentelemetry_otlp::SpanExporter::builder() .with_http() .with_protocol(Protocol::HttpBinary) .build()?; // Create a tracer provider with the exporter let tracer_provider = opentelemetry_sdk::trace::SdkTracerProvider::builder() .with_batch_exporter(otlp_exporter) .build(); // Set it as the global provider global::set_tracer_provider(tracer_provider); // Get a tracer and create spans let tracer = global::tracer("my_tracer"); tracer.in_span("doing_work", |_cx| { // Your application logic here... }); Ok(()) } ``` -------------------------------- ### LogExporterBuilder::new Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.LogExporterBuilder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new LogExporterBuilder with default settings. ```APIDOC ## LogExporterBuilder::new ### Description Create a new LogExporterBuilder with default settings. ### Method `pub fn new() -> Self` ``` -------------------------------- ### Obtain MetricExporter Builder Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.MetricExporter.html Use this function to get a builder for configuring a MetricExporter. The builder allows for setting up the exporter before it is created. ```rust pub fn builder() -> MetricExporterBuilder ``` -------------------------------- ### with_interceptor Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/trait.WithTonicConfig.html Use a custom `interceptor` to modify each outbound request. This can be used to modify the gRPC metadata, for example to inject auth tokens. ```APIDOC ## with_interceptor ### Description Use a custom `interceptor` to modify each outbound request. This can be used to modify the gRPC metadata, for example to inject auth tokens. Calling this method multiple times will replace the previous interceptor. If you need multiple interceptors, chain them together before passing to this method. ### Method `with_interceptor` ### Parameters - **interceptor** (I) - Required - The interceptor to use. Must implement `Interceptor + Clone + Send + Sync + 'static`. ### Returns `Self` - The modified exporter builder. ### Example #### Single interceptor ```rust use tonic::{Request, Status}; use opentelemetry_otlp::WithTonicConfig; fn auth_interceptor(mut req: Request<()>) -> Result, Status> { req.metadata_mut().insert("authorization", "Bearer token".parse().unwrap()); Ok(req) } let exporter = opentelemetry_otlp::SpanExporter::builder() .with_tonic() .with_interceptor(auth_interceptor) .build()?; ``` #### Multiple interceptors (chaining) ```rust use tonic::{Request, Status}; use opentelemetry_otlp::WithTonicConfig; fn auth_interceptor(mut req: Request<()>) -> Result, Status> { req.metadata_mut().insert("authorization", "Bearer token".parse().unwrap()); Ok(req) } fn logging_interceptor(req: Request<()>) -> Result, Status> { println!("Sending gRPC request with metadata: {:?}", req.metadata()); Ok(req) } // Chain interceptors by wrapping them fn combined_interceptor(req: Request<()>) -> Result, Status> { let req = logging_interceptor(req)?; auth_interceptor(req) } let exporter = opentelemetry_otlp::SpanExporter::builder() .with_tonic() .with_interceptor(combined_interceptor) .build()?; ``` ``` -------------------------------- ### PolicyExt::or Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.TonicExporterBuilder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Combines two policies, creating a new policy that returns Action::Follow if either returns Action::Follow. ```APIDOC ## PolicyExt::or ### Description Creates a new `Policy` that returns `Action::Follow` if either `self` or `other` policy returns `Action::Follow`. This is useful for creating composite policies where at least one condition must be met. ### Method `or` ### Parameters - **other** (`P`) - The other policy to combine with the current one. ### Type Parameters - `P`: The type of the other policy, which must also implement `Policy`. - `B`: The type of the binding. - `E`: The type of the error. ### Returns - `Or` - A new policy that represents the logical OR of the two input policies. ``` -------------------------------- ### impl CloneToUninit for T Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/enum.Protocol.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `clone_to_uninit` method for nightly-only experimental cloning to uninitialized memory. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description Performs copy-assignment from `self` to `dest`. This is a nightly-only experimental API. ### Method `clone_to_uninit` ``` -------------------------------- ### HttpExporterBuilder::search Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.HttpExporterBuilder.html?search=std%3A%3Avec This function is intended for searching within HttpExporterBuilder configurations. However, no specific implementation details or usage examples are available in the provided source. ```APIDOC ## fn search() ### Description This function is related to searching within HttpExporterBuilder. Specific details about its parameters, return values, or usage are not provided in the source documentation. ### Method Not specified in the source. ### Endpoint Not applicable for this Rust function. ### Parameters None explicitly documented. ### Request Example No example available in the source. ### Response No specific response details available in the source. ``` -------------------------------- ### with_interceptor Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.TonicExporterBuilder.html Use a custom `interceptor` to modify each outbound request. This can be used to modify the gRPC metadata, for example to inject auth tokens. Read more. Available on crate feature `grpc-tonic` only. ```APIDOC ## fn with_interceptor(self, interceptor: I) -> B where I: Interceptor + Clone + Send + Sync + 'static, ### Description Use a custom `interceptor` to modify each outbound request. This can be used to modify the gRPC metadata, for example to inject auth tokens. ### Parameters - **interceptor** (I) - Description for interceptor ### Availability Available on **crate feature`grpc-tonic`** only. ``` -------------------------------- ### LogExporterBuilder::with_interceptor Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.LogExporterBuilder.html?search=u32+-%3E+bool Uses a custom `interceptor` to modify each outbound request. This can be used to modify the gRPC metadata, for example to inject auth tokens. Available on `grpc-tonic` crate feature. ```APIDOC ## fn with_interceptor(self, interceptor: I) -> B where I: Interceptor + Clone + Send + Sync + 'static, Available on **crate feature`grpc-tonic`** only. Use a custom `interceptor` to modify each outbound request. This can be used to modify the gRPC metadata, for example to inject auth tokens. Read more ``` -------------------------------- ### Build Log Exporter Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.HttpExporterBuilder.html Creates a log exporter with the current configuration. Available on crate feature `logs` only. ```APIDOC ## build_log_exporter ### Description Create a log exporter with the current configuration ### Method `HttpExporterBuilder.build_log_exporter()` ### Parameters None ### Response - `Result`: A log exporter or a build error. ``` -------------------------------- ### from_env() Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/enum.Protocol.html Attempts to parse a protocol from the `OTEL_EXPORTER_OTLP_PROTOCOL` environment variable. Returns `None` if the variable is not set, the value doesn't match a known protocol, or the specified protocol's feature is not enabled. ```APIDOC ## impl Protocol ### pub fn from_env() -> Option Available on **crate features`grpc-tonic` or `http-proto` or `http-json`** only. Attempts to parse a protocol from the `OTEL_EXPORTER_OTLP_PROTOCOL` environment variable. Returns `None` if: * The environment variable is not set * The value doesn’t match a known protocol * The specified protocol’s feature is not enabled ``` -------------------------------- ### Creating HTTP Exporters with HttpExporterBuilder Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.HttpExporterBuilder.html Demonstrates how to create span, metrics, and log exporters using the HttpExporterBuilder. Ensure the necessary crate features (`http-proto` or `http-json`) are enabled for HTTP support. ```rust use opentelemetry_sdk::metrics::Temporality; // Create a span exporter you can use when configuring tracer providers let span_exporter = opentelemetry_otlp::SpanExporter::builder().with_http().build()?; // Create a metrics exporter you can use when configuring meter providers let metrics_exporter = opentelemetry_otlp::MetricExporter::builder() .with_http() .with_temporality(Temporality::default()) .build()?; // Create a log exporter you can use when configuring logger providers let log_exporter = opentelemetry_otlp::LogExporter::builder().with_http().build()?; ``` -------------------------------- ### Configure gRPC OTLP Exporter with Tokio (Rust) Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/index.html Initializes an OTLP span exporter using gRPC (Tonic) within a Tokio runtime. This is suitable for asynchronous applications. ```rust use opentelemetry::{global, trace::Tracer}; #[tokio::main] async fn main() -> Result<(), Box> { // Initialize OTLP exporter using gRPC (Tonic) let otlp_exporter = opentelemetry_otlp::SpanExporter::builder() .with_tonic() .build()?; // Create a tracer provider with the exporter let tracer_provider = opentelemetry_sdk::trace::SdkTracerProvider::builder() .with_batch_exporter(otlp_exporter) .build(); // Set it as the global provider global::set_tracer_provider(tracer_provider); // Get a tracer and create spans let tracer = global::tracer("my_tracer"); tracer.in_span("doing_work", |_cx| { // Your application logic here... }); Ok(()) } ``` -------------------------------- ### gRPC (Tonic) Configuration Methods Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.LogExporterBuilder.html?search= Methods for configuring gRPC-specific settings using Tonic for the Log Exporter Builder. ```APIDOC ## gRPC (Tonic) Configuration ### `with_metadata(self, metadata: MetadataMap) -> B` Available on **crate feature `grpc-tonic`** only. **Description**: Sets custom metadata entries to send to the collector. **Method**: Builder method **Parameters**: * **metadata** (MetadataMap): A map of metadata entries. ### `with_tls_config(self, tls_config: ClientTlsConfig) -> B` Available on **crate feature `grpc-tonic` and (crate features `tls` or `tls-ring` or `tls-aws-lc` or `tls-provider-agnostic`)** only. **Description**: Sets the TLS settings for the collector endpoint. **Method**: Builder method **Parameters**: * **tls_config** (ClientTlsConfig): The TLS configuration. ### `with_compression(self, compression: Compression) -> B` Available on **crate feature `grpc-tonic`** only. **Description**: Sets the compression algorithm to use when communicating with the collector. **Method**: Builder method **Parameters**: * **compression** (Compression): The compression algorithm. ### `with_channel(self, channel: Channel) -> B` Available on **crate feature `grpc-tonic`** only. **Description**: Uses `channel` as tonic’s transport channel. This will override TLS config and should only be used when working with non-HTTP transports. **Method**: Builder method **Parameters**: * **channel** (Channel): The tonic transport channel. ### `with_interceptor(self, interceptor: I) -> B` Available on **crate feature `grpc-tonic`** only. **Description**: Uses a custom `interceptor` to modify each outbound request. This can be used to modify the gRPC metadata, for example to inject auth tokens. **Method**: Builder method **Parameters**: * **interceptor** (I): The interceptor implementation. `I` must implement `Interceptor + Clone + Send + Sync + 'static`. ### `with_retry_policy(self, policy: RetryPolicy) -> B` Available on **crate features `grpc-tonic` and `experimental-grpc-retry`** only. **Description**: Sets the retry policy for gRPC requests. **Method**: Builder method **Parameters**: * **policy** (RetryPolicy): The retry policy to apply. ``` -------------------------------- ### Configure HTTP Exporter Options Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/index.html?search=u32+-%3E+bool Set various HTTP export options like endpoint, timeout, protocol, headers, and compression. The `http-proto` feature is required by default. Environment variables can also be used to configure these settings. ```rust use opentelemetry_otlp::{WithExportConfig, WithHttpConfig, Protocol, Compression}; use std::time::Duration; use std::collections::HashMap; let exporter = opentelemetry_otlp::SpanExporter::builder() .with_http() // Target base URL. Defaults to http://localhost:4318. // The path /v1/traces (or /v1/metrics, /v1/logs) is appended automatically. // Env var: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT (or OTEL_EXPORTER_OTLP_ENDPOINT). .with_endpoint("http://my-collector:4318") // Per-export timeout. Defaults to 10 s. // Env var: OTEL_EXPORTER_OTLP_TRACES_TIMEOUT (or OTEL_EXPORTER_OTLP_TIMEOUT). .with_timeout(Duration::from_secs(5)) // Transport encoding. HttpBinary (protobuf) is the default. // HttpJson requires the `http-json` feature. // Env var: OTEL_EXPORTER_OTLP_PROTOCOL. .with_protocol(Protocol::HttpBinary) // Custom HTTP headers (auth tokens, routing headers, …). // Values are URL-decoded when read from environment variables. // Env var: OTEL_EXPORTER_OTLP_TRACES_HEADERS (or OTEL_EXPORTER_OTLP_HEADERS). .with_headers(HashMap::from([ ("x-api-key".to_string(), "secret".to_string()), ])) // Compression. Requires the `gzip-http` or `zstd-http` feature. // Env var: OTEL_EXPORTER_OTLP_TRACES_COMPRESSION (or OTEL_EXPORTER_OTLP_COMPRESSION). .with_compression(Compression::Gzip) .build() .expect("Failed to build SpanExporter"); ``` -------------------------------- ### HTTP Client Configuration Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.MetricExporterBuilder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Configure the HTTP client for communication. ```APIDOC ## fn with_http_client(self, client: T) -> B ### Description Assign client implementation. Available on **crate features`http-proto` or `http-json`** only. ### Parameters #### Path Parameters - **client** (T) - Description: The HTTP client implementation. ``` -------------------------------- ### CloneToUninit::clone_to_uninit Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.SpanExporterBuilder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Performs copy-assignment from self to a raw pointer destination. This is a nightly-only experimental API. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) 🔬This is a nightly-only experimental API. (`clone_to_uninit`) Performs copy-assignment from `self` to `dest`. Read more ``` -------------------------------- ### PolicyExt::and Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.TonicExporterBuilder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Combines two policies, creating a new policy that requires both to return Action::Follow. ```APIDOC ## PolicyExt::and ### Description Creates a new `Policy` that returns `Action::Follow` only if both `self` and `other` policies return `Action::Follow`. This is useful for creating composite policies where all conditions must be met. ### Method `and` ### Parameters - **other** (`P`) - The other policy to combine with the current one. ### Type Parameters - `P`: The type of the other policy, which must also implement `Policy`. - `B`: The type of the binding. - `E`: The type of the error. ### Returns - `And` - A new policy that represents the logical AND of the two input policies. ``` -------------------------------- ### Protocol::from_env() Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/enum.Protocol.html?search= Attempts to parse a communication protocol from the `OTEL_EXPORTER_OTLP_PROTOCOL` environment variable. ```APIDOC ## Function `from_env` ### Description Attempts to parse a protocol from the `OTEL_EXPORTER_OTLP_PROTOCOL` environment variable. Returns `None` if: * The environment variable is not set * The value doesn’t match a known protocol * The specified protocol’s feature is not enabled ### Signature ```rust pub fn from_env() -> Option ``` ### Availability Available on **crate features`grpc-tonic` or `http-proto` or `http-json`** only. ``` -------------------------------- ### Configure OTLP Exporter via gRPC with Tokio Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/index.html?search=u32+-%3E+bool Initializes an OTLP span exporter using gRPC with a Tokio runtime. This is suitable for async applications. ```rust use opentelemetry::{ global, trace::Tracer }; #[tokio::main] async fn main() -> Result<(), Box> { // Initialize OTLP exporter using gRPC (Tonic) let otlp_exporter = opentelemetry_otlp::SpanExporter::builder() .with_tonic() .build()?; // Create a tracer provider with the exporter let tracer_provider = opentelemetry_sdk::trace::SdkTracerProvider::builder() .with_batch_exporter(otlp_exporter) .build(); // Set it as the global provider global::set_tracer_provider(tracer_provider); // Get a tracer and create spans let tracer = global::tracer("my_tracer"); tracer.in_span("doing_work", |_cx| { // Your application logic here... }); Ok(()) } ``` -------------------------------- ### MetricExporterBuilder::new Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.MetricExporterBuilder.html?search= Creates a new MetricExporterBuilder with default settings. ```APIDOC ## MetricExporterBuilder::new ### Description Create a new MetricExporterBuilder with default settings. ### Method `new()` ### Returns - `Self`: A new instance of MetricExporterBuilder. ``` -------------------------------- ### HTTP Exporter Configuration Options Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/index.html Demonstrates how to configure the HTTP exporter with various options such as endpoint, timeout, protocol, headers, and compression. These options are available for SpanExporter, MetricExporter, and LogExporter. ```APIDOC ## HTTP Exporter Configuration ### Description Configure the HTTP exporter with various options including endpoint, timeout, protocol, headers, and compression. ### Methods - `with_endpoint(url: &str)`: Sets the target base URL for the exporter. Defaults to `http://localhost:4318`. - `with_timeout(duration: Duration)`: Sets the per-export timeout. Defaults to 10 seconds. - `with_protocol(protocol: Protocol)`: Sets the transport encoding. Defaults to `Protocol::HttpBinary`. - `with_headers(headers: HashMap)`: Adds custom HTTP headers. - `with_compression(compression: Compression)`: Enables compression for exports. Requires `gzip-http` or `zstd-http` feature. ### Example ```rust use opentelemetry_otlp::{WithExportConfig, Protocol, Compression}; use std::time::Duration; use std::collections::HashMap; let exporter = opentelemetry_otlp::SpanExporter::builder() .with_http() .with_endpoint("http://my-collector:4318") .with_timeout(Duration::from_secs(5)) .with_protocol(Protocol::HttpBinary) .with_headers(HashMap::from([ ("x-api-key".to_string(), "secret".to_string()), ])) .with_compression(Compression::Gzip) .build() .expect("Failed to build SpanExporter"); ``` ``` -------------------------------- ### and Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.LogExporter.html?search= Creates a new `Policy` that returns `Action::Follow` only if `self` and `other` both return `Action::Follow`. Combines two policies with a logical AND. ```APIDOC ## fn and(self, other: P) -> And ### Description Create a new `Policy` that returns `Action::Follow` only if `self` and `other` return `Action::Follow`. ### Method N/A (associated function) ### Parameters - **other** (P) - The other policy to combine with. ### Response #### Success Response - **And** - A new policy representing the logical AND of `self` and `other`. ``` -------------------------------- ### Build Metrics Exporter Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.HttpExporterBuilder.html Creates a metrics exporter with the current configuration. Available on crate feature `metrics` only. ```APIDOC ## build_metrics_exporter ### Description Create a metrics exporter with the current configuration ### Method `HttpExporterBuilder.build_metrics_exporter(temporality: Temporality)` ### Parameters #### Path Parameters - **temporality** (Temporality) - Required - The temporality to use for metrics. ### Response - `Result`: A metrics exporter or a build error. ``` -------------------------------- ### Setting Export Configuration with WithExportConfig Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/trait.WithExportConfig.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to use the `with_endpoint` method to configure an exporter builder. Programmatically setting the endpoint overrides environment variables. ```rust use crate::opentelemetry_otlp::WithExportConfig; let exporter_builder = opentelemetry_otlp::SpanExporter::builder() .with_tonic() .with_endpoint("http://localhost:7201"); ``` -------------------------------- ### WithHttpConfig Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.SpanExporterBuilder.html?search=u32+-%3E+bool Methods for configuring HTTP-specific settings. ```APIDOC ## fn with_http_client(self, client: T) -> B ### Description Assign client implementation. Available on **crate features`http-proto` or `http-json`** only. ### Parameters #### Path Parameters - **client** (T): The HTTP client implementation. ### Method Not applicable (method on builder) ## fn with_headers(self, headers: HashMap) -> B ### Description Set additional headers to send to the collector. Available on **crate features`http-proto` or `http-json`** only. ### Parameters #### Path Parameters - **headers** (HashMap): A map of headers. ### Method Not applicable (method on builder) ## fn with_compression(self, compression: Compression) -> B ### Description Set the compression algorithm to use when communicating with the collector. Available on **crate features`http-proto` or `http-json`** only. ### Parameters #### Path Parameters - **compression** (Compression): The compression algorithm. ### Method Not applicable (method on builder) ## fn with_retry_policy(self, policy: RetryPolicy) -> B ### Description Set the retry policy for HTTP requests. Available on **(crate features`http-proto` or `http-json`) and crate feature `experimental-http-retry`** only. ### Parameters #### Path Parameters - **policy** (RetryPolicy): The retry policy. ### Method Not applicable (method on builder) ``` -------------------------------- ### Metric Exporter Configuration Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.MetricExporterBuilder.html Configure the basic settings for the metric exporter. ```APIDOC ## fn with_endpoint(self, endpoint: T) -> B ### Description Set the address of the OTLP collector. If not set or set to empty string, the default address is used. ### Parameters #### Path Parameters - **endpoint** (T) - Required - The OTLP collector address. ### Method `with_endpoint` ``` ```APIDOC ## fn with_protocol(self, protocol: Protocol) -> B ### Description Set the protocol to use when communicating with the collector. ### Parameters #### Path Parameters - **protocol** (Protocol) - Required - The communication protocol. ### Method `with_protocol` ``` ```APIDOC ## fn with_timeout(self, timeout: Duration) -> B ### Description Set the timeout to the collector. ### Parameters #### Path Parameters - **timeout** (Duration) - Required - The timeout duration. ### Method `with_timeout` ``` -------------------------------- ### opentelemetry_otlp::Compression::equivalent with u32 Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/constant.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL.html?search=u32+-%3E+bool Illustrates the usage of the `equivalent` method on the `Compression` enum where 'u32' is used as a generic parameter for type 'K'. ```rust pub fn equivalent(&self, _: &K) -> bool where u32: std::borrow::Borrow, ``` -------------------------------- ### default() Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/enum.Protocol.html Returns the default protocol based on enabled features. This does not consult environment variables. Protocol resolution from environment variables is handled internally by the exporter builders. Priority order (first available wins): http-json (if enabled), http-proto (if enabled), grpc-tonic (if enabled). ```APIDOC ### impl Default for Protocol Available on **crate features`grpc-tonic` or `http-proto` or `http-json`** only. Returns the default protocol based on enabled features. Note: This does not consult environment variables. Protocol resolution from environment variables is handled internally by the exporter builders. Priority order (first available wins): 1. http-json (if enabled) 2. http-proto (if enabled) 3. grpc-tonic (if enabled) #### fn default() -> Self Returns the “default value” for a type. Read more ``` -------------------------------- ### PolicyExt::or Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/enum.Compression.html Creates a new `Policy` that returns `Action::Follow` if either `self` or `other` policies return `Action::Follow`. ```APIDOC ## PolicyExt::or ### Description Create a new `Policy` that returns `Action::Follow` if either `self` or `other` return `Action::Follow`. ### Method `or` ### Parameters - `other` (P) - The other policy to combine with. ``` -------------------------------- ### TryFrom for CompressionEncoding Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/enum.Compression.html?search=u32+-%3E+bool Enables conversion from a Compression enum variant to a CompressionEncoding type, available when the `grpc-tonic` feature is enabled. ```APIDOC ### impl TryFrom for CompressionEncoding Available on **crate feature`grpc-tonic`** only. #### type Error = ExporterBuildError #### fn try_from(value: Compression) -> Result Performs the conversion. ``` -------------------------------- ### from_env() - Protocol Parsing Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/enum.Protocol.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Attempts to parse a communication protocol from the `OTEL_EXPORTER_OTLP_PROTOCOL` environment variable. ```APIDOC ## fn from_env() -> Option ### Description Attempts to parse a protocol from the `OTEL_EXPORTER_OTLP_PROTOCOL` environment variable. Returns `None` if: * The environment variable is not set * The value doesn’t match a known protocol * The specified protocol’s feature is not enabled ### Availability Available on **crate features`grpc-tonic` or `http-proto` or `http-json`** only. ``` -------------------------------- ### HTTP Configuration Methods Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.LogExporterBuilder.html?search= Methods for configuring HTTP-specific settings for the Log Exporter Builder. ```APIDOC ## HTTP Configuration Available on **crate features `http-proto` or `http-json`** only. ### `with_http_client(self, client: T) -> B` **Description**: Assigns a custom HTTP client implementation. **Method**: Builder method **Parameters**: * **client** (T): The HTTP client implementation. `T` must implement `HttpClient + 'static`. ### `with_headers(self, headers: HashMap) -> B` **Description**: Sets additional headers to send to the collector. **Method**: Builder method **Parameters**: * **headers** (HashMap): A map of headers to send. ### `with_compression(self, compression: Compression) -> B` **Description**: Sets the compression algorithm to use when communicating with the collector. **Method**: Builder method **Parameters**: * **compression** (Compression): The compression algorithm. ### `with_retry_policy(self, policy: RetryPolicy) -> B` **Description**: Sets the retry policy for HTTP requests. **Method**: Builder method **Parameters**: * **policy** (RetryPolicy): The retry policy to apply. ``` -------------------------------- ### VZip Method Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.TonicExporterBuilder.html?search=u32+-%3E+bool Method for zipping with a multi-lane. ```APIDOC ## vzip ### Description Returns a zipped version of the type. ### Method `vzip(self) -> V` ``` -------------------------------- ### From::from Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.LogExporterBuilder.html?search=u32+-%3E+bool Creates a LogExporterBuilder from a value. ```APIDOC ## fn from(t: T) -> T ### Description Returns the argument unchanged. ### Parameters - `t`: T - The value to convert. ### Returns - `T`: The converted value. ``` -------------------------------- ### Build Span Exporter Source: https://docs.rs/opentelemetry-otlp/latest/opentelemetry_otlp/struct.HttpExporterBuilder.html Creates a span exporter with the current configuration. Available on crate feature `trace` only. ```APIDOC ## build_span_exporter ### Description Create a span exporter with the current configuration ### Method `HttpExporterBuilder.build_span_exporter()` ### Parameters None ### Response - `Result`: A span exporter or a build error. ```