Skip to content

Commit

Permalink
Avoid vec allocation during each export for BatchLogProcessor (#2483)
Browse files Browse the repository at this point in the history
Co-authored-by: Cijo Thomas <[email protected]>
  • Loading branch information
utpilla and cijothomas authored Dec 28, 2024
1 parent f3b5fd3 commit 9a8ad95
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions opentelemetry-sdk/src/logs/log_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl BatchLogProcessor {
let _ = export_with_timeout_sync(
config.max_export_timeout,
&mut exporter,
logs.split_off(0),
&mut logs,
&mut last_export_time,
);
}
Expand All @@ -429,7 +429,7 @@ impl BatchLogProcessor {
let result = export_with_timeout_sync(
config.max_export_timeout,
&mut exporter,
logs.split_off(0),
&mut logs,
&mut last_export_time,
);
let _ = sender.send(result);
Expand All @@ -439,7 +439,7 @@ impl BatchLogProcessor {
let result = export_with_timeout_sync(
config.max_export_timeout,
&mut exporter,
logs.split_off(0),
&mut logs,
&mut last_export_time,
);
let _ = sender.send(result);
Expand All @@ -463,7 +463,7 @@ impl BatchLogProcessor {
let _ = export_with_timeout_sync(
config.max_export_timeout,
&mut exporter,
logs.split_off(0),
&mut logs,
&mut last_export_time,
);
}
Expand Down Expand Up @@ -512,7 +512,7 @@ impl BatchLogProcessor {
fn export_with_timeout_sync<E>(
_: Duration, // TODO, enforcing timeout in exporter.
exporter: &mut E,
batch: Vec<Box<(LogRecord, InstrumentationScope)>>,
batch: &mut Vec<Box<(LogRecord, InstrumentationScope)>>,
last_export_time: &mut Instant,
) -> ExportResult
where
Expand All @@ -528,9 +528,13 @@ where
.iter()
.map(|log_data| (&log_data.0, &log_data.1))
.collect();

let export = exporter.export(LogBatch::new(log_vec.as_slice()));
let export_result = futures_executor::block_on(export);

// Clear the batch vec after exporting
batch.clear();

match export_result {
Ok(_) => LogResult::Ok(()),
Err(err) => {
Expand Down

0 comments on commit 9a8ad95

Please sign in to comment.