Repository: open-telemetry/opentelemetry-java
File: exporters/prometheus/src/test/java/io/opentelemetry/exporter/prometheus/Otel2PrometheusConverterTest.java (Java)

Code before:
    assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("booleanKey"))
        .isEqualTo("true");
    assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("longKey"))
        .isEqualTo("9223372036854775807");
    assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("doubleKey"))
        .isEqualTo("0.12345");
  }

  @Test
  void labelValueSerialization_NonPrimitives() {
    Attributes attributes =
        Attributes.builder()
            .put(
                AttributeKey.stringArrayKey("stringKey"),
                Arrays.asList("stringValue1", "\"+\\\\\\+\b+\f+\n+\r+\t+" + (char) 0))
            .put(AttributeKey.booleanArrayKey("booleanKey"), Arrays.asList(true, false))
            .put(AttributeKey.longArrayKey("longKey"), Arrays.asList(12345L, 6789L))
            .put(AttributeKey.doubleArrayKey("doubleKey"), Arrays.asList(0.12345, 0.6789))
            .build();
    MetricData metricData =
        createSampleMetricData("sample", "1", MetricDataType.LONG_SUM, attributes, null);

    MetricSnapshots snapshots = converter.convert(Collections.singletonList(metricData));

    assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("stringKey"))
        .isEqualTo("[\"stringValue1\", \"\\\"+\\\\\\\\\\\\+\\b+\\f+\\n+\\r+\\t+\\u0000\"]");
    assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("booleanKey"))
        .isEqualTo("[true, false]");
    assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("longKey"))
        .isEqualTo("[12345, 6789]");
    assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("doubleKey"))
        .isEqualTo("[0.12345, 0.6789]");
  }

  @Test
  void labelValueSerialization_Should_Handle_All_AttributeTypes() {
    assertThat(Stream.of(AttributeType.values()).map(Enum::name))
        .isEqualTo(
            Arrays.asList(
                "STRING",
                "BOOLEAN",
                "LONG",
                "DOUBLE",
                "STRING_ARRAY",
                "BOOLEAN_ARRAY",
                "LONG_ARRAY",
                "DOUBLE_ARRAY"));
  }

  private static Stream<Arguments> resourceAttributesAdditionArgs() {
    List<Arguments> arguments = new ArrayList<>();

Review comment (suggestion):
For all strings, why don't we verify that the JSON encoded string is the sample as what jackson would have produced? I.e. add jackson as a test dependency to increase confidence of the implementation, but avoid having it as a runtime dependency.

Code after:
            "metric_name_ratio description",
            "metric_name_ratio"),
        Arguments.of(
            createSampleMetricData("metric_name_ratio", "1", MetricDataType.SUMMARY),
            "metric_name_ratio summary",
            "metric_name_ratio description",
            "metric_name_ratio_count"),
        Arguments.of(
            createSampleMetricData("metric_hertz", "hertz", MetricDataType.LONG_GAUGE),
            "metric_hertz gauge",
            "metric_hertz description",
            "metric_hertz"),
        Arguments.of(
            createSampleMetricData("metric_hertz", "hertz", MetricDataType.LONG_SUM),
            "metric_hertz_total counter",
            "metric_hertz_total description",
            "metric_hertz_total"),
        // if metric name ends with unit the unit is omitted - order matters
        Arguments.of(
            createSampleMetricData("metric_total_hertz", "hertz_total", MetricDataType.LONG_SUM),
            "metric_total_hertz_total counter",
            "metric_total_hertz_total description",
            "metric_total_hertz_total"),
        // metric name cannot start with a number
        Arguments.of(
            createSampleMetricData("2_metric_name", "By", MetricDataType.SUMMARY),
            "_metric_name_bytes summary",
            "_metric_name_bytes description",
            "_metric_name_bytes_count"));
  }

  @ParameterizedTest
  @MethodSource("resourceAttributesAdditionArgs")
  void resourceAttributesAddition(
      MetricData metricData,
      @Nullable Predicate<String> allowedResourceAttributesFilter,
      String metricName,
      String expectedMetricLabels)
      throws IOException {

    Otel2PrometheusConverter converter =
        new Otel2PrometheusConverter(true, allowedResourceAttributesFilter);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    MetricSnapshots snapshots = converter.convert(Collections.singletonList(metricData));
    ExpositionFormats.init().getPrometheusTextFormatWriter().write(out, snapshots);
    String expositionFormat = new String(out.toByteArray(), StandardCharsets.UTF_8);

    // extract the only metric line
    List<String> metricLines =
        Arrays.stream(expositionFormat.split("\n"))