Skip to content

Commit 7c9447f

Browse files
lalitbcijothomas
andauthored
Remove export timeout configuration for BatchLogProcessor. (#2587)
Co-authored-by: Cijo Thomas <cijo.thomas@gmail.com>
1 parent dde68a0 commit 7c9447f

File tree

2 files changed

+55
-16
lines changed

2 files changed

+55
-16
lines changed

opentelemetry-sdk/CHANGELOG.md

+33
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,39 @@ limit.
304304
`opentelemetry_sdk::trace::{InMemorySpanExporter, InMemorySpanExporterBuilder};`
305305
`opentelemetry_sdk::metrics::{InMemoryMetricExporter, InMemoryMetricExporterBuilder};`
306306

307+
- *Breaking*: The `BatchLogProcessor` no longer supports configuration of `max_export_timeout`
308+
or the `OTEL_BLRP_EXPORT_TIMEOUT` environment variable. Timeout handling is now the
309+
responsibility of the exporter.
310+
For example, in the OTLP Logs exporter, the export timeout can be configured using:
311+
- The environment variables `OTEL_EXPORTER_OTLP_TIMEOUT` or `OTEL_EXPORTER_OTLP_LOGS_TIMEOUT`.
312+
- The opentelemetry_otlp API, via `.with_tonic().with_timeout()` or `.with_http().with_timeout()`.
313+
Before:
314+
```rust
315+
let processor = BatchLogProcessor::builder(exporter)
316+
.with_batch_config(
317+
BatchConfigBuilder::default()
318+
.with_max_queue_size(2048)
319+
.with_max_export_batch_size(512)
320+
.with_scheduled_delay(Duration::from_secs(5))
321+
.with_max_export_timeout(Duration::from_secs(30)) // Previously configurable
322+
.build(),
323+
)
324+
.build();
325+
```
326+
327+
After:
328+
```rust
329+
let processor = BatchLogProcessor::builder(exporter)
330+
.with_batch_config(
331+
BatchConfigBuilder::default()
332+
.with_max_queue_size(2048)
333+
.with_max_export_batch_size(512)
334+
.with_scheduled_delay(Duration::from_secs(5)) // No `max_export_timeout`
335+
.build(),
336+
)
337+
.build();
338+
```
339+
307340
## 0.27.1
308341

309342
Released 2024-Nov-27

opentelemetry-sdk/src/logs/log_processor.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ pub(crate) const OTEL_BLRP_SCHEDULE_DELAY: &str = "OTEL_BLRP_SCHEDULE_DELAY";
5757
/// Default delay interval between two consecutive exports.
5858
pub(crate) const OTEL_BLRP_SCHEDULE_DELAY_DEFAULT: u64 = 1_000;
5959
/// Maximum allowed time to export data.
60+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
6061
pub(crate) const OTEL_BLRP_EXPORT_TIMEOUT: &str = "OTEL_BLRP_EXPORT_TIMEOUT";
6162
/// Default maximum allowed time to export data.
63+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
6264
pub(crate) const OTEL_BLRP_EXPORT_TIMEOUT_DEFAULT: u64 = 30_000;
6365
/// Maximum queue size.
6466
pub(crate) const OTEL_BLRP_MAX_QUEUE_SIZE: &str = "OTEL_BLRP_MAX_QUEUE_SIZE";
@@ -229,7 +231,6 @@ type LogsData = Box<(LogRecord, InstrumentationScope)>;
229231
/// - This processor supports the following configurations:
230232
/// - **Queue size**: Maximum number of log records that can be buffered.
231233
/// - **Batch size**: Maximum number of log records to include in a single export.
232-
/// - **Export timeout**: Maximum duration allowed for an export operation.
233234
/// - **Scheduled delay**: Frequency at which the batch is exported.
234235
///
235236
/// When using this processor with the OTLP Exporter, the following exporter
@@ -255,7 +256,6 @@ type LogsData = Box<(LogRecord, InstrumentationScope)>;
255256
/// .with_max_queue_size(2048)
256257
/// .with_max_export_batch_size(512)
257258
/// .with_scheduled_delay(Duration::from_secs(5))
258-
/// .with_max_export_timeout(Duration::from_secs(30))
259259
/// .build(),
260260
/// )
261261
/// .build();
@@ -525,12 +525,7 @@ impl BatchLogProcessor {
525525
let count_of_logs = logs.len(); // Count of logs that will be exported
526526
total_exported_logs += count_of_logs;
527527

528-
result = export_with_timeout_sync(
529-
config.max_export_timeout,
530-
exporter,
531-
logs,
532-
last_export_time,
533-
); // This method clears the logs vec after exporting
528+
result = export_batch_sync(exporter, logs, last_export_time); // This method clears the logs vec after exporting
534529

535530
current_batch_size.fetch_sub(count_of_logs, Ordering::Relaxed);
536531
}
@@ -656,8 +651,7 @@ impl BatchLogProcessor {
656651
}
657652

658653
#[allow(clippy::vec_box)]
659-
fn export_with_timeout_sync<E>(
660-
_: Duration, // TODO, enforcing timeout in exporter.
654+
fn export_batch_sync<E>(
661655
exporter: &E,
662656
batch: &mut Vec<Box<(LogRecord, InstrumentationScope)>>,
663657
last_export_time: &mut Instant,
@@ -733,6 +727,7 @@ pub struct BatchConfig {
733727
pub(crate) max_export_batch_size: usize,
734728

735729
/// The maximum duration to export a batch of data.
730+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
736731
pub(crate) max_export_timeout: Duration,
737732
}
738733

@@ -748,6 +743,7 @@ pub struct BatchConfigBuilder {
748743
max_queue_size: usize,
749744
scheduled_delay: Duration,
750745
max_export_batch_size: usize,
746+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
751747
max_export_timeout: Duration,
752748
}
753749

@@ -764,6 +760,7 @@ impl Default for BatchConfigBuilder {
764760
max_queue_size: OTEL_BLRP_MAX_QUEUE_SIZE_DEFAULT,
765761
scheduled_delay: Duration::from_millis(OTEL_BLRP_SCHEDULE_DELAY_DEFAULT),
766762
max_export_batch_size: OTEL_BLRP_MAX_EXPORT_BATCH_SIZE_DEFAULT,
763+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
767764
max_export_timeout: Duration::from_millis(OTEL_BLRP_EXPORT_TIMEOUT_DEFAULT),
768765
}
769766
.init_from_env_vars()
@@ -791,6 +788,7 @@ impl BatchConfigBuilder {
791788
/// Set max_export_timeout for [`BatchConfigBuilder`].
792789
/// It's the maximum duration to export a batch of data.
793790
/// The default value is 30000 milliseconds.
791+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
794792
pub fn with_max_export_timeout(mut self, max_export_timeout: Duration) -> Self {
795793
self.max_export_timeout = max_export_timeout;
796794
self
@@ -816,6 +814,7 @@ impl BatchConfigBuilder {
816814
BatchConfig {
817815
max_queue_size: self.max_queue_size,
818816
scheduled_delay: self.scheduled_delay,
817+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
819818
max_export_timeout: self.max_export_timeout,
820819
max_export_batch_size,
821820
}
@@ -843,6 +842,7 @@ impl BatchConfigBuilder {
843842
self.scheduled_delay = Duration::from_millis(scheduled_delay);
844843
}
845844

845+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
846846
if let Some(max_export_timeout) = env::var(OTEL_BLRP_EXPORT_TIMEOUT)
847847
.ok()
848848
.and_then(|s| u64::from_str(&s).ok())
@@ -946,6 +946,7 @@ mod tests {
946946
config.scheduled_delay,
947947
Duration::from_millis(OTEL_BLRP_SCHEDULE_DELAY_DEFAULT)
948948
);
949+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
949950
assert_eq!(
950951
config.max_export_timeout,
951952
Duration::from_millis(OTEL_BLRP_EXPORT_TIMEOUT_DEFAULT)
@@ -969,6 +970,7 @@ mod tests {
969970
let config = temp_env::with_vars(env_vars, BatchConfig::default);
970971

971972
assert_eq!(config.scheduled_delay, Duration::from_millis(2000));
973+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
972974
assert_eq!(config.max_export_timeout, Duration::from_millis(60000));
973975
assert_eq!(config.max_queue_size, 4096);
974976
assert_eq!(config.max_export_batch_size, 1024);
@@ -989,6 +991,7 @@ mod tests {
989991
config.scheduled_delay,
990992
Duration::from_millis(OTEL_BLRP_SCHEDULE_DELAY_DEFAULT)
991993
);
994+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
992995
assert_eq!(
993996
config.max_export_timeout,
994997
Duration::from_millis(OTEL_BLRP_EXPORT_TIMEOUT_DEFAULT)
@@ -997,15 +1000,18 @@ mod tests {
9971000

9981001
#[test]
9991002
fn test_batch_config_with_fields() {
1000-
let batch = BatchConfigBuilder::default()
1003+
let batch_builder = BatchConfigBuilder::default()
10011004
.with_max_export_batch_size(1)
10021005
.with_scheduled_delay(Duration::from_millis(2))
1003-
.with_max_export_timeout(Duration::from_millis(3))
1004-
.with_max_queue_size(4)
1005-
.build();
1006+
.with_max_queue_size(4);
1007+
1008+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
1009+
let batch_builder = batch_builder.with_max_export_timeout(Duration::from_millis(3));
1010+
let batch = batch_builder.build();
10061011

10071012
assert_eq!(batch.max_export_batch_size, 1);
10081013
assert_eq!(batch.scheduled_delay, Duration::from_millis(2));
1014+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
10091015
assert_eq!(batch.max_export_timeout, Duration::from_millis(3));
10101016
assert_eq!(batch.max_queue_size, 4);
10111017
}
@@ -1029,6 +1035,8 @@ mod tests {
10291035
builder.config.max_queue_size,
10301036
OTEL_BLRP_MAX_QUEUE_SIZE_DEFAULT
10311037
);
1038+
1039+
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
10321040
assert_eq!(
10331041
builder.config.max_export_timeout,
10341042
Duration::from_millis(2046)
@@ -1049,7 +1057,6 @@ mod tests {
10491057
let expected = BatchConfigBuilder::default()
10501058
.with_max_export_batch_size(1)
10511059
.with_scheduled_delay(Duration::from_millis(2))
1052-
.with_max_export_timeout(Duration::from_millis(3))
10531060
.with_max_queue_size(4)
10541061
.build();
10551062

@@ -1059,7 +1066,6 @@ mod tests {
10591066
let actual = &builder.config;
10601067
assert_eq!(actual.max_export_batch_size, 1);
10611068
assert_eq!(actual.scheduled_delay, Duration::from_millis(2));
1062-
assert_eq!(actual.max_export_timeout, Duration::from_millis(3));
10631069
assert_eq!(actual.max_queue_size, 4);
10641070
}
10651071

0 commit comments

Comments
 (0)