3838import io .opentelemetry .sdk .metrics .internal .data .ImmutableSummaryPointData ;
3939import io .opentelemetry .sdk .resources .Resource ;
4040import io .prometheus .metrics .expositionformats .ExpositionFormats ;
41+ import io .prometheus .metrics .model .snapshots .CounterSnapshot ;
4142import io .prometheus .metrics .model .snapshots .Labels ;
43+ import io .prometheus .metrics .model .snapshots .MetricSnapshot ;
4244import io .prometheus .metrics .model .snapshots .MetricSnapshots ;
4345import java .io .ByteArrayOutputStream ;
4446import java .io .IOException ;
4749import java .util .Arrays ;
4850import java .util .Collections ;
4951import java .util .List ;
52+ import java .util .Optional ;
5053import java .util .concurrent .atomic .AtomicInteger ;
5154import java .util .function .Predicate ;
5255import java .util .regex .Pattern ;
@@ -241,7 +244,7 @@ private static Stream<Arguments> resourceAttributesAdditionArgs() {
241244 : "my_metric_units" ,
242245
243246 // "cluster" attribute is added (due to reg expr specified) and only it
244- "cluster=\" mycluster\" ,foo1=\" bar1\" ,foo2=\" bar2\" ,otel_scope_name=\" scope\" " ));
247+ "cluster=\" mycluster\" ,foo1=\" bar1\" ,foo2=\" bar2\" ,otel_scope_foo= \" bar \" , otel_scope_name=\" scope\" ,otel_scope_schema_url= \" schemaUrl \" ,otel_scope_version= \" version \" " ));
245248 }
246249
247250 // Resource attributes which also exists in the metric labels are not added twice
@@ -260,7 +263,7 @@ private static Stream<Arguments> resourceAttributesAdditionArgs() {
260263
261264 // "cluster" attribute is present only once and the value is taken
262265 // from the metric attributes and not the resource attributes
263- "cluster=\" mycluster2\" ,foo2=\" bar2\" ,otel_scope_name=\" scope\" " ));
266+ "cluster=\" mycluster2\" ,foo2=\" bar2\" ,otel_scope_foo= \" bar \" , otel_scope_name=\" scope\" ,otel_scope_schema_url= \" schemaUrl \" ,otel_scope_version= \" version \" " ));
264267
265268 // Empty attributes
266269 arguments .add (
@@ -275,7 +278,7 @@ private static Stream<Arguments> resourceAttributesAdditionArgs() {
275278 stringKey ("host" ), "localhost" , stringKey ("cluster" ), "mycluster" ))),
276279 /* allowedResourceAttributesFilter= */ Predicates .startsWith ("clu" ),
277280 "my_metric_units" ,
278- "cluster=\" mycluster\" ,otel_scope_name=\" scope\" " ));
281+ "cluster=\" mycluster\" ,otel_scope_foo= \" bar \" , otel_scope_name=\" scope\" ,otel_scope_schema_url= \" schemaUrl \" ,otel_scope_version= \" version \" " ));
279282
280283 return arguments .stream ();
281284 }
@@ -316,7 +319,11 @@ void labelValueSerialization(Attributes attributes) {
316319
317320 MetricSnapshots snapshots = converter .convert (Collections .singletonList (metricData ));
318321
319- Labels labels = snapshots .get (0 ).getDataPoints ().get (0 ).getLabels ();
322+ Optional <MetricSnapshot > metricSnapshot =
323+ snapshots .stream ().filter (snapshot -> snapshot instanceof CounterSnapshot ).findFirst ();
324+ assertThat (metricSnapshot ).isPresent ();
325+
326+ Labels labels = metricSnapshot .get ().getDataPoints ().get (0 ).getLabels ();
320327 attributes .forEach (
321328 (key , value ) -> {
322329 String labelValue = labels .get (key .getKey ());
0 commit comments