Skip to content

Commit 905ffbc

Browse files
committed
Add force_flush to LogExporter
1 parent dd7b531 commit 905ffbc

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

opentelemetry-sdk/src/export/logs/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use crate::logs::LogRecord;
33
use crate::Resource;
44
use async_trait::async_trait;
5+
use futures_util::future::BoxFuture;
56
#[cfg(feature = "logs_level_enabled")]
67
use opentelemetry::logs::Severity;
78
use opentelemetry::logs::{LogError, LogResult};
@@ -91,6 +92,25 @@ pub trait LogExporter: Send + Sync + Debug {
9192
// By default, all logs are enabled
9293
true
9394
}
95+
96+
/// This is a hint to ensure that the export of any Spans the exporter
97+
/// has received prior to the call to this function SHOULD be completed
98+
/// as soon as possible, preferably before returning from this method.
99+
///
100+
/// This function SHOULD provide a way to let the caller know
101+
/// whether it succeeded, failed or timed out.
102+
///
103+
/// This function SHOULD only be called in cases where it is absolutely necessary,
104+
/// such as when using some FaaS providers that may suspend the process after
105+
/// an invocation, but before the exporter exports the completed spans.
106+
///
107+
/// This function SHOULD complete or abort within some timeout. This function can be
108+
/// implemented as a blocking API or an asynchronous API which notifies the caller via
109+
/// a callback or an event. OpenTelemetry client authors can decide if they want to
110+
/// make the flush timeout configurable.
111+
fn force_flush(&mut self) -> BoxFuture<'static, ExportResult> {
112+
Box::pin(async { Ok(()) })
113+
}
94114
/// Set the resource for the exporter.
95115
fn set_resource(&mut self, _resource: &Resource) {}
96116
}

opentelemetry-sdk/src/logs/log_processor.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ impl<R: RuntimeChannel> BatchLogProcessor<R> {
261261
&timeout_runtime,
262262
logs.split_off(0),
263263
)
264-
.await;
264+
.await
265+
.and(exporter.as_mut().force_flush().await);
265266

266267
if let Some(channel) = res_channel {
267268
if let Err(send_error) = channel.send(result) {

0 commit comments

Comments
 (0)