From 0c25a1308981e504ab77d51907425e5d7d611dde Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Thu, 2 May 2024 16:21:30 -0700 Subject: [PATCH 01/13] Update tests --- .../tests/integration_tests.rs | 2 ++ .../tests/integration_test/tests/traces.rs | 2 ++ .../tests/integration_test.rs | 19 +++++++++++++++++-- opentelemetry-proto/tests/grpc_build.rs | 17 +++++++++++++---- .../src/metrics/periodic_reader.rs | 4 +++- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/opentelemetry-otlp/tests/integration_test/tests/integration_tests.rs b/opentelemetry-otlp/tests/integration_test/tests/integration_tests.rs index 5646590c37..0e73d7f040 100644 --- a/opentelemetry-otlp/tests/integration_test/tests/integration_tests.rs +++ b/opentelemetry-otlp/tests/integration_test/tests/integration_tests.rs @@ -1,3 +1,5 @@ +#![cfg(unix)] + use integration_test_runner::images::Collector; use std::fs::File; use std::os::unix::fs::PermissionsExt; diff --git a/opentelemetry-otlp/tests/integration_test/tests/traces.rs b/opentelemetry-otlp/tests/integration_test/tests/traces.rs index c3aece6fcf..45507e5035 100644 --- a/opentelemetry-otlp/tests/integration_test/tests/traces.rs +++ b/opentelemetry-otlp/tests/integration_test/tests/traces.rs @@ -1,3 +1,5 @@ +#![cfg(unix)] + use integration_test_runner::asserter::{read_spans_from_json, TraceAsserter}; use opentelemetry::global; use opentelemetry::global::shutdown_tracer_provider; diff --git a/opentelemetry-prometheus/tests/integration_test.rs b/opentelemetry-prometheus/tests/integration_test.rs index a4797af34c..1615481ae7 100644 --- a/opentelemetry-prometheus/tests/integration_test.rs +++ b/opentelemetry-prometheus/tests/integration_test.rs @@ -405,7 +405,14 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &' let encoder = TextEncoder::new(); let metric_families = registry.gather(); encoder.encode(&metric_families, &mut output).unwrap(); - let output_string = String::from_utf8(output).unwrap(); + let output_string; + + if cfg!(windows) { + output_string = String::from_utf8(output).unwrap().replace("\n", "\r\n"); + } + else { + output_string = String::from_utf8(output).unwrap(); + } assert_eq!(output_string, expected, "{name}"); } @@ -816,7 +823,15 @@ fn gather_and_compare_multi( let encoder = TextEncoder::new(); let metric_families = registry.gather(); encoder.encode(&metric_families, &mut output).unwrap(); - let output_string = String::from_utf8(output).unwrap(); + + let output_string; + + if cfg!(windows) { + output_string = String::from_utf8(output).unwrap().replace("\n", "\r\n"); + } + else { + output_string = String::from_utf8(output).unwrap(); + } assert!( expected.contains(&output_string), diff --git a/opentelemetry-proto/tests/grpc_build.rs b/opentelemetry-proto/tests/grpc_build.rs index 60ab1255d4..30ddbb60a2 100644 --- a/opentelemetry-proto/tests/grpc_build.rs +++ b/opentelemetry-proto/tests/grpc_build.rs @@ -18,7 +18,7 @@ const TONIC_INCLUDES: &[&str] = &["src/proto/opentelemetry-proto", "src/proto"]; #[test] fn build_tonic() { - let before_build = build_content_map(TONIC_OUT_DIR); + let before_build = build_content_map(TONIC_OUT_DIR, false); let out_dir = TempDir::new().expect("failed to create temp dir to store the generated files"); @@ -95,11 +95,11 @@ fn build_tonic() { .compile(TONIC_PROTO_FILES, TONIC_INCLUDES) .expect("cannot compile protobuf using tonic"); - let after_build = build_content_map(out_dir.path()); + let after_build = build_content_map(out_dir.path(), true); ensure_files_are_same(before_build, after_build, TONIC_OUT_DIR); } -fn build_content_map(path: impl AsRef) -> HashMap { +fn build_content_map(path: impl AsRef, normalize_line_feed: bool) -> HashMap { std::fs::read_dir(path) .expect("cannot open dictionary of generated files") .flatten() @@ -108,9 +108,18 @@ fn build_content_map(path: impl AsRef) -> HashMap { let file_name = path .file_name() .expect("file name should always exist for generated files"); + + let file_contents; + if normalize_line_feed && cfg!(windows) { + file_contents = std::fs::read_to_string(path.clone()).expect("cannot read from existing generated file").replace("\n", "\r\n"); + } + else { + file_contents = std::fs::read_to_string(path.clone()).expect("cannot read from existing generated file"); + } + ( file_name.to_string_lossy().to_string(), - std::fs::read_to_string(path).expect("cannot read from existing generated file"), + file_contents, ) }) .collect() diff --git a/opentelemetry-sdk/src/metrics/periodic_reader.rs b/opentelemetry-sdk/src/metrics/periodic_reader.rs index d54c3be27f..983c075013 100644 --- a/opentelemetry-sdk/src/metrics/periodic_reader.rs +++ b/opentelemetry-sdk/src/metrics/periodic_reader.rs @@ -435,9 +435,11 @@ mod tests { }) .expect("callback registration should succeed"); + _ = meter_provider.force_flush(); + // Assert receiver - .recv_timeout(interval * 2) + .try_recv() .expect("message should be available in channel, indicating a collection occurred"); } From 930c3d595b3cbbaaaea45f0ac54c9f0f70057a3f Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Thu, 2 May 2024 17:19:54 -0700 Subject: [PATCH 02/13] Fix lint --- .../tests/integration_test.rs | 6 ++---- opentelemetry-proto/tests/grpc_build.rs | 16 +++++++--------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/opentelemetry-prometheus/tests/integration_test.rs b/opentelemetry-prometheus/tests/integration_test.rs index 1615481ae7..6b836d638f 100644 --- a/opentelemetry-prometheus/tests/integration_test.rs +++ b/opentelemetry-prometheus/tests/integration_test.rs @@ -409,8 +409,7 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &' if cfg!(windows) { output_string = String::from_utf8(output).unwrap().replace("\n", "\r\n"); - } - else { + } else { output_string = String::from_utf8(output).unwrap(); } @@ -828,8 +827,7 @@ fn gather_and_compare_multi( if cfg!(windows) { output_string = String::from_utf8(output).unwrap().replace("\n", "\r\n"); - } - else { + } else { output_string = String::from_utf8(output).unwrap(); } diff --git a/opentelemetry-proto/tests/grpc_build.rs b/opentelemetry-proto/tests/grpc_build.rs index 30ddbb60a2..abd54f37ae 100644 --- a/opentelemetry-proto/tests/grpc_build.rs +++ b/opentelemetry-proto/tests/grpc_build.rs @@ -111,16 +111,14 @@ fn build_content_map(path: impl AsRef, normalize_line_feed: bool) -> HashM let file_contents; if normalize_line_feed && cfg!(windows) { - file_contents = std::fs::read_to_string(path.clone()).expect("cannot read from existing generated file").replace("\n", "\r\n"); + file_contents = std::fs::read_to_string(path.clone()) + .expect("cannot read from existing generated file") + .replace("\n", "\r\n"); + } else { + file_contents = std::fs::read_to_string(path.clone()) + .expect("cannot read from existing generated file"); } - else { - file_contents = std::fs::read_to_string(path.clone()).expect("cannot read from existing generated file"); - } - - ( - file_name.to_string_lossy().to_string(), - file_contents, - ) + (file_name.to_string_lossy().to_string(), file_contents) }) .collect() } From 03e990dd40416cdad6849c9c4313cf7d33e6ddf1 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Thu, 2 May 2024 17:39:55 -0700 Subject: [PATCH 03/13] Fix lint --- .../tests/integration_test.rs | 19 ++++++++----------- opentelemetry-proto/tests/grpc_build.rs | 14 +++++++------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/opentelemetry-prometheus/tests/integration_test.rs b/opentelemetry-prometheus/tests/integration_test.rs index 6b836d638f..07644b1e99 100644 --- a/opentelemetry-prometheus/tests/integration_test.rs +++ b/opentelemetry-prometheus/tests/integration_test.rs @@ -405,13 +405,12 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &' let encoder = TextEncoder::new(); let metric_families = registry.gather(); encoder.encode(&metric_families, &mut output).unwrap(); - let output_string; - if cfg!(windows) { - output_string = String::from_utf8(output).unwrap().replace("\n", "\r\n"); + let output_string =if cfg!(windows) { + String::from_utf8(output).unwrap().replace('\n', "\r\n") } else { - output_string = String::from_utf8(output).unwrap(); - } + String::from_utf8(output).unwrap() + }; assert_eq!(output_string, expected, "{name}"); } @@ -823,13 +822,11 @@ fn gather_and_compare_multi( let metric_families = registry.gather(); encoder.encode(&metric_families, &mut output).unwrap(); - let output_string; - - if cfg!(windows) { - output_string = String::from_utf8(output).unwrap().replace("\n", "\r\n"); + let output_string = if cfg!(windows){ + String::from_utf8(output).unwrap().replace('\n', "\r\n") } else { - output_string = String::from_utf8(output).unwrap(); - } + String::from_utf8(output).unwrap() + }; assert!( expected.contains(&output_string), diff --git a/opentelemetry-proto/tests/grpc_build.rs b/opentelemetry-proto/tests/grpc_build.rs index abd54f37ae..b006895929 100644 --- a/opentelemetry-proto/tests/grpc_build.rs +++ b/opentelemetry-proto/tests/grpc_build.rs @@ -109,15 +109,15 @@ fn build_content_map(path: impl AsRef, normalize_line_feed: bool) -> HashM .file_name() .expect("file name should always exist for generated files"); - let file_contents; - if normalize_line_feed && cfg!(windows) { - file_contents = std::fs::read_to_string(path.clone()) + let file_contents = if normalize_line_feed && cfg!(windows) { + std::fs::read_to_string(path.clone()) .expect("cannot read from existing generated file") - .replace("\n", "\r\n"); + .replace('\n', "\r\n") } else { - file_contents = std::fs::read_to_string(path.clone()) - .expect("cannot read from existing generated file"); - } + std::fs::read_to_string(path.clone()) + .expect("cannot read from existing generated file") + }; + (file_name.to_string_lossy().to_string(), file_contents) }) .collect() From bdbbdb9fdd379356e64bac106057e2c8922d0dfc Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Thu, 2 May 2024 17:41:47 -0700 Subject: [PATCH 04/13] Fix spacing --- opentelemetry-prometheus/tests/integration_test.rs | 2 +- opentelemetry-proto/tests/grpc_build.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-prometheus/tests/integration_test.rs b/opentelemetry-prometheus/tests/integration_test.rs index 07644b1e99..36bf57f8ad 100644 --- a/opentelemetry-prometheus/tests/integration_test.rs +++ b/opentelemetry-prometheus/tests/integration_test.rs @@ -406,7 +406,7 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &' let metric_families = registry.gather(); encoder.encode(&metric_families, &mut output).unwrap(); - let output_string =if cfg!(windows) { + let output_string = if cfg!(windows) { String::from_utf8(output).unwrap().replace('\n', "\r\n") } else { String::from_utf8(output).unwrap() diff --git a/opentelemetry-proto/tests/grpc_build.rs b/opentelemetry-proto/tests/grpc_build.rs index b006895929..77ac847f5f 100644 --- a/opentelemetry-proto/tests/grpc_build.rs +++ b/opentelemetry-proto/tests/grpc_build.rs @@ -109,7 +109,7 @@ fn build_content_map(path: impl AsRef, normalize_line_feed: bool) -> HashM .file_name() .expect("file name should always exist for generated files"); - let file_contents = if normalize_line_feed && cfg!(windows) { + let file_contents = if normalize_line_feed && cfg!(windows) { std::fs::read_to_string(path.clone()) .expect("cannot read from existing generated file") .replace('\n', "\r\n") From e97c6ae667ac62b24f77d9c64c3d35b6bf40c7a2 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Thu, 2 May 2024 17:44:19 -0700 Subject: [PATCH 05/13] Fix spacing --- opentelemetry-prometheus/tests/integration_test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-prometheus/tests/integration_test.rs b/opentelemetry-prometheus/tests/integration_test.rs index 36bf57f8ad..11426c63b9 100644 --- a/opentelemetry-prometheus/tests/integration_test.rs +++ b/opentelemetry-prometheus/tests/integration_test.rs @@ -822,7 +822,7 @@ fn gather_and_compare_multi( let metric_families = registry.gather(); encoder.encode(&metric_families, &mut output).unwrap(); - let output_string = if cfg!(windows){ + let output_string = if cfg!(windows) { String::from_utf8(output).unwrap().replace('\n', "\r\n") } else { String::from_utf8(output).unwrap() From 597b7fd6bb9c7e056dc1a2b575b988565d44ab17 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Thu, 2 May 2024 17:56:01 -0700 Subject: [PATCH 06/13] Fix lint --- opentelemetry-sdk/src/trace/span_processor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/trace/span_processor.rs b/opentelemetry-sdk/src/trace/span_processor.rs index 37f8fff194..c0222803da 100644 --- a/opentelemetry-sdk/src/trace/span_processor.rs +++ b/opentelemetry-sdk/src/trace/span_processor.rs @@ -399,7 +399,7 @@ impl BatchSpanProcessorInternal { }) } - async fn run(mut self, mut messages: impl Stream + Unpin + FusedStream) { + async fn run(mut self, mut messages: impl Unpin + FusedStream) { loop { select! { // FuturesUnordered implements Fuse intelligently such that it From d22f97f47a9b2cccf86d0a682c1d8a4263ab7d90 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Thu, 2 May 2024 17:59:23 -0700 Subject: [PATCH 07/13] Remove unused import --- opentelemetry-sdk/src/trace/span_processor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/trace/span_processor.rs b/opentelemetry-sdk/src/trace/span_processor.rs index c0222803da..1d1b769d7b 100644 --- a/opentelemetry-sdk/src/trace/span_processor.rs +++ b/opentelemetry-sdk/src/trace/span_processor.rs @@ -42,7 +42,7 @@ use futures_util::{ future::{self, BoxFuture, Either}, select, stream::{self, FusedStream, FuturesUnordered}, - Stream, StreamExt as _, + StreamExt as _, }; use opentelemetry::global; use opentelemetry::{ From f9b47f257db77e4c81f4f2e81ca97ffc25100dd4 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Thu, 2 May 2024 18:26:03 -0700 Subject: [PATCH 08/13] Fix lint --- opentelemetry-jaeger/src/exporter/thrift/agent.rs | 2 +- opentelemetry-jaeger/src/exporter/thrift/jaeger.rs | 2 +- opentelemetry-jaeger/src/exporter/thrift/zipkincore.rs | 2 +- opentelemetry-otlp/examples/basic-otlp-http/src/main.rs | 4 ++-- opentelemetry-otlp/examples/basic-otlp/src/main.rs | 4 ++-- opentelemetry-sdk/src/metrics/periodic_reader.rs | 4 ++-- opentelemetry-sdk/src/metrics/pipeline.rs | 6 +++--- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/opentelemetry-jaeger/src/exporter/thrift/agent.rs b/opentelemetry-jaeger/src/exporter/thrift/agent.rs index 1fdfa45c04..06b6fce22d 100644 --- a/opentelemetry-jaeger/src/exporter/thrift/agent.rs +++ b/opentelemetry-jaeger/src/exporter/thrift/agent.rs @@ -3,7 +3,7 @@ #![allow(unused_imports)] #![allow(unused_extern_crates)] -#![cfg_attr(clippy, allow(clippy::too_many_arguments, clippy::type_complexity))] +#![allow(clippy::too_many_arguments, clippy::type_complexity)] #![cfg_attr(rustfmt, rustfmt_skip)] extern crate thrift; diff --git a/opentelemetry-jaeger/src/exporter/thrift/jaeger.rs b/opentelemetry-jaeger/src/exporter/thrift/jaeger.rs index ca5a49ee27..60e21e9e78 100644 --- a/opentelemetry-jaeger/src/exporter/thrift/jaeger.rs +++ b/opentelemetry-jaeger/src/exporter/thrift/jaeger.rs @@ -3,7 +3,7 @@ #![allow(unused_imports)] #![allow(unused_extern_crates)] -#![cfg_attr(clippy, allow(clippy::too_many_arguments, clippy::type_complexity))] +#![allow(clippy::too_many_arguments, clippy::type_complexity)] #![cfg_attr(rustfmt, rustfmt_skip)] extern crate thrift; diff --git a/opentelemetry-jaeger/src/exporter/thrift/zipkincore.rs b/opentelemetry-jaeger/src/exporter/thrift/zipkincore.rs index e9b10cc109..f9d54118db 100644 --- a/opentelemetry-jaeger/src/exporter/thrift/zipkincore.rs +++ b/opentelemetry-jaeger/src/exporter/thrift/zipkincore.rs @@ -3,7 +3,7 @@ #![allow(unused_imports)] #![allow(unused_extern_crates)] -#![cfg_attr(clippy, allow(clippy::too_many_arguments, clippy::type_complexity))] +#![allow(clippy::too_many_arguments, clippy::type_complexity)] #![cfg_attr(rustfmt, rustfmt_skip)] extern crate thrift; diff --git a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs index 91af4715fa..e312367711 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs @@ -74,8 +74,8 @@ static COMMON_ATTRIBUTES: Lazy<[KeyValue; 4]> = Lazy::new(|| { #[tokio::main] async fn main() -> Result<(), Box> { - let _ = init_tracer()?; - let _ = init_metrics()?; + init_tracer()?; + init_metrics()?; // Opentelemetry will not provide a global API to manage the logger provider. Application users must manage the lifecycle of the logger provider on their own. Dropping logger providers will disable log emitting. let logger_provider = init_logs().unwrap(); diff --git a/opentelemetry-otlp/examples/basic-otlp/src/main.rs b/opentelemetry-otlp/examples/basic-otlp/src/main.rs index 02e1cb3449..d25e4c07b5 100644 --- a/opentelemetry-otlp/examples/basic-otlp/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp/src/main.rs @@ -89,8 +89,8 @@ async fn main() -> Result<(), Box> { // By binding the result to an unused variable, the lifetime of the variable // matches the containing block, reporting traces and metrics during the whole // execution. - let _ = init_tracer()?; - let _ = init_metrics()?; + init_tracer()?; + init_metrics()?; // Initialize logs, which sets the global loggerprovider. let logger_provider = init_logs().unwrap(); diff --git a/opentelemetry-sdk/src/metrics/periodic_reader.rs b/opentelemetry-sdk/src/metrics/periodic_reader.rs index 983c075013..954874294a 100644 --- a/opentelemetry-sdk/src/metrics/periodic_reader.rs +++ b/opentelemetry-sdk/src/metrics/periodic_reader.rs @@ -9,7 +9,7 @@ use futures_util::{ future::{self, Either}, pin_mut, stream::{self, FusedStream}, - Stream, StreamExt, + StreamExt, }; use opentelemetry::{ global, @@ -290,7 +290,7 @@ impl PeriodicReaderWorker { true } - async fn run(mut self, mut messages: impl Stream + Unpin + FusedStream) { + async fn run(mut self, mut messages: impl Unpin + FusedStream) { while let Some(message) = messages.next().await { if !self.process_message(message).await { break; diff --git a/opentelemetry-sdk/src/metrics/pipeline.rs b/opentelemetry-sdk/src/metrics/pipeline.rs index b40012729b..cbb942b17e 100644 --- a/opentelemetry-sdk/src/metrics/pipeline.rs +++ b/opentelemetry-sdk/src/metrics/pipeline.rs @@ -165,9 +165,9 @@ impl SdkProducer for Pipeline { // previous aggregation was of a different type prev_agg.data = data; } - prev_agg.name = inst.name.clone(); - prev_agg.description = inst.description.clone(); - prev_agg.unit = inst.unit.clone(); + prev_agg.name.clone_from(&inst.name); + prev_agg.description.clone_from(&inst.description); + prev_agg.unit.clone_from(&inst.unit); } _ => continue, } From 4bdbc332e83e9ea11d22f7a628d204b34d55c2c2 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Fri, 3 May 2024 12:16:35 -0700 Subject: [PATCH 09/13] Address PR comments --- opentelemetry-otlp/examples/basic-otlp/src/main.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/opentelemetry-otlp/examples/basic-otlp/src/main.rs b/opentelemetry-otlp/examples/basic-otlp/src/main.rs index d25e4c07b5..561de3b2d7 100644 --- a/opentelemetry-otlp/examples/basic-otlp/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp/src/main.rs @@ -89,8 +89,12 @@ async fn main() -> Result<(), Box> { // By binding the result to an unused variable, the lifetime of the variable // matches the containing block, reporting traces and metrics during the whole // execution. - init_tracer()?; - init_metrics()?; + + let result = init_tracer(); + assert!(result.is_ok(), "Init tracer failed with error: {:?}", result.err()); + + let result = init_metrics(); + assert!(result.is_ok(), "Init metrics failed with error: {:?}", result.err()); // Initialize logs, which sets the global loggerprovider. let logger_provider = init_logs().unwrap(); From 32126b157f485da82f17743b87f026c9ed7d3eda Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Fri, 3 May 2024 12:21:00 -0700 Subject: [PATCH 10/13] Fix lint --- opentelemetry-otlp/examples/basic-otlp/src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/opentelemetry-otlp/examples/basic-otlp/src/main.rs b/opentelemetry-otlp/examples/basic-otlp/src/main.rs index 561de3b2d7..2f228dcc72 100644 --- a/opentelemetry-otlp/examples/basic-otlp/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp/src/main.rs @@ -91,10 +91,18 @@ async fn main() -> Result<(), Box> { // execution. let result = init_tracer(); - assert!(result.is_ok(), "Init tracer failed with error: {:?}", result.err()); + assert!( + result.is_ok(), + "Init tracer failed with error: {:?}", + result.err() + ); let result = init_metrics(); - assert!(result.is_ok(), "Init metrics failed with error: {:?}", result.err()); + assert!( + result.is_ok(), + "Init metrics failed with error: {:?}", + result.err() + ); // Initialize logs, which sets the global loggerprovider. let logger_provider = init_logs().unwrap(); From cb815915fe3d7a58fadeac5a57f5350f14b67a70 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Sat, 4 May 2024 12:51:54 -0700 Subject: [PATCH 11/13] Fix lint --- .../src/exporter/config/collector/http_client.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/opentelemetry-jaeger/src/exporter/config/collector/http_client.rs b/opentelemetry-jaeger/src/exporter/config/collector/http_client.rs index bcdbc4f20c..02d5219580 100644 --- a/opentelemetry-jaeger/src/exporter/config/collector/http_client.rs +++ b/opentelemetry-jaeger/src/exporter/config/collector/http_client.rs @@ -129,6 +129,7 @@ impl CollectorHttpClient { } #[cfg(test)] +#[allow(dead_code)] pub(crate) mod test_http_client { use async_trait::async_trait; use bytes::Bytes; From 9708e12bd31bdca26a493391d3b9f91a3200480d Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Sat, 4 May 2024 12:56:32 -0700 Subject: [PATCH 12/13] Address PR comments --- .../examples/basic-otlp-http/src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs index e312367711..f2eaa11bef 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs @@ -74,8 +74,20 @@ static COMMON_ATTRIBUTES: Lazy<[KeyValue; 4]> = Lazy::new(|| { #[tokio::main] async fn main() -> Result<(), Box> { - init_tracer()?; - init_metrics()?; + let result = init_tracer(); + assert!( + result.is_ok(), + "Init tracer failed with error: {:?}", + result.err() + ); + + let result = init_metrics(); + assert!( + result.is_ok(), + "Init metrics failed with error: {:?}", + result.err() + ); + // Opentelemetry will not provide a global API to manage the logger provider. Application users must manage the lifecycle of the logger provider on their own. Dropping logger providers will disable log emitting. let logger_provider = init_logs().unwrap(); From 6ef5850bbb8f12c3a12a2800344a71f7d172702e Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Sat, 4 May 2024 13:31:34 -0700 Subject: [PATCH 13/13] Address PR comments --- .../examples/basic-otlp-http/src/main.rs | 2 +- .../tests/integration_test.rs | 21 +++++++++-------- opentelemetry-proto/tests/grpc_build.rs | 23 ++++++++++++------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs index f2eaa11bef..32e50cb4d5 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs @@ -87,7 +87,7 @@ async fn main() -> Result<(), Box> { "Init metrics failed with error: {:?}", result.err() ); - + // Opentelemetry will not provide a global API to manage the logger provider. Application users must manage the lifecycle of the logger provider on their own. Dropping logger providers will disable log emitting. let logger_provider = init_logs().unwrap(); diff --git a/opentelemetry-prometheus/tests/integration_test.rs b/opentelemetry-prometheus/tests/integration_test.rs index 11426c63b9..51aa496b62 100644 --- a/opentelemetry-prometheus/tests/integration_test.rs +++ b/opentelemetry-prometheus/tests/integration_test.rs @@ -406,15 +406,20 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &' let metric_families = registry.gather(); encoder.encode(&metric_families, &mut output).unwrap(); - let output_string = if cfg!(windows) { - String::from_utf8(output).unwrap().replace('\n', "\r\n") - } else { - String::from_utf8(output).unwrap() - }; + let output_string = get_platform_specific_string(String::from_utf8(output).unwrap()); assert_eq!(output_string, expected, "{name}"); } +/// Returns a String which uses the platform specific new line feed character. +fn get_platform_specific_string(input: String) -> String { + if cfg!(windows) { + input.replace('\n', "\r\n") + } else { + input + } +} + #[test] fn multiple_scopes() { let registry = prometheus::Registry::new(); @@ -822,11 +827,7 @@ fn gather_and_compare_multi( let metric_families = registry.gather(); encoder.encode(&metric_families, &mut output).unwrap(); - let output_string = if cfg!(windows) { - String::from_utf8(output).unwrap().replace('\n', "\r\n") - } else { - String::from_utf8(output).unwrap() - }; + let output_string = get_platform_specific_string(String::from_utf8(output).unwrap()); assert!( expected.contains(&output_string), diff --git a/opentelemetry-proto/tests/grpc_build.rs b/opentelemetry-proto/tests/grpc_build.rs index 77ac847f5f..e63fd412ba 100644 --- a/opentelemetry-proto/tests/grpc_build.rs +++ b/opentelemetry-proto/tests/grpc_build.rs @@ -109,20 +109,27 @@ fn build_content_map(path: impl AsRef, normalize_line_feed: bool) -> HashM .file_name() .expect("file name should always exist for generated files"); - let file_contents = if normalize_line_feed && cfg!(windows) { - std::fs::read_to_string(path.clone()) - .expect("cannot read from existing generated file") - .replace('\n', "\r\n") - } else { - std::fs::read_to_string(path.clone()) - .expect("cannot read from existing generated file") - }; + let mut file_contents = std::fs::read_to_string(path.clone()) + .expect("cannot read from existing generated file"); + + if normalize_line_feed { + file_contents = get_platform_specific_string(file_contents); + } (file_name.to_string_lossy().to_string(), file_contents) }) .collect() } +/// Returns a String with the platform specific new line feed character. +fn get_platform_specific_string(input: String) -> String { + if cfg!(windows) { + input.replace('\n', "\r\n") + } else { + input + } +} + fn ensure_files_are_same( before_build: HashMap, after_build: HashMap,