Skip to content

Commit 475ab15

Browse files
committed
Loop on channel in background thread
1 parent 4453aa7 commit 475ab15

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

opentelemetry-sdk/src/logs/log_processor.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ impl BatchLogProcessor {
209209
let (sender, receiver) = mpsc::sync_channel(config.max_queue_size);
210210
let handle = thread::spawn(move || {
211211
let mut logs = Vec::new();
212+
logs.reserve(config.max_export_batch_size);
213+
loop {
214+
logs.clear();
212215
match receiver.recv() {
213216
Ok(BatchMessage::ExportLog(data)) => {
214217
logs.push(data);
@@ -229,6 +232,8 @@ impl BatchLogProcessor {
229232
// }
230233
}
231234
Ok(BatchMessage::Shutdown(_sender)) => {
235+
exporter.shutdown();
236+
break;
232237
// let export = exporter.export(batch.into_iter().map(|data| Cow::Owned(*data)).collect());
233238
// let result = futures_executor::block_on(export);
234239
// match sender {
@@ -248,13 +253,14 @@ impl BatchLogProcessor {
248253
}
249254
Err(_) => {}
250255
}
256+
251257
let export = export_with_timeout(config.max_export_timeout, exporter.as_mut(), logs.split_off(0));
252258
let result = futures_executor::block_on(export);
253259
match result {
254260
Ok(_) => {}
255261
Err(err) => global::handle_error(err),
256262
}
257-
});
263+
}});
258264

259265
// Return batch processor with link to worker
260266
BatchLogProcessor { sender, handle: Mutex::new(Some(handle)) }

0 commit comments

Comments
 (0)