Skip to content
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

replace usages of TestSpanExporter with InMemorySpanExporter #1626

Merged
merged 5 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## vNext

- Replace TestExporter with InMemoryExporter [#1624](https://github.com/open-telemetry/opentelemetry-rust/pull/1624)
- Fix SimpleSpanProcessor to be consistent with log counterpart. Also removed
dependency on crossbeam-channel.
[1612](https://github.com/open-telemetry/opentelemetry-rust/pull/1612/files)
Expand Down
31 changes: 20 additions & 11 deletions opentelemetry-sdk/src/trace/span_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ mod tests {
use crate::export::trace::{ExportResult, SpanData, SpanExporter};
use crate::runtime;
use crate::testing::trace::{
new_test_export_span_data, new_tokio_test_exporter, TestSpanExporter,
new_test_export_span_data, new_tokio_test_exporter, InMemorySpanExporterBuilder,
};
use crate::trace::span_processor::{
OTEL_BSP_EXPORT_TIMEOUT_DEFAULT, OTEL_BSP_MAX_EXPORT_BATCH_SIZE_DEFAULT,
Expand All @@ -685,16 +685,17 @@ mod tests {

#[test]
fn simple_span_processor_on_end_calls_export() {
let exporter = TestSpanExporter::new();
let exporter = InMemorySpanExporterBuilder::new().build();
let mut processor = SimpleSpanProcessor::new(Box::new(exporter.clone()));
processor.on_end(new_test_export_span_data());
assert!(exporter.is_export_called());
let span_data = new_test_export_span_data();
processor.on_end(span_data.clone());
assert_eq!(exporter.get_finished_spans().unwrap()[0], span_data);
let _result = processor.shutdown();
}

#[test]
fn simple_span_processor_on_end_skips_export_if_not_sampled() {
let exporter = TestSpanExporter::new();
let exporter = InMemorySpanExporterBuilder::new().build();
let processor = SimpleSpanProcessor::new(Box::new(exporter.clone()));
let unsampled = SpanData {
span_context: SpanContext::empty_context(),
Expand All @@ -712,16 +713,18 @@ mod tests {
instrumentation_lib: Default::default(),
};
processor.on_end(unsampled);
assert!(!exporter.is_export_called());
assert!(exporter.get_finished_spans().unwrap().is_empty());
}

#[test]
fn simple_span_processor_shutdown_calls_shutdown() {
let exporter = TestSpanExporter::new();
let exporter = InMemorySpanExporterBuilder::new().build();
let mut processor = SimpleSpanProcessor::new(Box::new(exporter.clone()));
assert!(!exporter.is_shutdown_called());
let span_data = new_test_export_span_data();
processor.on_end(span_data.clone());
assert_eq!(exporter.get_finished_spans().unwrap()[0], span_data);
Copy link
Member

Choose a reason for hiding this comment

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

nit: we only need to validate that finished spans is not empty before shutdown, and is empty after shutdown, to keep the test very focused on its purpose.

let _result = processor.shutdown();
assert!(exporter.is_shutdown_called());
assert!(exporter.get_finished_spans().unwrap().is_empty());
Copy link
Member

Choose a reason for hiding this comment

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

nit: Add a comment saying, we indirectly test shutdown is called, by asserting that spans are empty in inmemoryexporter.

}

#[test]
Expand Down Expand Up @@ -820,7 +823,10 @@ mod tests {
(OTEL_BSP_EXPORT_TIMEOUT, Some("2046")),
];
temp_env::with_vars(env_vars.clone(), || {
let builder = BatchSpanProcessor::builder(TestSpanExporter::new(), runtime::Tokio);
let builder = BatchSpanProcessor::builder(
InMemorySpanExporterBuilder::new().build(),
runtime::Tokio,
);
// export batch size cannot exceed max queue size
assert_eq!(builder.config.max_export_batch_size, 500);
assert_eq!(
Expand All @@ -840,7 +846,10 @@ mod tests {
env_vars.push((OTEL_BSP_MAX_QUEUE_SIZE, Some("120")));

temp_env::with_vars(env_vars, || {
let builder = BatchSpanProcessor::builder(TestSpanExporter::new(), runtime::Tokio);
let builder = BatchSpanProcessor::builder(
InMemorySpanExporterBuilder::new().build(),
runtime::Tokio,
);
assert_eq!(builder.config.max_export_batch_size, 120);
assert_eq!(builder.config.max_queue_size, 120);
});
Expand Down
Loading