Skip to content

fix: Adds shutdown function for spans #2812

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion opentelemetry-otlp/src/exporter/http/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
Ok(())
}

fn shutdown(&mut self) -> OTelSdkResult {
fn shutdown(&self) -> OTelSdkResult {

Check warning on line 64 in opentelemetry-otlp/src/exporter/http/trace.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/exporter/http/trace.rs#L64

Added line #L64 was not covered by tests
let mut client_guard = self.client.lock().map_err(|e| {
OTelSdkError::InternalFailure(format!("Failed to acquire client lock: {}", e))
})?;
Expand Down
16 changes: 11 additions & 5 deletions opentelemetry-otlp/src/exporter/tonic/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,17 @@
Ok(())
}

fn shutdown(&mut self) -> OTelSdkResult {
match self.inner.take() {
Some(_) => Ok(()), // Successfully took `inner`, indicating a successful shutdown.
None => Err(OTelSdkError::AlreadyShutdown), // `inner` was already `None`, meaning it's already shut down.
}
fn shutdown(&self) -> OTelSdkResult {
// ToDo: as part of https://github.com/open-telemetry/opentelemetry-rust/pull/2812
// self is no longer mutable due to trait change for span exporter
// the shutdown for gRPC needs to implemented and tracked in
// https://github.com/open-telemetry/opentelemetry-rust/issues/2777
//
// match self.inner.take() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to make self mutable for this to work, shutdown for tonic needs to be implemented according to #2777

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a TODO here linking to the issue.

// Some(_) => Ok(()), // Successfully took `inner`, indicating a successful shutdown.
// None => Err(OTelSdkError::AlreadyShutdown), // `inner` was already `None`, meaning it's already shut down.
// }
Ok(())

Check warning on line 102 in opentelemetry-otlp/src/exporter/tonic/trace.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/exporter/tonic/trace.rs#L92-L102

Added lines #L92 - L102 were not covered by tests
}

fn set_resource(&mut self, resource: &opentelemetry_sdk::Resource) {
Expand Down
8 changes: 8 additions & 0 deletions opentelemetry-otlp/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,12 @@
SupportedTransportClient::Http(client) => client.set_resource(resource),
}
}
fn shutdown(&self) -> OTelSdkResult {
match &self.client {

Check warning on line 163 in opentelemetry-otlp/src/span.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/span.rs#L162-L163

Added lines #L162 - L163 were not covered by tests
#[cfg(feature = "grpc-tonic")]
SupportedTransportClient::Tonic(client) => client.shutdown(),

Check warning on line 165 in opentelemetry-otlp/src/span.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/span.rs#L165

Added line #L165 was not covered by tests
#[cfg(any(feature = "http-proto", feature = "http-json"))]
SupportedTransportClient::Http(client) => client.shutdown(),

Check warning on line 167 in opentelemetry-otlp/src/span.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/span.rs#L167

Added line #L167 was not covered by tests
}
}

Check warning on line 169 in opentelemetry-otlp/src/span.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-otlp/src/span.rs#L169

Added line #L169 was not covered by tests
}
4 changes: 4 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## vNext

- **Breaking**: [#2779](https://github.com/open-telemetry/opentelemetry-rust/issues/2779) handle
shutdown for span exporter for `http` exporters, shutdown for `grpc` would be added
separately.

## 0.29.0

Released 2025-Mar-21
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/testing/trace/span_exporters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl SpanExporter for TokioSpanExporter {
})
}

fn shutdown(&mut self) -> OTelSdkResult {
fn shutdown(&self) -> OTelSdkResult {
self.tx_shutdown.send(()).map_err(|_| {
OTelSdkError::InternalFailure("Failed to send shutdown signal".to_string())
})
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/trace/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub trait SpanExporter: Send + Sync + Debug {
/// flush the data and the destination is unavailable). SDK authors
/// can decide if they want to make the shutdown timeout
/// configurable.
fn shutdown(&mut self) -> OTelSdkResult {
fn shutdown(&self) -> OTelSdkResult {
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/trace/in_memory_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl SpanExporter for InMemorySpanExporter {
result
}

fn shutdown(&mut self) -> OTelSdkResult {
fn shutdown(&self) -> OTelSdkResult {
self.reset();
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/src/trace/span_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
}

fn shutdown(&self) -> OTelSdkResult {
if let Ok(mut exporter) = self.exporter.lock() {
if let Ok(exporter) = self.exporter.lock() {
exporter.shutdown()
} else {
Err(OTelSdkError::InternalFailure(
Expand Down Expand Up @@ -1089,7 +1089,7 @@
Ok(())
}

fn shutdown(&mut self) -> OTelSdkResult {
fn shutdown(&self) -> OTelSdkResult {

Check warning on line 1092 in opentelemetry-sdk/src/trace/span_processor.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/trace/span_processor.rs#L1092

Added line #L1092 was not covered by tests
Ok(())
}
fn set_resource(&mut self, resource: &Resource) {
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-stdout/src/trace/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
}
}

fn shutdown(&mut self) -> OTelSdkResult {
fn shutdown(&self) -> OTelSdkResult {

Check warning on line 62 in opentelemetry-stdout/src/trace/exporter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-stdout/src/trace/exporter.rs#L62

Added line #L62 was not covered by tests
self.is_shutdown.store(true, Ordering::SeqCst);
Ok(())
}
Expand Down
Loading