Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add force_flush to LogExporter #2276

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions opentelemetry-sdk/src/export/logs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::logs::LogRecord;
use crate::Resource;
use async_trait::async_trait;
use futures_util::future::BoxFuture;
#[cfg(feature = "logs_level_enabled")]
use opentelemetry::logs::Severity;
use opentelemetry::logs::{LogError, LogResult};
Expand Down Expand Up @@ -91,6 +92,25 @@ pub trait LogExporter: Send + Sync + Debug {
// By default, all logs are enabled
true
}

/// This is a hint to ensure that the export of any Spans the exporter
ThomsonTan marked this conversation as resolved.
Show resolved Hide resolved
/// has received prior to the call to this function SHOULD be completed
/// as soon as possible, preferably before returning from this method.
///
/// This function SHOULD provide a way to let the caller know
/// whether it succeeded, failed or timed out.
///
/// This function SHOULD only be called in cases where it is absolutely necessary,
/// such as when using some FaaS providers that may suspend the process after
/// an invocation, but before the exporter exports the completed spans.
ThomsonTan marked this conversation as resolved.
Show resolved Hide resolved
///
/// This function SHOULD complete or abort within some timeout. This function can be
Copy link
Contributor

@utpilla utpilla Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update the comments here to reflect the actual trait method definition instead of putting the spec guidelines for this method.

We could put something like:

/// This method will block the current thread until all pending log records are exported. If the export was not
/// successful, an error is returned.

/// implemented as a blocking API or an asynchronous API which notifies the caller via
/// a callback or an event. OpenTelemetry client authors can decide if they want to
/// make the flush timeout configurable.
fn force_flush(&mut self) -> BoxFuture<'static, ExportResult> {
ThomsonTan marked this conversation as resolved.
Show resolved Hide resolved
ThomsonTan marked this conversation as resolved.
Show resolved Hide resolved
Box::pin(async { Ok(()) })
}
/// Set the resource for the exporter.
fn set_resource(&mut self, _resource: &Resource) {}
}
Expand Down
3 changes: 2 additions & 1 deletion opentelemetry-sdk/src/logs/log_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@
&timeout_runtime,
logs.split_off(0),
)
.await;
.await

Check warning on line 264 in opentelemetry-sdk/src/logs/log_processor.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/logs/log_processor.rs#L264

Added line #L264 was not covered by tests
.and(exporter.as_mut().force_flush().await);

if let Some(channel) = res_channel {
if let Err(send_error) = channel.send(result) {
Expand Down
Loading