Skip to content

Commit c590dc8

Browse files
add shutdown with timeout for log exporter
1 parent bc82d4f commit c590dc8

File tree

13 files changed

+45
-16
lines changed

13 files changed

+45
-16
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::time;
12
use super::OtlpHttpClient;
23
use http::{header::CONTENT_TYPE, Method};
34
use opentelemetry::otel_debug;
@@ -46,7 +47,7 @@ impl LogExporter for OtlpHttpClient {
4647
Ok(())
4748
}
4849

49-
fn shutdown(&self) -> OTelSdkResult {
50+
fn shutdown_with_timeout(&self, _timeout: time::Duration) -> OTelSdkResult {
5051
let mut client_guard = self.client.lock().map_err(|e| {
5152
OTelSdkError::InternalFailure(format!("Failed to acquire client lock: {}", e))
5253
})?;
@@ -58,6 +59,10 @@ impl LogExporter for OtlpHttpClient {
5859
Ok(())
5960
}
6061

62+
fn shutdown(&self) -> OTelSdkResult {
63+
self.shutdown_with_timeout(time::Duration::from_secs(5))
64+
}
65+
6166
fn set_resource(&mut self, resource: &opentelemetry_sdk::Resource) {
6267
self.resource = resource.into();
6368
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::fmt;
2+
use std::time;
23
use opentelemetry::otel_debug;
34
use opentelemetry_proto::tonic::collector::logs::v1::{
45
logs_service_client::LogsServiceClient, ExportLogsServiceRequest,
@@ -84,7 +85,7 @@ impl LogExporter for TonicLogsClient {
8485
Ok(())
8586
}
8687

87-
fn shutdown(&self) -> OTelSdkResult {
88+
fn shutdown_with_timeout(&self, _timeout: time::Duration) -> OTelSdkResult {
8889
// TODO: Implement actual shutdown
8990
// Due to the use of tokio::sync::Mutex to guard
9091
// the inner client, we need to await the call to lock the mutex

opentelemetry-otlp/src/logs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#[cfg(feature = "grpc-tonic")]
66
use opentelemetry::otel_debug;
77
use std::fmt::Debug;
8-
8+
use std::time;
99
use opentelemetry_sdk::{error::OTelSdkResult, logs::LogBatch};
1010

1111
use crate::{ExporterBuildError, HasExportConfig, NoExporterBuilderSet};
@@ -157,7 +157,7 @@ impl opentelemetry_sdk::logs::LogExporter for LogExporter {
157157
}
158158
}
159159

160-
fn shutdown(&self) -> OTelSdkResult {
160+
fn shutdown_with_timeout(&self, _timeout: time::Duration) -> OTelSdkResult {
161161
match &self.client {
162162
#[cfg(feature = "grpc-tonic")]
163163
SupportedTransportClient::Tonic(client) => client.shutdown(),

opentelemetry-sdk/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ also modified to suppress telemetry before invoking exporters.
2424
- *Breaking* change for custom `MetricReader` authors.
2525
The `shutdown_with_timeout` method is added to `MetricReader` trait.
2626
`collect` method on `MetricReader` modified to return `OTelSdkResult`.
27-
27+
- *Breaking* The `shutdown_with_timeout` method is added to LogExporter trait. This is breaking change for custom `LogExporter` authors.
28+
-
2829
## 0.29.0
2930

3031
Released 2025-Mar-21

opentelemetry-sdk/benches/log_enabled.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
// cargo bench --bench log_enabled --features="spec_unstable_logs_enabled,experimental_logs_concurrent_log_processor"
1313

14+
use std::time;
1415
use criterion::{criterion_group, criterion_main, Criterion};
1516
use opentelemetry::logs::{Logger, LoggerProvider};
1617
use opentelemetry_sdk::error::OTelSdkResult;
@@ -29,7 +30,7 @@ impl LogExporter for NoopExporter {
2930
Ok(())
3031
}
3132

32-
fn shutdown(&self) -> OTelSdkResult {
33+
fn shutdown_with_timeout(&self, _timeout: time::Duration) -> OTelSdkResult {
3334
Ok(())
3435
}
3536

opentelemetry-sdk/src/logs/export.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::Resource;
66
use opentelemetry::logs::Severity;
77
use opentelemetry::InstrumentationScope;
88
use std::fmt::Debug;
9+
use std::time;
910

1011
/// A batch of log records to be exported by a `LogExporter`.
1112
///
@@ -134,10 +135,11 @@ pub trait LogExporter: Send + Sync + Debug {
134135
&self,
135136
batch: LogBatch<'_>,
136137
) -> impl std::future::Future<Output = OTelSdkResult> + Send;
137-
138138
/// Shuts down the exporter.
139+
fn shutdown_with_timeout(&self, _timeout: time::Duration) -> OTelSdkResult;
140+
/// Shuts down the exporter with a default timeout.
139141
fn shutdown(&self) -> OTelSdkResult {
140-
Ok(())
142+
self.shutdown_with_timeout(time::Duration::from_secs(5))
141143
}
142144
#[cfg(feature = "spec_unstable_logs_enabled")]
143145
/// Check if logs are enabled.

opentelemetry-sdk/src/logs/in_memory_exporter.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use opentelemetry::InstrumentationScope;
77
use std::borrow::Cow;
88
use std::sync::atomic::AtomicBool;
99
use std::sync::{Arc, Mutex};
10+
use std::time;
1011

1112
/// An in-memory logs exporter that stores logs data in memory..
1213
///
@@ -205,7 +206,7 @@ impl LogExporter for InMemoryLogExporter {
205206
Ok(())
206207
}
207208

208-
fn shutdown(&self) -> OTelSdkResult {
209+
fn shutdown_with_timeout(&self, _timeout: time::Duration) -> OTelSdkResult {
209210
self.shutdown_called
210211
.store(true, std::sync::atomic::Ordering::Relaxed);
211212
if self.should_reset_on_shutdown {
@@ -214,6 +215,11 @@ impl LogExporter for InMemoryLogExporter {
214215
Ok(())
215216
}
216217

218+
fn shutdown(&self) -> OTelSdkResult {
219+
self.shutdown_with_timeout(time::Duration::from_secs(5))
220+
}
221+
222+
217223
fn set_resource(&mut self, resource: &Resource) {
218224
let mut res_guard = self.resource.lock().expect("Resource lock poisoned");
219225
*res_guard = resource.clone();

opentelemetry-sdk/src/logs/log_processor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub(crate) mod tests {
8181
use opentelemetry::logs::{Logger, LoggerProvider};
8282
use opentelemetry::{InstrumentationScope, Key};
8383
use std::sync::{Arc, Mutex};
84+
use std::time;
8485

8586
#[derive(Debug, Clone)]
8687
pub(crate) struct MockLogExporter {
@@ -92,7 +93,7 @@ pub(crate) mod tests {
9293
Ok(())
9394
}
9495

95-
fn shutdown(&self) -> OTelSdkResult {
96+
fn shutdown_with_timeout(&self, _timeout: time::Duration)-> OTelSdkResult {
9697
Ok(())
9798
}
9899

opentelemetry-sdk/src/logs/log_processor_with_async_runtime.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ mod tests {
309309
use opentelemetry::KeyValue;
310310
use opentelemetry::{InstrumentationScope, Key};
311311
use std::sync::{Arc, Mutex};
312+
use std::time;
312313
use std::time::Duration;
313314

314315
#[derive(Debug, Clone)]
@@ -321,10 +322,14 @@ mod tests {
321322
Ok(())
322323
}
323324

324-
fn shutdown(&self) -> OTelSdkResult {
325+
fn shutdown_with_timeout(&self, _timeout: time::Duration) -> OTelSdkResult {
325326
Ok(())
326327
}
327328

329+
fn shutdown(&self) -> OTelSdkResult {
330+
self.shutdown_with_timeout(time::Duration::from_secs(5))
331+
}
332+
328333
fn set_resource(&mut self, resource: &Resource) {
329334
self.resource
330335
.lock()

opentelemetry-sdk/src/logs/logger_provider.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ mod tests {
291291
use std::fmt::{Debug, Formatter};
292292
use std::sync::atomic::AtomicU64;
293293
use std::sync::Mutex;
294-
use std::thread;
294+
use std::{thread, time};
295295

296296
struct ShutdownTestLogProcessor {
297297
is_shutdown: Arc<Mutex<bool>>,
@@ -364,7 +364,7 @@ mod tests {
364364
*res = resource.clone();
365365
}
366366

367-
fn shutdown(&self) -> OTelSdkResult {
367+
fn shutdown_with_timeout(&self, _timeout: time::Duration)-> OTelSdkResult {
368368
Ok(())
369369
}
370370
}

0 commit comments

Comments
 (0)