-
Notifications
You must be signed in to change notification settings - Fork 450
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
Use native Rust support for async traits in LogExporter::export() method #2374
base: main
Are you sure you want to change the base?
Conversation
@@ -82,7 +80,11 @@ pub trait LogExporter: Send + Sync + Debug { | |||
/// A `LogResult<()>`, which is a result type indicating either a successful export (with | |||
/// `Ok(())`) or an error (`Err(LogError)`) if the export operation failed. | |||
/// | |||
async fn export(&mut self, batch: LogBatch<'_>) -> LogResult<()>; | |||
fn export<'a>( | |||
&'a mut self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lalitb I think it maybe better to first check how to avoid requiring mut
reference for exporting, before evaluating the results of this perf test, as that requirement has forced the need of mutex and introduced contention and hence stress tests shows way low throughput than before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cijothomas If we remove the mut
self-reference from the LogExporter::export()
method, it will force the exporter implementation to rely on interior mutability to modify its internal state. This would involve using synchronization mechanisms like locks or atomic operations, which add complexity and overhead. But in the case of SimpleLogProcessor
and BatchLogProcessor
, these methods are always called sequentially, so there’s no real benefit to introducing this extra layer of synchronization. It would just make the code more complicated and less performant without actually solving any problem.
The use-case for having a non-mutating export method would be in reentrant log processors, where LogProcessor::emit() -> LogProcessor::export()
could be invoked concurrently from multiple user threads. In such scenarios, interior mutability would be necessary if the exporter implementation needs to manage internal state. However, this is not relevant for the current simple and batch processors, which operate in a strictly sequential manner.
Actually, there are 4 different exporter scenarios to think about -
- sync/concurrent:
fn export<'a>(&'a self, batch: &'a LogBatch<'a>) -> LogResult<()>;
- sync/sequential,
fn export<'a>(&'a mut self, batch: &'a LogBatch<'a>) -> LogResult<()>;
- async/concurrent
fn export<'a>(&'a self, batch: &'a LogBatch<'a>) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a;
- async/sequential
fn export<'a>(&'a mut self, batch: &'a LogBatch<'a>) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a;
Currently:
- The
SimpleLogProcessor
andBatchLogProcessor
invoke the exporter inasync/sequential
mode. - The
ReentrantProcessor
, used by ETW and user_events in the contrib repository, operates the exporter insync/concurrent
mode.
To ensure clarity and extensibility, we need to properly model these scenarios within the design.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to add, we don't currently have specific use-case for sync/sequential
, and async/concurrent
, they are mentioned above for completeness of all the scenarios.
@@ -247,11 +247,16 @@ mod tests { | |||
|
|||
#[async_trait] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need async-trait anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this can be safely removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unresolving to remove async_trait
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2374 +/- ##
=======================================
- Coverage 79.4% 79.3% -0.2%
=======================================
Files 122 122
Lines 21708 21736 +28
=======================================
- Hits 17255 17250 -5
- Misses 4453 4486 +33 ☔ View full report in Codecov by Sentry. |
OK, have updated this PR after removing the Before this PR (the regression introduced by #2380 because of inclusion of exporter ~44 -> ~40):
After this PR:
The cons of introducing the native-async in trait would be
Current export method could be simplified a bit for lifetime specifiers. I will look into that. But in general, open for discussion if we should bump the msrv. |
Based on today's SIG discussion: Awaiting more feedback. |
This is ready for review now, with #2417 to bump msrv is merged |
@@ -34,8 +34,12 @@ struct NoopExporter { | |||
|
|||
#[async_trait] | |||
impl LogExporter for NoopExporter { | |||
async fn export(&self, _: LogBatch<'_>) -> LogResult<()> { | |||
LogResult::Ok(()) | |||
#[allow(clippy::manual_async_fn)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This annotation is required for false positive clippy warning - rust-lang/rust-clippy#12664
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe have it on the project level until #12664 is addressed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding #[allow(clippy::manual_async_fn)]
at the package level in Cargo.toml
is not supported—it only works as an attribute in Rust source files. To suppress this lint effectively, it needs to be added in lib.rs
or mod.rs
for the main crate and separately for benches
(and likely tests
as well). It seems, adding at method level seems cleaner as of now. We can revisit this if similar implementation is done for Spans, and the issue is not fixed by then.
@@ -58,35 +58,40 @@ impl TonicLogsClient { | |||
|
|||
#[async_trait] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove async_trait from everywhere now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done, thanks.
opentelemetry-otlp/src/logs.rs
Outdated
@@ -108,7 +108,16 @@ impl HasHttpConfig for LogExporterBuilder<HttpExporterBuilderSet> { | |||
/// OTLP exporter that sends log data | |||
#[derive(Debug)] | |||
pub struct LogExporter { | |||
client: Box<dyn opentelemetry_sdk::export::logs::LogExporter>, | |||
//client: Box<dyn opentelemetry_sdk::export::logs::LogExporter>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove this now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, removed. thanks
opentelemetry-otlp/src/logs.rs
Outdated
} | ||
|
||
#[derive(Debug)] | ||
enum LogExporterInner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name can be better IMO. Maybe SupportedTransportClient
. Inner
just don't convey this is a enum clearly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocking issue though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Have renamed it to SupportedTransportClient
.
Changes
Continuation to #2143, more to show feasibility, performance improvements, and have discussion before raising the PR for eventual review, this PR demonstrate using async traits support in Rust exporter. The support was added in Rust v1.75, while the msrv as of now is v1.70 for otel-sdk
The change is:
Existing:
PR:
Have modified the stress test to use LogExporter to demonstrate the improvement:
main with modified stress test:
main...lalitb:opentelemetry-rust:main-stress-with-exporter
6,348,766 iterations/sec
5,725,142 iterations/sec
6,020,324 iterations/sec
5,814,542 iterations/sec
this PR with modified stress test:
9,550,832 iterations/sec
11,045,635 iterations/sec
10,632,124 iterations/sec
10,212,681 iterations/sec
9,810,356 iterations/sec
There are improvements of ~71%, but it need to bump msrv to 1.75. Also, most of the improvement won't be the periodic
Thanks,
Lalit
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes