Skip to content

Commit

Permalink
Expose log batchconfig (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
CosminLazar committed Jan 22, 2024
1 parent 27d338d commit 67e6a71
Show file tree
Hide file tree
Showing 3 changed files with 321 additions and 9 deletions.
21 changes: 18 additions & 3 deletions opentelemetry-otlp/src/logs.rs
Expand Up @@ -42,6 +42,7 @@ impl OtlpPipeline {
OtlpLogPipeline {
log_config: None,
exporter_builder: NoExporterConfig(()),
batch_config: None,
}
}
}
Expand Down Expand Up @@ -124,6 +125,7 @@ impl opentelemetry_sdk::export::logs::LogExporter for LogExporter {
pub struct OtlpLogPipeline<EB> {
exporter_builder: EB,
log_config: Option<opentelemetry_sdk::logs::Config>,
batch_config: Option<opentelemetry_sdk::logs::BatchConfig>,
}

impl<EB> OtlpLogPipeline<EB> {
Expand All @@ -132,6 +134,12 @@ impl<EB> OtlpLogPipeline<EB> {
self.log_config = Some(log_config);
self
}

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

impl OtlpLogPipeline<NoExporterConfig> {
Expand All @@ -143,6 +151,7 @@ impl OtlpLogPipeline<NoExporterConfig> {
OtlpLogPipeline {
exporter_builder: pipeline.into(),
log_config: self.log_config,
batch_config: self.batch_config,
}
}
}
Expand All @@ -160,7 +169,7 @@ impl OtlpLogPipeline<LogExporterBuilder> {
))
}

/// Install the configured log exporter and a batch span processor using the
/// Install the configured log exporter and a batch log processor using the
/// specified runtime.
///
/// Returns a [`Logger`] with the name `opentelemetry-otlp` and the current crate version.
Expand All @@ -174,6 +183,7 @@ impl OtlpLogPipeline<LogExporterBuilder> {
self.exporter_builder.build_log_exporter()?,
self.log_config,
runtime,
self.batch_config,
))
}
}
Expand Down Expand Up @@ -202,9 +212,14 @@ fn build_batch_with_exporter<R: RuntimeChannel>(
exporter: LogExporter,
log_config: Option<opentelemetry_sdk::logs::Config>,
runtime: R,
batch_config: Option<opentelemetry_sdk::logs::BatchConfig>,
) -> opentelemetry_sdk::logs::Logger {
let mut provider_builder =
opentelemetry_sdk::logs::LoggerProvider::builder().with_batch_exporter(exporter, runtime);
let mut provider_builder = opentelemetry_sdk::logs::LoggerProvider::builder();
let batch_processor = opentelemetry_sdk::logs::BatchLogProcessor::builder(exporter, runtime)
.with_batch_config(batch_config.unwrap_or_default())
.build();
provider_builder = provider_builder.with_log_processor(batch_processor);

if let Some(config) = log_config {
provider_builder = provider_builder.with_config(config);
}
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-sdk/CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
### Added

- [#1410](https://github.com/open-telemetry/opentelemetry-rust/pull/1410) Add experimental synchronous gauge
- [#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`

### Changed

Expand Down

0 comments on commit 67e6a71

Please sign in to comment.