pub struct TracerProviderBuilder { /* private fields */ }Expand description
Builder for provider attributes.
Implementations§
Source§impl TracerProviderBuilder
impl TracerProviderBuilder
Sourcepub fn with_simple_exporter<T: SpanExporter + 'static>(
self,
exporter: T,
) -> Self
pub fn with_simple_exporter<T: SpanExporter + 'static>( self, exporter: T, ) -> Self
Adds a SimpleSpanProcessor with the configured exporter to the pipeline.
§Arguments
exporter- The exporter to be used by the SimpleSpanProcessor.
§Returns
A new Builder instance with the SimpleSpanProcessor added to the pipeline.
Processors are invoked in the order they are added.
Sourcepub fn with_batch_exporter<T: SpanExporter + 'static>(self, exporter: T) -> Self
pub fn with_batch_exporter<T: SpanExporter + 'static>(self, exporter: T) -> Self
Adds a BatchSpanProcessor with the configured exporter to the pipeline.
§Arguments
exporter- The exporter to be used by the BatchSpanProcessor.
§Returns
A new Builder instance with the BatchSpanProcessor added to the pipeline.
Processors are invoked in the order they are added.
Sourcepub fn with_span_processor<T: SpanProcessor + 'static>(
self,
processor: T,
) -> Self
pub fn with_span_processor<T: SpanProcessor + 'static>( self, processor: T, ) -> Self
Adds a custom SpanProcessor to the pipeline.
§Arguments
processor- TheSpanProcessorto be added.
§Returns
A new Builder instance with the custom SpanProcessor added to the pipeline.
Processors are invoked in the order they are added.
Sourcepub fn with_sampler(self, sampler: impl Into<Box<dyn ShouldSample>>) -> Self
pub fn with_sampler(self, sampler: impl Into<Box<dyn ShouldSample>>) -> Self
Specify the sampler to be used.
§Dynamic sampler selection
use opentelemetry_sdk::trace::{Sampler, ShouldSample};
fn should_return_dynamic_sampler() -> Box<dyn ShouldSample + 'static> {
Box::new(opentelemetry_sdk::trace::Sampler::AlwaysOn)
}
opentelemetry_sdk::trace::SdkTracerProvider::builder()
// You can pass already boxed sampler if you need to configure your sampler in a simple fashion
// This can be useful if you create your own sampler that implements `ShouldSample`
.with_sampler(should_return_dynamic_sampler())
// Or you can pass exact instance if you do not have complex configuration
.with_sampler(Sampler::AlwaysOff);Sourcepub fn with_id_generator<T: IdGenerator + 'static>(
self,
id_generator: T,
) -> Self
pub fn with_id_generator<T: IdGenerator + 'static>( self, id_generator: T, ) -> Self
Specify the id generator to be used.
Sourcepub fn with_max_events_per_span(self, max_events: u32) -> Self
pub fn with_max_events_per_span(self, max_events: u32) -> Self
Specify the number of events to be recorded per span.
Sourcepub fn with_max_attributes_per_span(self, max_attributes: u32) -> Self
pub fn with_max_attributes_per_span(self, max_attributes: u32) -> Self
Specify the number of attributes to be recorded per span.
Sourcepub fn with_max_links_per_span(self, max_links: u32) -> Self
pub fn with_max_links_per_span(self, max_links: u32) -> Self
Specify the number of events to be recorded per span.
Sourcepub fn with_max_attributes_per_event(self, max_attributes: u32) -> Self
pub fn with_max_attributes_per_event(self, max_attributes: u32) -> Self
Specify the number of attributes one event can have.
Sourcepub fn with_max_attributes_per_link(self, max_attributes: u32) -> Self
pub fn with_max_attributes_per_link(self, max_attributes: u32) -> Self
Specify the number of attributes one link can have.
Sourcepub fn with_span_limits(self, span_limits: SpanLimits) -> Self
pub fn with_span_limits(self, span_limits: SpanLimits) -> Self
Specify all limit via the span_limits
Sourcepub fn with_resource(self, resource: Resource) -> Self
pub fn with_resource(self, resource: Resource) -> Self
Associates a Resource with a SdkTracerProvider.
This Resource represents the entity producing telemetry and is associated with all Tracers the SdkTracerProvider will create.
By default, if this option is not used, the default Resource will be used.
When constructing a Resource, use Resource::builder() to preserve
SDK-provided defaults such as telemetry.sdk.* and service.name.
Using Resource::builder_empty() will not include these attributes.
§Example
use opentelemetry_sdk::{Resource, trace::SdkTracerProvider};
use opentelemetry::KeyValue;
let provider = SdkTracerProvider::builder()
.with_resource(
Resource::builder()
.with_service_name("my-service")
.with_attributes([KeyValue::new("deployment.environment.name", "production")])
.build(),
)
.build();Note: Calls to this method are additive, each call merges the provided resource with the previous one.
Sourcepub fn build(self) -> SdkTracerProvider
pub fn build(self) -> SdkTracerProvider
Create a new provider from this configuration.