Skip to content

Commit c54d2b8

Browse files
authored
fix: make shutdown_with_timeout required on LogProcessor (#3133)
1 parent f70afa2 commit c54d2b8

File tree

14 files changed

+68
-14
lines changed

14 files changed

+68
-14
lines changed

examples/tracing-http-propagator/src/server.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ impl LogProcessor for EnrichWithBaggageLogProcessor {
121121
fn force_flush(&self) -> OTelSdkResult {
122122
Ok(())
123123
}
124+
125+
fn shutdown_with_timeout(&self, _timeout: Duration) -> OTelSdkResult {
126+
Ok(())
127+
}
124128
}
125129

126130
/// A custom span processor that enriches spans with baggage attributes. Baggage

opentelemetry-appender-tracing/benches/log-attributes.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ impl LogProcessor for NoopProcessor {
4343
fn force_flush(&self) -> OTelSdkResult {
4444
Ok(())
4545
}
46+
47+
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
48+
Ok(())
49+
}
4650
}
4751

4852
/// Creates a single benchmark for a specific number of attributes

opentelemetry-appender-tracing/benches/logs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ impl LogProcessor for NoopProcessor {
6262
) -> bool {
6363
self.enabled
6464
}
65+
66+
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
67+
Ok(())
68+
}
6569
}
6670

6771
struct NoOpLogLayer {

opentelemetry-appender-tracing/src/layer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,10 @@ mod tests {
934934
fn force_flush(&self) -> OTelSdkResult {
935935
Ok(())
936936
}
937+
938+
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
939+
Ok(())
940+
}
937941
}
938942

939943
#[cfg(feature = "spec_unstable_logs_enabled")]

opentelemetry-proto/src/transform/logs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ mod tests {
241241
fn force_flush(&self) -> OTelSdkResult {
242242
Ok(())
243243
}
244+
245+
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
246+
Ok(())
247+
}
244248
}
245249

246250
fn create_test_log_data(

opentelemetry-sdk/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Released 2025-Sep-25
2121
The logs functionality now operates independently, while automatic correlation
2222
between logs and traces continues to work when the "trace" feature is
2323
explicitly enabled.
24+
- **Fix**: Fix shutdown of `SimpleLogProcessor` and async `BatchLogProcessor`.
25+
- Default implementation of `LogProcessor::shutdown_with_timeout()` will now warn to encourage users to implement proper shutdown.
2426

2527
## 0.30.0
2628

@@ -43,7 +45,7 @@ also modified to suppress telemetry before invoking exporters.
4345

4446
- **Feature**: Implemented and enabled cardinality capping for Metrics by
4547
default. [#2901](https://github.com/open-telemetry/opentelemetry-rust/pull/2901)
46-
- The default cardinality limit is 2000 and can be customized using Views.
48+
- The default cardinality limit is 2000 and can be customized using Views.
4749
- This feature was previously removed in version 0.28 due to the lack of
4850
configurability but has now been reintroduced with the ability to configure
4951
the limit.
@@ -184,7 +186,7 @@ Released 2025-Mar-21
184186
```
185187

186188
After:
187-
189+
188190
```rust
189191
async fn export(&self, batch: Vec<SpanData>) -> OTelSdkResult
190192
```

opentelemetry-sdk/benches/log.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl LogProcessor for NoopProcessor {
3838
Ok(())
3939
}
4040

41-
fn shutdown(&self) -> OTelSdkResult {
41+
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
4242
Ok(())
4343
}
4444
}

opentelemetry-sdk/benches/log_exporter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl LogProcessor for ExportingProcessorWithFuture {
7373
Ok(())
7474
}
7575

76-
fn shutdown(&self) -> OTelSdkResult {
76+
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
7777
Ok(())
7878
}
7979
}
@@ -104,7 +104,7 @@ impl LogProcessor for ExportingProcessorWithoutFuture {
104104
Ok(())
105105
}
106106

107-
fn shutdown(&self) -> OTelSdkResult {
107+
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
108108
Ok(())
109109
}
110110
}

opentelemetry-sdk/benches/log_processor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl LogProcessor for NoopProcessor {
5454
Ok(())
5555
}
5656

57-
fn shutdown(&self) -> OTelSdkResult {
57+
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
5858
Ok(())
5959
}
6060
}
@@ -71,7 +71,7 @@ impl LogProcessor for CloningProcessor {
7171
Ok(())
7272
}
7373

74-
fn shutdown(&self) -> OTelSdkResult {
74+
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
7575
Ok(())
7676
}
7777
}
@@ -117,7 +117,7 @@ impl LogProcessor for SendToChannelProcessor {
117117
Ok(())
118118
}
119119

120-
fn shutdown(&self) -> OTelSdkResult {
120+
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
121121
Ok(())
122122
}
123123
}

opentelemetry-sdk/src/logs/log_processor.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::{logs::SdkLogRecord, Resource};
3131

3232
#[cfg(feature = "spec_unstable_logs_enabled")]
3333
use opentelemetry::logs::Severity;
34-
use opentelemetry::InstrumentationScope;
34+
use opentelemetry::{otel_warn, InstrumentationScope};
3535

3636
use std::fmt::Debug;
3737
use std::time::Duration;
@@ -57,10 +57,21 @@ pub trait LogProcessor: Send + Sync + Debug {
5757
/// Shuts down the processor.
5858
/// After shutdown returns the log processor should stop processing any logs.
5959
/// It's up to the implementation on when to drop the LogProcessor.
60+
///
61+
/// All implementors should implement this method.
6062
fn shutdown_with_timeout(&self, _timeout: Duration) -> OTelSdkResult {
63+
// It would have been better to make this method required, but that ship
64+
// sailed when the logs API was declared stable.
65+
otel_warn!(
66+
name: "LogProcessor.DefaultShutdownWithTimeout",
67+
message = format!("LogProcessor::shutdown_with_timeout should be implemented by all LogProcessor types")
68+
);
6169
Ok(())
6270
}
6371
/// Shuts down the processor with default timeout.
72+
///
73+
/// Implementors typically do not need to change this method, and can just
74+
/// implement `shutdown_with_timeout`.
6475
fn shutdown(&self) -> OTelSdkResult {
6576
self.shutdown_with_timeout(Duration::from_secs(5))
6677
}
@@ -140,6 +151,10 @@ pub(crate) mod tests {
140151
fn force_flush(&self) -> OTelSdkResult {
141152
Ok(())
142153
}
154+
155+
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
156+
Ok(())
157+
}
143158
}
144159

145160
#[derive(Debug)]
@@ -166,6 +181,10 @@ pub(crate) mod tests {
166181
fn force_flush(&self) -> OTelSdkResult {
167182
Ok(())
168183
}
184+
185+
fn shutdown_with_timeout(&self, _timeout: std::time::Duration) -> OTelSdkResult {
186+
Ok(())
187+
}
169188
}
170189

171190
#[test]

0 commit comments

Comments
 (0)