Skip to content

Commit 6ef5850

Browse files
committed
Address PR comments
1 parent 9708e12 commit 6ef5850

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

opentelemetry-otlp/examples/basic-otlp-http/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
8787
"Init metrics failed with error: {:?}",
8888
result.err()
8989
);
90-
90+
9191
// 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.
9292
let logger_provider = init_logs().unwrap();
9393

opentelemetry-prometheus/tests/integration_test.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,20 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &'
406406
let metric_families = registry.gather();
407407
encoder.encode(&metric_families, &mut output).unwrap();
408408

409-
let output_string = if cfg!(windows) {
410-
String::from_utf8(output).unwrap().replace('\n', "\r\n")
411-
} else {
412-
String::from_utf8(output).unwrap()
413-
};
409+
let output_string = get_platform_specific_string(String::from_utf8(output).unwrap());
414410

415411
assert_eq!(output_string, expected, "{name}");
416412
}
417413

414+
/// Returns a String which uses the platform specific new line feed character.
415+
fn get_platform_specific_string(input: String) -> String {
416+
if cfg!(windows) {
417+
input.replace('\n', "\r\n")
418+
} else {
419+
input
420+
}
421+
}
422+
418423
#[test]
419424
fn multiple_scopes() {
420425
let registry = prometheus::Registry::new();
@@ -822,11 +827,7 @@ fn gather_and_compare_multi(
822827
let metric_families = registry.gather();
823828
encoder.encode(&metric_families, &mut output).unwrap();
824829

825-
let output_string = if cfg!(windows) {
826-
String::from_utf8(output).unwrap().replace('\n', "\r\n")
827-
} else {
828-
String::from_utf8(output).unwrap()
829-
};
830+
let output_string = get_platform_specific_string(String::from_utf8(output).unwrap());
830831

831832
assert!(
832833
expected.contains(&output_string),

opentelemetry-proto/tests/grpc_build.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,27 @@ fn build_content_map(path: impl AsRef<Path>, normalize_line_feed: bool) -> HashM
109109
.file_name()
110110
.expect("file name should always exist for generated files");
111111

112-
let file_contents = if normalize_line_feed && cfg!(windows) {
113-
std::fs::read_to_string(path.clone())
114-
.expect("cannot read from existing generated file")
115-
.replace('\n', "\r\n")
116-
} else {
117-
std::fs::read_to_string(path.clone())
118-
.expect("cannot read from existing generated file")
119-
};
112+
let mut file_contents = std::fs::read_to_string(path.clone())
113+
.expect("cannot read from existing generated file");
114+
115+
if normalize_line_feed {
116+
file_contents = get_platform_specific_string(file_contents);
117+
}
120118

121119
(file_name.to_string_lossy().to_string(), file_contents)
122120
})
123121
.collect()
124122
}
125123

124+
/// Returns a String with the platform specific new line feed character.
125+
fn get_platform_specific_string(input: String) -> String {
126+
if cfg!(windows) {
127+
input.replace('\n', "\r\n")
128+
} else {
129+
input
130+
}
131+
}
132+
126133
fn ensure_files_are_same(
127134
before_build: HashMap<String, String>,
128135
after_build: HashMap<String, String>,

0 commit comments

Comments
 (0)