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

Use native Rust support for async traits in LogExporter::export() method (11% improvement) #2374

Merged
merged 34 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d454536
initial commit
lalitb Dec 1, 2024
3ed482d
futher changes..
lalitb Dec 1, 2024
a2aa648
changes..
lalitb Dec 2, 2024
8ba1173
initial change
lalitb Dec 2, 2024
37823e7
stdout exporter
lalitb Dec 2, 2024
3b4cd57
update stress
lalitb Dec 2, 2024
858cd87
Merge branch 'main' into log-async-trait-impl
lalitb Dec 3, 2024
e6472bf
Merge branch 'main' into log-async-trait-impl
lalitb Dec 6, 2024
8cacf52
fix otlp
lalitb Dec 6, 2024
dfac978
Merge branch 'main' into log-async-trait-impl
lalitb Dec 13, 2024
f752d50
add comment
lalitb Dec 13, 2024
6ac8aa0
Merge branch 'main' into log-async-trait-impl
cijothomas Dec 13, 2024
4924e3b
Merge branch 'main' into log-async-trait-impl
TommyCpp Dec 13, 2024
8db475c
review comment
lalitb Dec 15, 2024
4a6e36f
Merge branch 'main' into log-async-trait-impl
lalitb Dec 15, 2024
3af54c3
Merge branch 'main' into log-async-trait-impl
lalitb Dec 15, 2024
8c34380
Merge branch 'main' into log-async-trait-impl
lalitb Dec 16, 2024
87c6c9d
Merge branch 'main' into log-async-trait-impl
cijothomas Dec 16, 2024
be7ecec
Merge branch 'main' into log-async-trait-impl
lalitb Dec 17, 2024
5c8c644
Merge branch 'main' into log-async-trait-impl
lalitb Dec 19, 2024
d1f3cbb
resolve conflicts
lalitb Dec 19, 2024
fa11cd7
initial commit
lalitb Dec 19, 2024
67f006a
further conflicts
lalitb Dec 19, 2024
85f653c
remove unwantd comments
lalitb Dec 19, 2024
33b7572
Merge branch 'main' into log-async-trait-impl
cijothomas Dec 19, 2024
0d5a17c
merge conflict
lalitb Dec 19, 2024
e8333f5
Merge branch 'main' into log-async-trait-impl
lalitb Dec 20, 2024
4e4a189
Remove async_trait import and attribute
lalitb Dec 20, 2024
7627224
remove unused crate
lalitb Dec 20, 2024
09f7cb8
Merge branch 'main' into log-async-trait-impl
lalitb Dec 20, 2024
ddb15bf
update export to take batch by value
lalitb Dec 20, 2024
5e025d2
Merge branch 'log-async-trait-impl' of github.com:lalitb/opentelemetr…
lalitb Dec 20, 2024
158e922
remove temporary batch variable
lalitb Dec 20, 2024
36ea18a
keep diff minimal
lalitb Dec 20, 2024
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
15 changes: 10 additions & 5 deletions opentelemetry-appender-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,16 @@ mod tests {

#[async_trait]
lalitb marked this conversation as resolved.
Show resolved Hide resolved
impl LogExporter for ReentrantLogExporter {
async fn export(&mut self, _batch: LogBatch<'_>) -> LogResult<()> {
// This will cause a deadlock as the export itself creates a log
// while still within the lock of the SimpleLogProcessor.
warn!(name: "my-event-name", target: "reentrant", event_id = 20, user_name = "otel", user_email = "[email protected]");
Ok(())
fn export<'a>(
&'a mut self,
_batch: &'a LogBatch<'a>,
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a {
async {
// This will cause a deadlock as the export itself creates a log
// while still within the lock of the SimpleLogProcessor.
warn!(name: "my-event-name", target: "reentrant", event_id = 20, user_name = "otel", user_email = "[email protected]");
Ok(())
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pprof = { version = "0.13", features = ["flamegraph", "criterion"] }
default = ["trace", "metrics", "logs", "internal-logs"]
trace = ["opentelemetry/trace", "rand", "percent-encoding"]
jaeger_remote_sampler = ["trace", "opentelemetry-http", "http", "serde", "serde_json", "url"]
logs = ["opentelemetry/logs", "async-trait", "serde_json"]
logs = ["opentelemetry/logs", "serde_json"]
spec_unstable_logs_enabled = ["logs", "opentelemetry/spec_unstable_logs_enabled"]
metrics = ["opentelemetry/metrics", "glob", "async-trait"]
testing = ["opentelemetry/testing", "trace", "metrics", "logs", "rt-async-std", "rt-tokio", "rt-tokio-current-thread", "tokio/macros", "tokio/rt-multi-thread"]
Expand Down
8 changes: 5 additions & 3 deletions opentelemetry-sdk/src/export/logs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use crate::logs::LogRecord;
use crate::logs::{LogError, LogResult};
use crate::Resource;
use async_trait::async_trait;
#[cfg(feature = "spec_unstable_logs_enabled")]
use opentelemetry::logs::Severity;
use opentelemetry::InstrumentationScope;
Expand Down Expand Up @@ -63,7 +62,6 @@ impl LogBatch<'_> {
}

/// `LogExporter` defines the interface that log exporters should implement.
#[async_trait]
pub trait LogExporter: Send + Sync + Debug {
/// Exports a batch of log records and their associated instrumentation scopes.
///
Expand All @@ -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>(
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
&'a mut self,
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
batch: &'a LogBatch<'a>,
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a;

/// Shuts down the exporter.
fn shutdown(&mut self) {}
#[cfg(feature = "spec_unstable_logs_enabled")]
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/logs/log_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl Builder {
/// The `LogExporter` that this provider should use.
pub fn with_simple_exporter<T: LogExporter + 'static>(self, exporter: T) -> Self {
let mut processors = self.processors;
processors.push(Box::new(SimpleLogProcessor::new(Box::new(exporter))));
processors.push(Box::new(SimpleLogProcessor::new(exporter)));

Builder { processors, ..self }
}
Expand Down
Loading
Loading