Skip to content

Commit 13fafcb

Browse files
Shunpococijothomas
andauthored
test: Add Scope attributes test cases for metrics (#2736)
Signed-off-by: Shunpoco <[email protected]> Co-authored-by: Cijo Thomas <[email protected]>
1 parent 1583e70 commit 13fafcb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

opentelemetry-sdk/src/metrics/meter_provider.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,45 @@ mod tests {
579579
meter_provider.meter_with_scope(make_scope(vec![KeyValue::new("key", "value1")]));
580580

581581
assert_eq!(meter_provider.inner.meters.lock().unwrap().len(), 1);
582+
583+
// these are identical because InstrumentScope ignores the order of attributes
584+
let _meter3 = meter_provider.meter_with_scope(make_scope(vec![
585+
KeyValue::new("key1", "value1"),
586+
KeyValue::new("key2", "value2"),
587+
]));
588+
let _meter4 = meter_provider.meter_with_scope(make_scope(vec![
589+
KeyValue::new("key2", "value2"),
590+
KeyValue::new("key1", "value1"),
591+
]));
592+
593+
assert_eq!(meter_provider.inner.meters.lock().unwrap().len(), 2);
594+
}
595+
596+
#[test]
597+
fn different_meter_different_attributes() {
598+
let meter_provider = super::SdkMeterProvider::builder().build();
599+
let make_scope = |attributes| {
600+
InstrumentationScope::builder("test.meter")
601+
.with_version("v0.1.0")
602+
.with_schema_url("http://example.com")
603+
.with_attributes(attributes)
604+
.build()
605+
};
606+
607+
let _meter1 = meter_provider.meter_with_scope(make_scope(vec![]));
608+
// _meter2 and _meter3, and _meter4 are different because attribute is case sensitive
609+
let _meter2 =
610+
meter_provider.meter_with_scope(make_scope(vec![KeyValue::new("key1", "value1")]));
611+
let _meter3 =
612+
meter_provider.meter_with_scope(make_scope(vec![KeyValue::new("Key1", "value1")]));
613+
let _meter4 =
614+
meter_provider.meter_with_scope(make_scope(vec![KeyValue::new("key1", "Value1")]));
615+
let _meter5 = meter_provider.meter_with_scope(make_scope(vec![
616+
KeyValue::new("key1", "value1"),
617+
KeyValue::new("key2", "value2"),
618+
]));
619+
620+
assert_eq!(meter_provider.inner.meters.lock().unwrap().len(), 5);
582621
}
583622

584623
#[test]

0 commit comments

Comments
 (0)