Skip to content

Commit 51dda2f

Browse files
test: fix otlp log integration tests failing with some set of features (#2784)
1 parent dac8bd5 commit 51dda2f

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

opentelemetry-otlp/tests/integration_test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ reqwest-client = ["opentelemetry-otlp/reqwest-client", "opentelemetry-otlp/http-
2929
reqwest-blocking-client = ["opentelemetry-otlp/reqwest-blocking-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics", "internal-logs"]
3030
tonic-client = ["opentelemetry-otlp/grpc-tonic", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics", "internal-logs"]
3131
internal-logs = ["opentelemetry-otlp/internal-logs"]
32+
experimental_metadata_attributes = ["opentelemetry-appender-tracing/experimental_metadata_attributes"]
3233

3334
# Keep tonic as the default client
3435
default = ["tonic-client", "internal-logs"]

opentelemetry-otlp/tests/integration_test/src/logs_asserter.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use anyhow::Result;
2-
use opentelemetry_proto::tonic::logs::v1::{LogRecord, LogsData, ResourceLogs};
2+
use opentelemetry_proto::tonic::{
3+
common::v1::KeyValue,
4+
logs::v1::{LogRecord, LogsData, ResourceLogs},
5+
};
36
use std::fs::File;
47

58
// Given two ResourceLogs, assert that they are equal except for the timestamps
@@ -75,8 +78,22 @@ impl PartialEq for LogRecordWrapper {
7578
a.severity_text, b.severity_text,
7679
"severity_text does not match"
7780
);
81+
let a_attrs = a.attributes.clone();
82+
#[cfg(feature = "experimental_metadata_attributes")]
83+
let a_attrs: Vec<_> = a_attrs
84+
.into_iter()
85+
.filter(|KeyValue { key, .. }| !key.as_str().starts_with("code."))
86+
.collect();
87+
88+
let b_attrs = b.attributes.clone();
89+
#[cfg(feature = "experimental_metadata_attributes")]
90+
let b_attrs: Vec<_> = b_attrs
91+
.into_iter()
92+
.filter(|KeyValue { key, .. }| !key.as_str().starts_with("code."))
93+
.collect();
94+
7895
assert_eq!(a.body, b.body, "body does not match");
79-
assert_eq!(a.attributes, b.attributes, "attributes do not match");
96+
assert_eq!(a_attrs, b_attrs, "attributes do not match");
8097
assert_eq!(
8198
a.dropped_attributes_count, b.dropped_attributes_count,
8299
"dropped_attributes_count does not match"

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ mod logtests {
255255
// current thread
256256
#[test]
257257
#[cfg(feature = "reqwest-blocking-client")]
258+
#[cfg(not(feature = "tonic-client"))]
258259
pub fn logs_batch_non_tokio_main_with_init_logs_outside_rt() -> Result<()> {
259260
logs_non_tokio_helper(false, false)
260261
}
@@ -295,7 +296,8 @@ mod logtests {
295296
// Client - Reqwest-blocking
296297
#[test]
297298
#[cfg(feature = "reqwest-blocking-client")]
298-
pub fn logs_simple_non_tokio_main_with_init_logs_outsie_rt_blocking() -> Result<()> {
299+
#[cfg(not(feature = "tonic-client"))]
300+
pub fn logs_simple_non_tokio_main_with_init_logs_outside_rt_blocking() -> Result<()> {
299301
logs_non_tokio_helper(true, false)
300302
}
301303

@@ -309,7 +311,7 @@ mod logtests {
309311
feature = "tonic-client",
310312
feature = "reqwest-client"
311313
))]
312-
pub fn logs_simple_non_tokio_main_with_init_logs_outsie_rt() -> Result<()> {
314+
pub fn logs_simple_non_tokio_main_with_init_logs_outside_rt() -> Result<()> {
313315
logs_non_tokio_helper(true, false)
314316
}
315317

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub async fn test_logs() -> Result<()> {
3737
info!(target: "my-target", "hello from {}. My price is {}.", "banana", 2.99);
3838
}
3939

40-
let _ = logger_provider.shutdown();
40+
logger_provider.shutdown().unwrap();
4141
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
4242
assert_logs_results(test_utils::LOGS_FILE, "expected/logs.json")?;
4343
Ok(())

0 commit comments

Comments
 (0)