From 2057dec329dcf75d8ef78d04d23bbddaeb6daf17 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Fri, 27 Dec 2024 23:44:57 +0000 Subject: [PATCH] Avoid vec allocation during export --- opentelemetry-sdk/src/logs/log_processor.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/opentelemetry-sdk/src/logs/log_processor.rs b/opentelemetry-sdk/src/logs/log_processor.rs index e46341eb6d..dad8f2790d 100644 --- a/opentelemetry-sdk/src/logs/log_processor.rs +++ b/opentelemetry-sdk/src/logs/log_processor.rs @@ -422,7 +422,7 @@ impl BatchLogProcessor { let _ = export_with_timeout_sync( config.max_export_timeout, &mut exporter, - logs.split_off(0), + &mut logs, &mut last_export_time, ); } @@ -432,7 +432,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); @@ -442,7 +442,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); @@ -466,7 +466,7 @@ impl BatchLogProcessor { let _ = export_with_timeout_sync( config.max_export_timeout, &mut exporter, - logs.split_off(0), + &mut logs, &mut last_export_time, ); } @@ -515,7 +515,7 @@ impl BatchLogProcessor { fn export_with_timeout_sync( _: Duration, // TODO, enforcing timeout in exporter. exporter: &mut E, - batch: Vec>, + batch: &mut Vec>, last_export_time: &mut Instant, ) -> ExportResult where @@ -531,9 +531,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) => {