@@ -684,9 +684,56 @@ private static Stream<Arguments> resourceAttributesAdditionArgs() {
684684 "my_metric_units" ,
685685 "cluster=\" mycluster\" ,otel_scope_foo=\" bar\" ,otel_scope_name=\" scope\" ,otel_scope_schema_url=\" schemaUrl\" ,otel_scope_version=\" version\" " ));
686686
687+ // Array-valued resource attribute is serialized as a JSON string, matching the point attribute
688+ // path
689+ arguments .add (
690+ Arguments .argumentSet (
691+ "array-valued resource attribute serialized as json" ,
692+ createSampleMetricData (
693+ "my.metric" ,
694+ "units" ,
695+ MetricDataType .LONG_SUM ,
696+ Attributes .empty (),
697+ Resource .create (
698+ Attributes .of (stringArrayKey ("clusters" ), Arrays .asList ("a" , "b" )))),
699+ /* allowedResourceAttributesFilter= */ Predicates .startsWith ("clu" ),
700+ "my_metric_units" ,
701+ "clusters=\" [\\ \" a\\ \" ,\\ \" b\\ \" ]\" ,otel_scope_foo=\" bar\" ,otel_scope_name=\" scope\" ,otel_scope_schema_url=\" schemaUrl\" ,otel_scope_version=\" version\" " ));
702+
687703 return arguments .stream ();
688704 }
689705
706+ @ Test
707+ void arrayValuedScopeAttributeSerializedAsJson () {
708+ // Array-valued scope attribute is serialized as a JSON string, matching the point attribute
709+ // path
710+ InstrumentationScopeInfo scope =
711+ InstrumentationScopeInfo .builder ("scope" )
712+ .setAttributes (Attributes .of (stringArrayKey ("foo" ), Arrays .asList ("a" , "b" )))
713+ .build ();
714+ MetricData metricData =
715+ ImmutableMetricData .createLongSum (
716+ Resource .getDefault (),
717+ scope ,
718+ "sample" ,
719+ "description" ,
720+ "1" ,
721+ ImmutableSumData .create (
722+ /* isMonotonic= */ true ,
723+ AggregationTemporality .CUMULATIVE ,
724+ Collections .singletonList (
725+ ImmutableLongPointData .create (0 , 1 , Attributes .empty (), 1L ))));
726+
727+ MetricSnapshots snapshots = converter .convert (Collections .singletonList (metricData ));
728+
729+ Optional <MetricSnapshot > metricSnapshot =
730+ snapshots .stream ().filter (snapshot -> snapshot instanceof CounterSnapshot ).findFirst ();
731+ assertThat (metricSnapshot ).isPresent ();
732+
733+ Labels labels = metricSnapshot .get ().getDataPoints ().get (0 ).getLabels ();
734+ assertThat (labels .get ("otel_scope_foo" )).isEqualTo ("[\" a\" ,\" b\" ]" );
735+ }
736+
690737 @ Test
691738 void metricNameCollisionTest_Issue6277 () {
692739 // NOTE: Metrics with the same resolved prometheus name should merge. However,
0 commit comments