4949import java .util .List ;
5050import java .util .concurrent .atomic .AtomicInteger ;
5151import java .util .function .Predicate ;
52- import java .util .regex .Matcher ;
5352import java .util .regex .Pattern ;
5453import java .util .stream .Collectors ;
5554import java .util .stream .Stream ;
@@ -63,7 +62,9 @@ class Otel2PrometheusConverterTest {
6362
6463 private static final Pattern PATTERN =
6564 Pattern .compile (
66- "# HELP (?<help>.*)\n # TYPE (?<type>.*)\n (?<metricName>.*)\\ {otel_scope_name=\" scope\" }(.|\\ n)*" );
65+ "(.|\\ n)*# HELP (?<help>.*)\n # TYPE (?<type>.*)\n (?<metricName>.*)\\ {"
66+ + "otel_scope_foo=\" bar\" ,otel_scope_name=\" scope\" ,"
67+ + "otel_scope_schema_url=\" schemaUrl\" ,otel_scope_version=\" version\" }(.|\\ n)*" );
6768 private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper ();
6869
6970 private final Otel2PrometheusConverter converter =
@@ -79,16 +80,17 @@ void metricMetadata(
7980 ExpositionFormats .init ().getPrometheusTextFormatWriter ().write (out , snapshots );
8081 String expositionFormat = new String (out .toByteArray (), StandardCharsets .UTF_8 );
8182
82- // Uncomment to debug exposition format output
83- // System.out.println(expositionFormat);
84-
85- Matcher matcher = PATTERN .matcher (expositionFormat );
86- assertThat (matcher .matches ()).isTrue ();
87- assertThat (matcher .group ("help" )).isEqualTo (expectedHelp );
88- assertThat (matcher .group ("type" )).isEqualTo (expectedType );
89- // Note: Summaries and histograms produce output which matches METRIC_NAME_PATTERN multiple
90- // times. The pattern ends up matching against the first.
91- assertThat (matcher .group ("metricName" )).isEqualTo (expectedMetricName );
83+ assertThat (expositionFormat )
84+ .matchesSatisfying (
85+ PATTERN ,
86+ matcher -> {
87+ assertThat (matcher .group ("help" )).isEqualTo (expectedHelp );
88+ assertThat (matcher .group ("type" )).isEqualTo (expectedType );
89+ // Note: Summaries and histograms produce output which matches METRIC_NAME_PATTERN
90+ // multiple
91+ // times. The pattern ends up matching against the first.
92+ assertThat (matcher .group ("metricName" )).isEqualTo (expectedMetricName );
93+ });
9294 }
9395
9496 private static Stream <Arguments > metricMetadataArgs () {
@@ -368,11 +370,17 @@ static MetricData createSampleMetricData(
368370 Attributes attributesToUse = attributes == null ? Attributes .empty () : attributes ;
369371 Resource resourceToUse = resource == null ? Resource .getDefault () : resource ;
370372
373+ InstrumentationScopeInfo scope =
374+ InstrumentationScopeInfo .builder ("scope" )
375+ .setVersion ("version" )
376+ .setSchemaUrl ("schemaUrl" )
377+ .setAttributes (Attributes .of (stringKey ("foo" ), "bar" ))
378+ .build ();
371379 switch (metricDataType ) {
372380 case SUMMARY :
373381 return ImmutableMetricData .createDoubleSummary (
374382 resourceToUse ,
375- InstrumentationScopeInfo . create ( " scope" ) ,
383+ scope ,
376384 metricName ,
377385 "description" ,
378386 metricUnit ,
@@ -383,7 +391,7 @@ static MetricData createSampleMetricData(
383391 case LONG_SUM :
384392 return ImmutableMetricData .createLongSum (
385393 resourceToUse ,
386- InstrumentationScopeInfo . create ( " scope" ) ,
394+ scope ,
387395 metricName ,
388396 "description" ,
389397 metricUnit ,
@@ -395,7 +403,7 @@ static MetricData createSampleMetricData(
395403 case DOUBLE_SUM :
396404 return ImmutableMetricData .createDoubleSum (
397405 resourceToUse ,
398- InstrumentationScopeInfo . create ( " scope" ) ,
406+ scope ,
399407 metricName ,
400408 "description" ,
401409 metricUnit ,
@@ -407,7 +415,7 @@ static MetricData createSampleMetricData(
407415 case LONG_GAUGE :
408416 return ImmutableMetricData .createLongGauge (
409417 resourceToUse ,
410- InstrumentationScopeInfo . create ( " scope" ) ,
418+ scope ,
411419 metricName ,
412420 "description" ,
413421 metricUnit ,
@@ -417,7 +425,7 @@ static MetricData createSampleMetricData(
417425 case DOUBLE_GAUGE :
418426 return ImmutableMetricData .createDoubleGauge (
419427 resourceToUse ,
420- InstrumentationScopeInfo . create ( " scope" ) ,
428+ scope ,
421429 metricName ,
422430 "description" ,
423431 metricUnit ,
@@ -427,7 +435,7 @@ static MetricData createSampleMetricData(
427435 case HISTOGRAM :
428436 return ImmutableMetricData .createDoubleHistogram (
429437 resourceToUse ,
430- InstrumentationScopeInfo . create ( " scope" ) ,
438+ scope ,
431439 metricName ,
432440 "description" ,
433441 metricUnit ,
@@ -448,7 +456,7 @@ static MetricData createSampleMetricData(
448456 case EXPONENTIAL_HISTOGRAM :
449457 return ImmutableMetricData .createExponentialHistogram (
450458 resourceToUse ,
451- InstrumentationScopeInfo . create ( " scope" ) ,
459+ scope ,
452460 metricName ,
453461 "description" ,
454462 metricUnit ,
0 commit comments