[Exporter.Prometheus] Add ScopeInfoEnabled option#7436
Conversation
- Simplify test names. - Use snapshots. - Fix buffer resize test to actually grow the buffer.
Add new `ScopeInfoEnabled` option that allows a user to opt-out of scope information being written to the scrape response. Fixes open-telemetry#5725. Fixes open-telemetry#7157.
Use snapshots and simplify metric name.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7436 +/- ##
==========================================
+ Coverage 89.93% 89.98% +0.04%
==========================================
Files 283 278 -5
Lines 15183 14667 -516
==========================================
- Hits 13655 13198 -457
+ Misses 1528 1469 -59
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Add PR number.
There was a problem hiding this comment.
Pull request overview
Adds a ScopeInfoEnabled configuration option to the Prometheus exporters (HttpListener + ASP.NET Core) so users can opt out of emitting otel_scope_* labels in scrape responses, aligning with the Prometheus/OpenMetrics compatibility guidance.
Changes:
- Introduces
ScopeInfoEnabledonPrometheusHttpListenerOptionsandPrometheusAspNetCoreOptions(defaulttrue) and wires it into the exporter pipeline. - Threads a new
TextFormatSerializerOptionsthrough serialization to suppress scope labels when disabled. - Refactors/expands tests to snapshot-based verification for the new behavior and updated integration scenarios.
Reviewed changes
Copilot reviewed 52 out of 53 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs | Adds unit coverage for suppressing scope labels during metric serialization. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs | Updates integration tests and adds snapshot verification (including ScopeInfoEnabled scenarios). |
| test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs | Updates ASP.NET Core integration tests and adds snapshot verification (including ScopeInfoEnabled scenarios). |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.WriteMetricSupportsScopeInfoEnabledOptionForCounters_useOpenMetrics=True_suppressScopeInfo=True.verified.txt | Snapshot baseline for serialization with scope info suppressed (OpenMetrics). |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.WriteMetricSupportsScopeInfoEnabledOptionForCounters_useOpenMetrics=True_suppressScopeInfo=False.verified.txt | Snapshot baseline for serialization with scope info enabled (OpenMetrics). |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.WriteMetricSupportsScopeInfoEnabledOptionForCounters_useOpenMetrics=False_suppressScopeInfo=True.verified.txt | Snapshot baseline for serialization with scope info suppressed (Prometheus text). |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.WriteMetricSupportsScopeInfoEnabledOptionForCounters_useOpenMetrics=False_suppressScopeInfo=False.verified.txt | Snapshot baseline for serialization with scope info enabled (Prometheus text). |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithTextPlainResponseAndMeterTags.verified.text | Snapshot baseline for text/plain scrape with meter tags. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithTextPlainResponse.verified.text | Snapshot baseline for text/plain scrape. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithScrapeEndpointPathOverride.verified.text | Snapshot baseline for path override behavior. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithScrapeEndpointPathFallbackFromAddPrometheusExporter.verified.text | Snapshot baseline for options fallback via AddPrometheusExporter. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithScrapeEndpointPathFallback.verified.text | Snapshot baseline for scrape endpoint path fallback. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithScopeInfoEnabledConfigured_scopeInfoEnabled=True.verified.text | Snapshot baseline when scope labels are enabled. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithScopeInfoEnabledConfigured_scopeInfoEnabled=False.verified.text | Snapshot baseline when scope labels are disabled. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithPathNamedOptionsOverride.verified.text | Snapshot baseline for named-options overrides. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithOpenMetricsVersionHeaderAndMeterTags.verified.text | Snapshot baseline for OpenMetrics negotiation with meter tags. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithOpenMetricsVersionHeader.verified.text | Snapshot baseline for OpenMetrics negotiation. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithNoMetrics.verified.text | Snapshot baseline for “no metrics” scrape. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithMixedPredicateAndPath.verified.text | Snapshot baseline for mixed predicate/path configuration. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithMixedPath.verified.text | Snapshot baseline for mixed path configuration. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithMeterProvider.verified.text | Snapshot baseline for custom meter provider usage. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithMapPrometheusScrapingEndpointWithPathOverride.verified.text | Snapshot baseline for endpoint mapping with path override. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithMapPrometheusScrapingEndpointWithPathNamedOptionsOverride.verified.text | Snapshot baseline for endpoint mapping with named options. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithMapPrometheusScrapingEndpointWithMeterProvider.verified.text | Snapshot baseline for endpoint mapping with external meter provider. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithMapPrometheusScrapingEndpoint.verified.text | Snapshot baseline for endpoint mapping defaults. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithHttpContextPredicate.verified.text | Snapshot baseline for scrape predicate behavior. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithDefaultOptions.verified.text | Snapshot baseline for ASP.NET Core default scrape behavior. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithCustomScrapeEndpointPath.verified.text | Snapshot baseline for custom scrape path in ASP.NET Core. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunHttpServerWithScopeInfoEnabledConfigured_scopeInfoEnabled=True.verified.text | Snapshot baseline for HttpListener server with scope labels enabled. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunHttpServerWithScopeInfoEnabledConfigured_scopeInfoEnabled=False.verified.text | Snapshot baseline for HttpListener server with scope labels disabled. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunHttpServerWithOpenMetricsVersionHeaderAndMeterTags.verified.text | Snapshot baseline for HttpListener server OpenMetrics + meter tags. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunHttpServerWithOpenMetricsVersionHeader.verified.text | Snapshot baseline for HttpListener server OpenMetrics. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunHttpServerWithNoMetrics.verified.text | Snapshot baseline for HttpListener server with no metrics. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunHttpServerWithNoAcceptHeaderAndMeterTags.verified.text | Snapshot baseline for HttpListener server Prometheus text + meter tags. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunHttpServerWithNoAcceptHeader.verified.text | Snapshot baseline for HttpListener server Prometheus text. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunHttpServerWithDefaultOptions.verified.text | Snapshot baseline for HttpListener server default behavior. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.BufferSizeIncreasesWithLotOfMetrics.verified.text | Snapshot baseline for large-payload/buffer growth scenario. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerOptions.cs | Adds public ScopeInfoEnabled option (default true). |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerMeterProviderBuilderExtensions.cs | Wires ScopeInfoEnabled from listener options into exporter options. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusExporterOptions.cs | Adds internal ScopeInfoEnabled plumbing (default true). |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusExporter.cs | Stores ScopeInfoEnabled on the exporter instance. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusCollectionManager.cs | Passes suppression intent into serialization via TextFormatSerializerOptions. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization/TextFormatSerializerOptions.cs | Introduces serializer options struct (includes SuppressScopeInfo). |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization/TextFormatSerializer.cs | Threads serializer options into tag writing and created-series paths. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization/OpenMetricsSerializer.cs | Updates created-series writing to propagate serializer options. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization/PrometheusTextSerializer.cs | Updates created-series writing signature to accept serializer options. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/README.md | Documents ScopeInfoEnabled. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md | Notes the new ScopeInfoEnabled option. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/.publicApi/PublicAPI.Unshipped.txt | Tracks the new public API on PrometheusHttpListenerOptions. |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusAspNetCoreOptions.cs | Adds ScopeInfoEnabled surface for ASP.NET Core options. |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/README.md | Documents ScopeInfoEnabled for ASP.NET Core exporter. |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md | Notes the new ScopeInfoEnabled option. |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/.publicApi/PublicAPI.Unshipped.txt | Tracks the new public API on PrometheusAspNetCoreOptions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add missing condition. - Use deterministic sort for test. - Fix test name.
Fixes #5725.
Fixes #7157.
Changes
ScopeInfoEnabledoption that allows a user to opt-out of scope information being written to the scrape response.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes