Skip to content

Commit

Permalink
feat: add batch config for opentelemetry otlp pipeline (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengxilong committed Mar 14, 2023
1 parent 0d666d4 commit 6e472f8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions opentelemetry-otlp/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl OtlpPipeline {
pub struct OtlpTracePipeline {
exporter_builder: Option<SpanExporterBuilder>,
trace_config: Option<sdk::trace::Config>,
batch_config: Option<sdk::trace::BatchConfig>,
}

impl OtlpTracePipeline {
Expand All @@ -99,6 +100,12 @@ impl OtlpTracePipeline {
self
}

/// Set the batch span processor configuration, and it will override the env vars.
pub fn with_batch_config(mut self, batch_config: sdk::trace::BatchConfig) -> Self {
self.batch_config = Some(batch_config);
self
}

/// Set the OTLP span exporter builder.
///
/// Note that the pipeline will not build the exporter until [`install_batch`] or [`install_simple`]
Expand Down Expand Up @@ -143,6 +150,7 @@ impl OtlpTracePipeline {
.build_span_exporter()?,
self.trace_config,
runtime,
self.batch_config,
))
}
}
Expand All @@ -166,9 +174,14 @@ fn build_batch_with_exporter<R: TraceRuntime>(
exporter: SpanExporter,
trace_config: Option<sdk::trace::Config>,
runtime: R,
batch_config: Option<sdk::trace::BatchConfig>,
) -> sdk::trace::Tracer {
let mut provider_builder =
sdk::trace::TracerProvider::builder().with_batch_exporter(exporter, runtime);
let mut provider_builder = sdk::trace::TracerProvider::builder();
let batch_processor = sdk::trace::BatchSpanProcessor::builder(exporter, runtime)
.with_batch_config(batch_config.unwrap_or_default())
.build();
provider_builder = provider_builder.with_span_processor(batch_processor);

if let Some(config) = trace_config {
provider_builder = provider_builder.with_config(config);
}
Expand Down

0 comments on commit 6e472f8

Please sign in to comment.