Skip to content

Commit 1da56d4

Browse files
committed
fixes
1 parent 3713f72 commit 1da56d4

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

opentelemetry-sdk/src/metrics/meter_provider.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ impl fmt::Debug for MeterProviderBuilder {
328328
#[cfg(all(test, feature = "testing"))]
329329
mod tests {
330330
use crate::error::OTelSdkError;
331+
use crate::metrics::SdkMeterProvider;
331332
use crate::resource::{
332333
SERVICE_NAME, TELEMETRY_SDK_LANGUAGE, TELEMETRY_SDK_NAME, TELEMETRY_SDK_VERSION,
333334
};
@@ -337,7 +338,6 @@ mod tests {
337338
use opentelemetry::{global, InstrumentationScope};
338339
use opentelemetry::{Key, KeyValue, Value};
339340
use std::env;
340-
use crate::metrics::SdkMeterProvider;
341341

342342
#[test]
343343
fn test_meter_provider_resource() {
@@ -566,14 +566,27 @@ mod tests {
566566
let builder = SdkMeterProvider::builder()
567567
.with_resource(Resource::new(vec![KeyValue::new("key1", "value1")]))
568568
.with_resource(Resource::new(vec![KeyValue::new("key2", "value2")]))
569-
.with_resource(Resource::builder_empty().with_schema_url(vec![], "http://example.com").build())
569+
.with_resource(
570+
Resource::builder_empty()
571+
.with_schema_url(vec![], "http://example.com")
572+
.build(),
573+
)
570574
.with_resource(Resource::new(vec![KeyValue::new("key3", "value3")]));
571575

572576
let resource = builder.resource.unwrap();
573577

574-
assert_eq!(resource.get(&Key::from_static_str("key1")), Some(Value::from("value1")));
575-
assert_eq!(resource.get(&Key::from_static_str("key2")), Some(Value::from("value2")));
576-
assert_eq!(resource.get(&Key::from_static_str("key3")), Some(Value::from("value3")));
578+
assert_eq!(
579+
resource.get(&Key::from_static_str("key1")),
580+
Some(Value::from("value1"))
581+
);
582+
assert_eq!(
583+
resource.get(&Key::from_static_str("key2")),
584+
Some(Value::from("value2"))
585+
);
586+
assert_eq!(
587+
resource.get(&Key::from_static_str("key3")),
588+
Some(Value::from("value3"))
589+
);
577590
assert_eq!(resource.schema_url(), Some("http://example.com"));
578591
}
579592
}

opentelemetry-sdk/src/resource/mod.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -419,18 +419,29 @@ mod tests {
419419
}
420420

421421
#[rstest]
422-
#[case(vec![], vec![KeyValue::new("key", "b")], "http://schema/a", None)]
423-
#[case(vec![KeyValue::new("key", "a")], vec![KeyValue::new("key", "b")], "http://schema/a", Some("http://schema/a"))]
424-
fn merge_resource_with_missing_attribtes(
422+
#[case(vec![], vec![KeyValue::new("key", "b")], Some("http://schema/a"), None, Some("http://schema/a"))]
423+
#[case(vec![KeyValue::new("key", "a")], vec![KeyValue::new("key", "b")], Some("http://schema/a"), None, Some("http://schema/a"))]
424+
#[case(vec![KeyValue::new("key", "a")], vec![KeyValue::new("key", "b")], Some("http://schema/a"), None, Some("http://schema/a"))]
425+
#[case(vec![KeyValue::new("key", "a")], vec![KeyValue::new("key", "b")], Some("http://schema/a"), Some("http://schema/b"), None)]
426+
#[case(vec![KeyValue::new("key", "a")], vec![KeyValue::new("key", "b")], None, Some("http://schema/b"), Some("http://schema/b"))]
427+
fn merge_resource_with_missing_attributes(
425428
#[case] key_values_a: Vec<KeyValue>,
426429
#[case] key_values_b: Vec<KeyValue>,
427-
#[case] schema_url: &'static str,
430+
#[case] schema_url_a: Option<&'static str>,
431+
#[case] schema_url_b: Option<&'static str>,
428432
#[case] expected_schema_url: Option<&'static str>,
429433
) {
430-
let resource = Resource::from_schema_url(key_values_a, schema_url);
431-
let other_resource = Resource::builder_empty()
432-
.with_attributes(key_values_b)
433-
.build();
434+
let resource = match schema_url_a {
435+
Some(schema) => Resource::from_schema_url(key_values_a, schema),
436+
None => Resource::new(key_values_a),
437+
};
438+
439+
let other_resource = match schema_url_b {
440+
Some(schema) => Resource::builder_empty()
441+
.with_schema_url(key_values_b, schema)
442+
.build(),
443+
None => Resource::new(key_values_b),
444+
};
434445

435446
assert_eq!(
436447
resource.merge(&other_resource).schema_url(),
@@ -544,15 +555,4 @@ mod tests {
544555
},
545556
)
546557
}
547-
548-
#[test]
549-
fn with_schema_url_for_empty_attributes() {
550-
let resource = Resource::builder_empty()
551-
.with_schema_url(vec![], "http://schema/a")
552-
.build();
553-
assert_eq!(resource.schema_url(), Some("http://schema/a"));
554-
555-
let resource = Resource::builder_empty().build().merge(&resource);
556-
assert_eq!(resource.schema_url(), Some("http://schema/a"));
557-
}
558558
}

0 commit comments

Comments
 (0)