@@ -192,11 +192,10 @@ public void MetricInstrumentationScopeIsExportedCorrectly()
192192 }
193193
194194 [ Fact ]
195- public void MetricInstrumentationScopeAttributesAreNotTreatedAsIdentifyingProperty ( )
195+ public void MetricInstrumentationScopeAttributesAreTreatedAsIdentifyingProperty ( )
196196 {
197197 // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#get-a-meter
198- // Meters are identified by name, version, and schema_url fields
199- // and not with tags.
198+ // Meters are identified by name, version, meter tags and schema_url fields.
200199 var exportedItems = new List < Metric > ( ) ;
201200 var meterName = "MyMeter" ;
202201 var meterVersion = "1.0" ;
@@ -224,19 +223,16 @@ public void MetricInstrumentationScopeAttributesAreNotTreatedAsIdentifyingProper
224223 counter2 . Add ( 15 ) ;
225224 meterProvider . ForceFlush ( MaxTimeToAllowForFlush ) ;
226225
227- // The instruments differ only in the Meter.Tags, which is not an identifying property.
228- // The first instrument's Meter.Tags is exported.
229- // It is considered a user-error to create Meters with same name,version but with
230- // different tags. TODO: See if we can emit an internal log about this.
231- Assert . Single ( exportedItems ) ;
232- var metric = exportedItems [ 0 ] ;
233- Assert . Equal ( meterName , metric . MeterName ) ;
234- Assert . Equal ( meterVersion , metric . MeterVersion ) ;
226+ Assert . Equal ( 2 , exportedItems . Count ) ;
235227
236- Assert . NotNull ( metric . MeterTags ) ;
228+ bool TagComparator ( KeyValuePair < string , object ? > lhs , KeyValuePair < string , object ? > rhs )
229+ {
230+ return lhs . Key . Equals ( rhs . Key ) && lhs . Value ! . GetHashCode ( ) . Equals ( rhs . Value ! . GetHashCode ( ) ) ;
231+ }
237232
238- Assert . Single ( metric . MeterTags . Where ( kvp => kvp . Key == meterTags1 [ 0 ] . Key && kvp . Value == meterTags1 [ 0 ] . Value ) ) ;
239- Assert . DoesNotContain ( metric . MeterTags , kvp => kvp . Key == meterTags2 [ 0 ] . Key && kvp . Value == meterTags2 [ 0 ] . Value ) ;
233+ var metric = exportedItems . First ( m => TagComparator ( m . MeterTags ! . First ( ) , meterTags1 ! . First ( ) ) ) ;
234+ Assert . Equal ( meterName , metric . MeterName ) ;
235+ Assert . Equal ( meterVersion , metric . MeterVersion ) ;
240236
241237 List < MetricPoint > metricPoints = new List < MetricPoint > ( ) ;
242238 foreach ( ref readonly var mp in metric . GetMetricPoints ( ) )
@@ -246,7 +242,21 @@ public void MetricInstrumentationScopeAttributesAreNotTreatedAsIdentifyingProper
246242
247243 Assert . Single ( metricPoints ) ;
248244 var metricPoint1 = metricPoints [ 0 ] ;
249- Assert . Equal ( 25 , metricPoint1 . GetSumLong ( ) ) ;
245+ Assert . Equal ( 10 , metricPoint1 . GetSumLong ( ) ) ;
246+
247+ metric = exportedItems . First ( m => TagComparator ( m . MeterTags ! . First ( ) , meterTags2 ! . First ( ) ) ) ;
248+ Assert . Equal ( meterName , metric . MeterName ) ;
249+ Assert . Equal ( meterVersion , metric . MeterVersion ) ;
250+
251+ metricPoints = new List < MetricPoint > ( ) ;
252+ foreach ( ref readonly var mp in metric . GetMetricPoints ( ) )
253+ {
254+ metricPoints . Add ( mp ) ;
255+ }
256+
257+ Assert . Single ( metricPoints ) ;
258+ metricPoint1 = metricPoints [ 0 ] ;
259+ Assert . Equal ( 15 , metricPoint1 . GetSumLong ( ) ) ;
250260 }
251261
252262 [ Fact ]
0 commit comments