Skip to content

Commit ddb15bf

Browse files
committed
update export to take batch by value
1 parent 7627224 commit ddb15bf

File tree

10 files changed

+52
-55
lines changed

10 files changed

+52
-55
lines changed

opentelemetry-appender-tracing/benches/logs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ struct NoopExporter {
3333

3434
impl LogExporter for NoopExporter {
3535
#[allow(clippy::manual_async_fn)]
36-
fn export<'a>(
37-
&'a self,
38-
_batch: &'a LogBatch<'a>,
39-
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a {
36+
fn export(
37+
&self,
38+
_batch: LogBatch<'_>,
39+
) -> impl std::future::Future<Output = LogResult<()>> + Send {
4040
async { LogResult::Ok(()) }
4141
}
4242

opentelemetry-appender-tracing/src/layer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ mod tests {
246246

247247
impl LogExporter for ReentrantLogExporter {
248248
#[allow(clippy::manual_async_fn)]
249-
fn export<'a>(
250-
&'a self,
251-
_batch: &'a LogBatch<'a>,
252-
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a {
249+
fn export(
250+
&self,
251+
_batch: LogBatch<'_>,
252+
) -> impl std::future::Future<Output = LogResult<()>> + Send {
253253
async {
254254
// This will cause a deadlock as the export itself creates a log
255255
// while still within the lock of the SimpleLogProcessor.

opentelemetry-otlp/src/exporter/http/logs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use super::OtlpHttpClient;
99

1010
impl LogExporter for OtlpHttpClient {
1111
#[allow(clippy::manual_async_fn)]
12-
fn export<'a>(
13-
&'a self,
14-
batch: &'a LogBatch<'a>,
15-
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a {
12+
fn export(
13+
&self,
14+
batch: LogBatch<'_>,
15+
) -> impl std::future::Future<Output = LogResult<()>> + Send {
1616
async move {
1717
let client = self
1818
.client
@@ -23,7 +23,7 @@ impl LogExporter for OtlpHttpClient {
2323
_ => Err(LogError::Other("exporter is already shut down".into())),
2424
})?;
2525

26-
let (body, content_type) = { self.build_logs_export_body(batch)? };
26+
let (body, content_type) = { self.build_logs_export_body(&batch)? };
2727
let mut request = http::Request::builder()
2828
.method(Method::POST)
2929
.uri(&self.collector_endpoint)

opentelemetry-otlp/src/exporter/tonic/logs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ impl TonicLogsClient {
5757

5858
impl LogExporter for TonicLogsClient {
5959
#[allow(clippy::manual_async_fn)]
60-
fn export<'a>(
61-
&'a self,
62-
batch: &'a LogBatch<'a>,
63-
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a {
60+
fn export(
61+
&self,
62+
batch: LogBatch<'_>,
63+
) -> impl std::future::Future<Output = LogResult<()>> + Send {
6464
async move {
6565
let (mut client, metadata, extensions) = match &self.inner {
6666
Some(inner) => {
@@ -76,7 +76,7 @@ impl LogExporter for TonicLogsClient {
7676
None => return Err(LogError::Other("exporter is already shut down".into())),
7777
};
7878

79-
let resource_logs = group_logs_by_resource_and_scope(batch, &self.resource);
79+
let resource_logs = group_logs_by_resource_and_scope(&batch, &self.resource);
8080

8181
otel_debug!(name: "TonicsLogsClient.CallingExport");
8282

opentelemetry-otlp/src/logs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ impl LogExporter {
141141

142142
impl opentelemetry_sdk::export::logs::LogExporter for LogExporter {
143143
#[allow(clippy::manual_async_fn)]
144-
fn export<'a>(
145-
&'a self,
146-
batch: &'a LogBatch<'a>,
147-
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a {
144+
fn export(
145+
&self,
146+
batch: LogBatch<'_>,
147+
) -> impl std::future::Future<Output = LogResult<()>> + Send {
148148
async move {
149149
match &self.client {
150150
#[cfg(feature = "grpc-tonic")]

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,10 @@ pub trait LogExporter: Send + Sync + Debug {
7979
/// A `LogResult<()>`, which is a result type indicating either a successful export (with
8080
/// `Ok(())`) or an error (`Err(LogError)`) if the export operation failed.
8181
///
82-
/// Note:
83-
/// The `Send` bound ensures the future can be safely moved across threads, which is crucial for multi-threaded async runtimes like Tokio.
84-
/// Explicit lifetimes (`'a`) synchronize the lifetimes of `self`, `batch`, and the returned future.
85-
fn export<'a>(
86-
&'a self,
87-
batch: &'a LogBatch<'a>,
88-
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a;
82+
fn export(
83+
&self,
84+
batch: LogBatch<'_>,
85+
) -> impl std::future::Future<Output = LogResult<()>> + Send;
8986

9087
/// Shuts down the exporter.
9188
fn shutdown(&mut self) {}

opentelemetry-sdk/src/logs/log_processor.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<T: LogExporter> LogProcessor for SimpleLogProcessor<T> {
118118
.and_then(|exporter| {
119119
let log_tuple = &[(record as &LogRecord, instrumentation)];
120120
let log_batch = LogBatch::new(log_tuple);
121-
futures_executor::block_on(exporter.export(&log_batch))
121+
futures_executor::block_on(exporter.export(log_batch))
122122
});
123123
// Handle errors with specific static names
124124
match result {
@@ -447,7 +447,7 @@ where
447447
.map(|log_data| (&log_data.0, &log_data.1))
448448
.collect();
449449
let log_batch = LogBatch::new(log_vec.as_slice());
450-
let export = exporter.export(&log_batch);
450+
let export = exporter.export(log_batch);
451451
let export_result = futures_executor::block_on(export);
452452

453453
match export_result {
@@ -717,7 +717,7 @@ where
717717
.map(|log_data| (&log_data.0, &log_data.1))
718718
.collect();
719719
let log_batch = LogBatch::new(log_vec.as_slice());
720-
let export = exporter.export(&log_batch);
720+
let export = exporter.export(log_batch);
721721
let timeout = runtime.delay(time_out);
722722
pin_mut!(export);
723723
pin_mut!(timeout);
@@ -937,10 +937,10 @@ mod tests {
937937

938938
impl LogExporter for MockLogExporter {
939939
#[allow(clippy::manual_async_fn)]
940-
fn export<'a>(
941-
&'a self,
942-
_batch: &'a LogBatch<'a>,
943-
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a {
940+
fn export(
941+
&self,
942+
_batch: LogBatch<'_>,
943+
) -> impl std::future::Future<Output = LogResult<()>> + Send {
944944
async { Ok(()) }
945945
}
946946

@@ -1443,10 +1443,10 @@ mod tests {
14431443

14441444
impl LogExporter for LogExporterThatRequiresTokio {
14451445
#[allow(clippy::manual_async_fn)]
1446-
fn export<'a>(
1447-
&'a self,
1448-
batch: &'a LogBatch<'a>,
1449-
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a {
1446+
fn export(
1447+
&self,
1448+
batch: LogBatch<'_>,
1449+
) -> impl std::future::Future<Output = LogResult<()>> + Send {
14501450
// Simulate minimal dependency on tokio by sleeping asynchronously for a short duration
14511451
async move {
14521452
tokio::time::sleep(Duration::from_millis(50)).await;

opentelemetry-sdk/src/testing/logs/in_memory_exporter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ impl InMemoryLogExporter {
182182

183183
impl LogExporter for InMemoryLogExporter {
184184
#[allow(clippy::manual_async_fn)]
185-
fn export<'a>(
186-
&'a self,
187-
batch: &'a LogBatch<'a>,
188-
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a {
185+
fn export(
186+
&self,
187+
batch: LogBatch<'_>,
188+
) -> impl std::future::Future<Output = LogResult<()>> + Send {
189189
async move {
190190
let mut logs_guard = self.logs.lock().map_err(LogError::from)?;
191191
for (log_record, instrumentation) in batch.iter() {

opentelemetry-stdout/src/logs/exporter.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ impl fmt::Debug for LogExporter {
3232
impl opentelemetry_sdk::export::logs::LogExporter for LogExporter {
3333
/// Export spans to stdout
3434
#[allow(clippy::manual_async_fn)]
35-
fn export<'a>(
36-
&'a self,
37-
batch: &'a LogBatch<'a>,
38-
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a {
35+
fn export(
36+
&self,
37+
batch: LogBatch<'_>,
38+
) -> impl std::future::Future<Output = LogResult<()>> + Send {
3939
async move {
4040
if self.is_shutdown.load(atomic::Ordering::SeqCst) {
4141
Err("exporter is shut down".into())
@@ -46,7 +46,7 @@ impl opentelemetry_sdk::export::logs::LogExporter for LogExporter {
4646
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
4747
.is_err()
4848
{
49-
print_logs(batch);
49+
print_logs(&batch);
5050
} else {
5151
println!("Resource");
5252
if let Some(schema_url) = self.resource.schema_url() {
@@ -55,7 +55,7 @@ impl opentelemetry_sdk::export::logs::LogExporter for LogExporter {
5555
self.resource.iter().for_each(|(k, v)| {
5656
println!("\t -> {}={:?}", k, v);
5757
});
58-
print_logs(batch);
58+
print_logs(&batch);
5959
}
6060

6161
Ok(())

stress/src/logs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ mod throughput;
2323
struct MockLogExporter;
2424

2525
impl LogExporter for MockLogExporter {
26-
fn export<'a>(
27-
&'a self,
28-
_batch: &'a LogBatch<'a>,
29-
) -> impl std::future::Future<Output = LogResult<()>> + Send + 'a {
26+
fn export(
27+
&self,
28+
_batch: LogBatch<'_>,
29+
) -> impl std::future::Future<Output = LogResult<()>> + Send {
3030
async { Ok(()) }
3131
}
3232
}
@@ -40,7 +40,7 @@ impl LogProcessor for MockLogProcessor {
4040
fn emit(&self, record: &mut opentelemetry_sdk::logs::LogRecord, scope: &InstrumentationScope) {
4141
let log_tuple = &[(record as &LogRecord, scope)];
4242
let log_batch = LogBatch::new(log_tuple);
43-
let _ = futures_executor::block_on(self.exporter.export(&log_batch));
43+
let _ = futures_executor::block_on(self.exporter.export(log_batch));
4444
}
4545

4646
fn force_flush(&self) -> LogResult<()> {

0 commit comments

Comments
 (0)