Skip to content

Commit 1b45663

Browse files
committed
add shutdown in global logger provider
1 parent eace555 commit 1b45663

12 files changed

+43
-23
lines changed

opentelemetry-proto/src/proto/tonic/opentelemetry.proto.collector.logs.v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This file is @generated by prost-build.
12
#[cfg_attr(feature = "with-schemars", derive(schemars::JsonSchema))]
23
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
34
#[cfg_attr(feature = "with-serde", serde(rename_all = "camelCase"))]

opentelemetry-proto/src/proto/tonic/opentelemetry.proto.collector.metrics.v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This file is @generated by prost-build.
12
#[cfg_attr(feature = "with-schemars", derive(schemars::JsonSchema))]
23
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
34
#[cfg_attr(feature = "with-serde", serde(rename_all = "camelCase"))]

opentelemetry-proto/src/proto/tonic/opentelemetry.proto.collector.trace.v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This file is @generated by prost-build.
12
#[cfg_attr(feature = "with-schemars", derive(schemars::JsonSchema))]
23
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
34
#[cfg_attr(feature = "with-serde", serde(rename_all = "camelCase"))]

opentelemetry-proto/src/proto/tonic/opentelemetry.proto.common.v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This file is @generated by prost-build.
12
/// AnyValue is used to represent any type of attribute value. AnyValue may contain a
23
/// primitive value such as a string or integer or it may contain an arbitrary nested
34
/// object containing arrays, key-value lists and primitives.

opentelemetry-proto/src/proto/tonic/opentelemetry.proto.logs.v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This file is @generated by prost-build.
12
/// LogsData represents the logs data that can be stored in a persistent storage,
23
/// OR can be embedded by other protocols that transfer OTLP logs data but do not
34
/// implement the OTLP protocol.

opentelemetry-proto/src/proto/tonic/opentelemetry.proto.metrics.v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This file is @generated by prost-build.
12
/// MetricsData represents the metrics data that can be stored in a persistent
23
/// storage, OR can be embedded by other protocols that transfer OTLP metrics
34
/// data but do not implement the OTLP protocol.

opentelemetry-proto/src/proto/tonic/opentelemetry.proto.resource.v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This file is @generated by prost-build.
12
/// Resource information.
23
#[cfg_attr(feature = "with-schemars", derive(schemars::JsonSchema))]
34
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]

opentelemetry-proto/src/proto/tonic/opentelemetry.proto.trace.v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This file is @generated by prost-build.
12
/// TracesData represents the traces data that can be stored in a persistent storage,
23
/// OR can be embedded by other protocols that transfer OTLP traces data but do
34
/// not implement the OTLP protocol.

opentelemetry-proto/src/proto/tonic/opentelemetry.proto.tracez.v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This file is @generated by prost-build.
12
#[cfg_attr(feature = "with-schemars", derive(schemars::JsonSchema))]
23
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
34
#[cfg_attr(feature = "with-serde", serde(rename_all = "camelCase"))]

opentelemetry-sdk/src/logs/log_emitter.rs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ impl opentelemetry::logs::LoggerProvider for LoggerProvider {
7373
}
7474
Logger::new(library, self.clone())
7575
}
76+
77+
/// Shuts down this `LoggerProvider`
78+
fn shutdown(&self) -> Vec<LogResult<()>> {
79+
// mark itself as already shutdown
80+
self.is_shutdown
81+
.store(true, std::sync::atomic::Ordering::Relaxed);
82+
// propagate the shutdown signal to processors
83+
// it's up to the processor to properly block new logs after shutdown
84+
self.inner
85+
.processors
86+
.iter()
87+
.map(|processor| processor.shutdown())
88+
.collect()
89+
}
7690
}
7791

7892
impl LoggerProvider {
@@ -98,27 +112,6 @@ impl LoggerProvider {
98112
.map(|processor| processor.force_flush())
99113
.collect()
100114
}
101-
102-
/// Shuts down this `LoggerProvider`, panicking on failure.
103-
pub fn shutdown(&mut self) -> Vec<LogResult<()>> {
104-
// mark itself as already shutdown
105-
self.is_shutdown
106-
.store(true, std::sync::atomic::Ordering::Relaxed);
107-
// propagate the shutdown signal to processors
108-
// it's up to the processor to properly block new logs after shutdown
109-
self.inner
110-
.processors
111-
.iter()
112-
.map(|processor| processor.shutdown())
113-
.collect()
114-
}
115-
116-
/// Attempts to shutdown this `LoggerProvider`, succeeding only when
117-
/// all cloned `LoggerProvider` values have been dropped.
118-
// todo: remove this
119-
pub fn try_shutdown(&mut self) -> Option<Vec<LogResult<()>>> {
120-
Some(self.shutdown())
121-
}
122115
}
123116

124117
#[derive(Debug)]
@@ -324,7 +317,7 @@ mod tests {
324317
#[test]
325318
fn shutdown_test() {
326319
let counter = Arc::new(AtomicU64::new(0));
327-
let mut logger_provider = LoggerProvider::builder()
320+
let logger_provider = LoggerProvider::builder()
328321
.with_log_processor(ShutdownTestLogProcessor::new(counter.clone()))
329322
.build();
330323

0 commit comments

Comments
 (0)