Skip to content

Commit 67e6a71

Browse files
authored
Expose log batchconfig (#1471)
1 parent 27d338d commit 67e6a71

File tree

3 files changed

+321
-9
lines changed

3 files changed

+321
-9
lines changed

opentelemetry-otlp/src/logs.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl OtlpPipeline {
4242
OtlpLogPipeline {
4343
log_config: None,
4444
exporter_builder: NoExporterConfig(()),
45+
batch_config: None,
4546
}
4647
}
4748
}
@@ -124,6 +125,7 @@ impl opentelemetry_sdk::export::logs::LogExporter for LogExporter {
124125
pub struct OtlpLogPipeline<EB> {
125126
exporter_builder: EB,
126127
log_config: Option<opentelemetry_sdk::logs::Config>,
128+
batch_config: Option<opentelemetry_sdk::logs::BatchConfig>,
127129
}
128130

129131
impl<EB> OtlpLogPipeline<EB> {
@@ -132,6 +134,12 @@ impl<EB> OtlpLogPipeline<EB> {
132134
self.log_config = Some(log_config);
133135
self
134136
}
137+
138+
/// Set the batch log processor configuration, and it will override the env vars.
139+
pub fn with_batch_config(mut self, batch_config: opentelemetry_sdk::logs::BatchConfig) -> Self {
140+
self.batch_config = Some(batch_config);
141+
self
142+
}
135143
}
136144

137145
impl OtlpLogPipeline<NoExporterConfig> {
@@ -143,6 +151,7 @@ impl OtlpLogPipeline<NoExporterConfig> {
143151
OtlpLogPipeline {
144152
exporter_builder: pipeline.into(),
145153
log_config: self.log_config,
154+
batch_config: self.batch_config,
146155
}
147156
}
148157
}
@@ -160,7 +169,7 @@ impl OtlpLogPipeline<LogExporterBuilder> {
160169
))
161170
}
162171

163-
/// Install the configured log exporter and a batch span processor using the
172+
/// Install the configured log exporter and a batch log processor using the
164173
/// specified runtime.
165174
///
166175
/// Returns a [`Logger`] with the name `opentelemetry-otlp` and the current crate version.
@@ -174,6 +183,7 @@ impl OtlpLogPipeline<LogExporterBuilder> {
174183
self.exporter_builder.build_log_exporter()?,
175184
self.log_config,
176185
runtime,
186+
self.batch_config,
177187
))
178188
}
179189
}
@@ -202,9 +212,14 @@ fn build_batch_with_exporter<R: RuntimeChannel>(
202212
exporter: LogExporter,
203213
log_config: Option<opentelemetry_sdk::logs::Config>,
204214
runtime: R,
215+
batch_config: Option<opentelemetry_sdk::logs::BatchConfig>,
205216
) -> opentelemetry_sdk::logs::Logger {
206-
let mut provider_builder =
207-
opentelemetry_sdk::logs::LoggerProvider::builder().with_batch_exporter(exporter, runtime);
217+
let mut provider_builder = opentelemetry_sdk::logs::LoggerProvider::builder();
218+
let batch_processor = opentelemetry_sdk::logs::BatchLogProcessor::builder(exporter, runtime)
219+
.with_batch_config(batch_config.unwrap_or_default())
220+
.build();
221+
provider_builder = provider_builder.with_log_processor(batch_processor);
222+
208223
if let Some(config) = log_config {
209224
provider_builder = provider_builder.with_config(config);
210225
}

opentelemetry-sdk/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66

77
- [#1410](https://github.com/open-telemetry/opentelemetry-rust/pull/1410) Add experimental synchronous gauge
8+
- [#1471](https://github.com/open-telemetry/opentelemetry-rust/pull/1471) Configure batch log record processor via [`OTEL_BLRP_*`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#batch-logrecord-processor) environment variables and via `OtlpLogPipeline::with_batch_config`
89

910
### Changed
1011

0 commit comments

Comments
 (0)