Skip to content

Commit c2dc170

Browse files
authored
Merge branch 'main' into cijothomas/metric-api-instrument-builder-sync
2 parents 5643a93 + a99438a commit c2dc170

File tree

13 files changed

+80
-24
lines changed

13 files changed

+80
-24
lines changed

opentelemetry-jaeger/src/exporter/config/collector/http_client.rs

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl CollectorHttpClient {
129129
}
130130

131131
#[cfg(test)]
132+
#[allow(dead_code)]
132133
pub(crate) mod test_http_client {
133134
use async_trait::async_trait;
134135
use bytes::Bytes;

opentelemetry-jaeger/src/exporter/thrift/agent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#![allow(unused_imports)]
55
#![allow(unused_extern_crates)]
6-
#![cfg_attr(clippy, allow(clippy::too_many_arguments, clippy::type_complexity))]
6+
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
77
#![cfg_attr(rustfmt, rustfmt_skip)]
88

99
extern crate thrift;

opentelemetry-jaeger/src/exporter/thrift/jaeger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#![allow(unused_imports)]
55
#![allow(unused_extern_crates)]
6-
#![cfg_attr(clippy, allow(clippy::too_many_arguments, clippy::type_complexity))]
6+
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
77
#![cfg_attr(rustfmt, rustfmt_skip)]
88

99
extern crate thrift;

opentelemetry-jaeger/src/exporter/thrift/zipkincore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#![allow(unused_imports)]
55
#![allow(unused_extern_crates)]
6-
#![cfg_attr(clippy, allow(clippy::too_many_arguments, clippy::type_complexity))]
6+
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
77
#![cfg_attr(rustfmt, rustfmt_skip)]
88

99
extern crate thrift;

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

+14-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,20 @@ static COMMON_ATTRIBUTES: Lazy<[KeyValue; 4]> = Lazy::new(|| {
7474

7575
#[tokio::main]
7676
async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
77-
let _ = init_tracer()?;
78-
let _ = init_metrics()?;
77+
let result = init_tracer();
78+
assert!(
79+
result.is_ok(),
80+
"Init tracer failed with error: {:?}",
81+
result.err()
82+
);
83+
84+
let result = init_metrics();
85+
assert!(
86+
result.is_ok(),
87+
"Init metrics failed with error: {:?}",
88+
result.err()
89+
);
90+
7991
// 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.
8092
let logger_provider = init_logs().unwrap();
8193

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

+14-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,20 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
8989
// By binding the result to an unused variable, the lifetime of the variable
9090
// matches the containing block, reporting traces and metrics during the whole
9191
// execution.
92-
let _ = init_tracer()?;
93-
let _ = init_metrics()?;
92+
93+
let result = init_tracer();
94+
assert!(
95+
result.is_ok(),
96+
"Init tracer failed with error: {:?}",
97+
result.err()
98+
);
99+
100+
let result = init_metrics();
101+
assert!(
102+
result.is_ok(),
103+
"Init metrics failed with error: {:?}",
104+
result.err()
105+
);
94106

95107
// Initialize logs, which sets the global loggerprovider.
96108
let logger_provider = init_logs().unwrap();

opentelemetry-otlp/tests/integration_test/tests/integration_tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(unix)]
2+
13
use integration_test_runner::images::Collector;
24
use std::fs::File;
35
use std::os::unix::fs::PermissionsExt;

opentelemetry-otlp/tests/integration_test/tests/traces.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(unix)]
2+
13
use integration_test_runner::asserter::{read_spans_from_json, TraceAsserter};
24
use opentelemetry::global;
35
use opentelemetry::global::shutdown_tracer_provider;

opentelemetry-prometheus/tests/integration_test.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,21 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &'
405405
let encoder = TextEncoder::new();
406406
let metric_families = registry.gather();
407407
encoder.encode(&metric_families, &mut output).unwrap();
408-
let output_string = String::from_utf8(output).unwrap();
408+
409+
let output_string = get_platform_specific_string(String::from_utf8(output).unwrap());
409410

410411
assert_eq!(output_string, expected, "{name}");
411412
}
412413

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+
413423
#[test]
414424
fn multiple_scopes() {
415425
let registry = prometheus::Registry::new();
@@ -816,7 +826,8 @@ fn gather_and_compare_multi(
816826
let encoder = TextEncoder::new();
817827
let metric_families = registry.gather();
818828
encoder.encode(&metric_families, &mut output).unwrap();
819-
let output_string = String::from_utf8(output).unwrap();
829+
830+
let output_string = get_platform_specific_string(String::from_utf8(output).unwrap());
820831

821832
assert!(
822833
expected.contains(&output_string),

opentelemetry-proto/tests/grpc_build.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const TONIC_INCLUDES: &[&str] = &["src/proto/opentelemetry-proto", "src/proto"];
1818

1919
#[test]
2020
fn build_tonic() {
21-
let before_build = build_content_map(TONIC_OUT_DIR);
21+
let before_build = build_content_map(TONIC_OUT_DIR, false);
2222

2323
let out_dir = TempDir::new().expect("failed to create temp dir to store the generated files");
2424

@@ -95,11 +95,11 @@ fn build_tonic() {
9595
.compile(TONIC_PROTO_FILES, TONIC_INCLUDES)
9696
.expect("cannot compile protobuf using tonic");
9797

98-
let after_build = build_content_map(out_dir.path());
98+
let after_build = build_content_map(out_dir.path(), true);
9999
ensure_files_are_same(before_build, after_build, TONIC_OUT_DIR);
100100
}
101101

102-
fn build_content_map(path: impl AsRef<Path>) -> HashMap<String, String> {
102+
fn build_content_map(path: impl AsRef<Path>, normalize_line_feed: bool) -> HashMap<String, String> {
103103
std::fs::read_dir(path)
104104
.expect("cannot open dictionary of generated files")
105105
.flatten()
@@ -108,14 +108,28 @@ fn build_content_map(path: impl AsRef<Path>) -> HashMap<String, String> {
108108
let file_name = path
109109
.file_name()
110110
.expect("file name should always exist for generated files");
111-
(
112-
file_name.to_string_lossy().to_string(),
113-
std::fs::read_to_string(path).expect("cannot read from existing generated file"),
114-
)
111+
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+
}
118+
119+
(file_name.to_string_lossy().to_string(), file_contents)
115120
})
116121
.collect()
117122
}
118123

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+
119133
fn ensure_files_are_same(
120134
before_build: HashMap<String, String>,
121135
after_build: HashMap<String, String>,

opentelemetry-sdk/src/metrics/periodic_reader.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use futures_util::{
99
future::{self, Either},
1010
pin_mut,
1111
stream::{self, FusedStream},
12-
Stream, StreamExt,
12+
StreamExt,
1313
};
1414
use opentelemetry::{
1515
global,
@@ -290,7 +290,7 @@ impl<RT: Runtime> PeriodicReaderWorker<RT> {
290290
true
291291
}
292292

293-
async fn run(mut self, mut messages: impl Stream<Item = Message> + Unpin + FusedStream) {
293+
async fn run(mut self, mut messages: impl Unpin + FusedStream<Item = Message>) {
294294
while let Some(message) = messages.next().await {
295295
if !self.process_message(message).await {
296296
break;
@@ -435,9 +435,11 @@ mod tests {
435435
})
436436
.expect("callback registration should succeed");
437437

438+
_ = meter_provider.force_flush();
439+
438440
// Assert
439441
receiver
440-
.recv_timeout(interval * 2)
442+
.try_recv()
441443
.expect("message should be available in channel, indicating a collection occurred");
442444
}
443445

opentelemetry-sdk/src/metrics/pipeline.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ impl SdkProducer for Pipeline {
165165
// previous aggregation was of a different type
166166
prev_agg.data = data;
167167
}
168-
prev_agg.name = inst.name.clone();
169-
prev_agg.description = inst.description.clone();
170-
prev_agg.unit = inst.unit.clone();
168+
prev_agg.name.clone_from(&inst.name);
169+
prev_agg.description.clone_from(&inst.description);
170+
prev_agg.unit.clone_from(&inst.unit);
171171
}
172172
_ => continue,
173173
}

opentelemetry-sdk/src/trace/span_processor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use futures_util::{
4242
future::{self, BoxFuture, Either},
4343
select,
4444
stream::{self, FusedStream, FuturesUnordered},
45-
Stream, StreamExt as _,
45+
StreamExt as _,
4646
};
4747
use opentelemetry::global;
4848
use opentelemetry::{
@@ -399,7 +399,7 @@ impl<R: RuntimeChannel> BatchSpanProcessorInternal<R> {
399399
})
400400
}
401401

402-
async fn run(mut self, mut messages: impl Stream<Item = BatchMessage> + Unpin + FusedStream) {
402+
async fn run(mut self, mut messages: impl Unpin + FusedStream<Item = BatchMessage>) {
403403
loop {
404404
select! {
405405
// FuturesUnordered implements Fuse intelligently such that it

0 commit comments

Comments
 (0)