Skip to content

fix: make shutdown &self in span processor #1836

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

Merged
merged 2 commits into from
May 28, 2024
Merged
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: 2 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
asynchronously, it should clone the log data to ensure it can be safely processed without
lifetime issues.

- **Breaking** [1836](https://github.com/open-telemetry/opentelemetry-rust/pull/1836) `SpanProcessor::shutdown` now takes an immutable reference to self. Any reference can call shutdown on the processor. After the first call to `shutdown` the processor will not process any new spans.
Copy link
Member

Choose a reason for hiding this comment

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

I use Rewrap to keep comments wrapped!


## v0.23.0

- Fix SimpleSpanProcessor to be consistent with log counterpart. Also removed
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/trace/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ mod tests {
}
}

fn shutdown(&mut self) -> TraceResult<()> {
fn shutdown(&self) -> TraceResult<()> {
self.force_flush()
}
}
Expand Down
16 changes: 8 additions & 8 deletions opentelemetry-sdk/src/trace/span_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub trait SpanProcessor: Send + Sync + std::fmt::Debug {
fn force_flush(&self) -> TraceResult<()>;
/// Shuts down the processor. Called when SDK is shut down. This is an
/// opportunity for processors to do any cleanup required.
fn shutdown(&mut self) -> TraceResult<()>;
fn shutdown(&self) -> TraceResult<()>;
}

/// A [SpanProcessor] that passes finished spans to the configured
Expand Down Expand Up @@ -137,7 +137,7 @@ impl SpanProcessor for SimpleSpanProcessor {
Ok(())
}

fn shutdown(&mut self) -> TraceResult<()> {
fn shutdown(&self) -> TraceResult<()> {
if let Ok(mut exporter) = self.exporter.lock() {
exporter.shutdown();
Ok(())
Expand Down Expand Up @@ -249,7 +249,7 @@ impl<R: RuntimeChannel> SpanProcessor for BatchSpanProcessor<R> {
.and_then(|identity| identity)
}

fn shutdown(&mut self) -> TraceResult<()> {
fn shutdown(&self) -> TraceResult<()> {
let (res_sender, res_receiver) = oneshot::channel();
self.message_sender
.try_send(BatchMessage::Shutdown(res_sender))
Expand Down Expand Up @@ -687,7 +687,7 @@ mod tests {
#[test]
fn simple_span_processor_on_end_calls_export() {
let exporter = InMemorySpanExporterBuilder::new().build();
let mut processor = SimpleSpanProcessor::new(Box::new(exporter.clone()));
let processor = SimpleSpanProcessor::new(Box::new(exporter.clone()));
let span_data = new_test_export_span_data();
processor.on_end(span_data.clone());
assert_eq!(exporter.get_finished_spans().unwrap()[0], span_data);
Expand Down Expand Up @@ -720,7 +720,7 @@ mod tests {
#[test]
fn simple_span_processor_shutdown_calls_shutdown() {
let exporter = InMemorySpanExporterBuilder::new().build();
let mut processor = SimpleSpanProcessor::new(Box::new(exporter.clone()));
let processor = SimpleSpanProcessor::new(Box::new(exporter.clone()));
let span_data = new_test_export_span_data();
processor.on_end(span_data.clone());
assert!(!exporter.get_finished_spans().unwrap().is_empty());
Expand Down Expand Up @@ -876,7 +876,7 @@ mod tests {
scheduled_delay: Duration::from_secs(60 * 60 * 24), // set the tick to 24 hours so we know the span must be exported via force_flush
..Default::default()
};
let mut processor =
let processor =
BatchSpanProcessor::new(Box::new(exporter), config, runtime::TokioCurrentThread);
let handle = tokio::spawn(async move {
loop {
Expand Down Expand Up @@ -976,7 +976,7 @@ mod tests {
delay_for: Duration::from_millis(if !time_out { 5 } else { 60 }),
delay_fn: async_std::task::sleep,
};
let mut processor = BatchSpanProcessor::new(Box::new(exporter), config, runtime::AsyncStd);
let processor = BatchSpanProcessor::new(Box::new(exporter), config, runtime::AsyncStd);
processor.on_end(new_test_export_span_data());
let flush_res = processor.force_flush();
if time_out {
Expand All @@ -1000,7 +1000,7 @@ mod tests {
delay_for: Duration::from_millis(if !time_out { 5 } else { 60 }),
delay_fn: tokio::time::sleep,
};
let mut processor =
let processor =
BatchSpanProcessor::new(Box::new(exporter), config, runtime::TokioCurrentThread);
tokio::time::sleep(Duration::from_secs(1)).await; // skip the first
processor.on_end(new_test_export_span_data());
Expand Down
2 changes: 1 addition & 1 deletion stress/src/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl SpanProcessor for NoOpSpanProcessor {
Ok(())
}

fn shutdown(&mut self) -> TraceResult<()> {
fn shutdown(&self) -> TraceResult<()> {
Ok(())
}
}
Expand Down
Loading