Skip to content

[Exporter.Prometheus] Add ScopeInfoEnabled option#7436

Merged
Kielek merged 9 commits into
open-telemetry:mainfrom
martincostello:gh-7157
Jun 29, 2026
Merged

[Exporter.Prometheus] Add ScopeInfoEnabled option#7436
Kielek merged 9 commits into
open-telemetry:mainfrom
martincostello:gh-7157

Conversation

@martincostello

Copy link
Copy Markdown
Member

Fixes #5725.
Fixes #7157.

Changes

  • Add new ScopeInfoEnabled option that allows a user to opt-out of scope information being written to the scrape response.
  • Improve tests by adding snapshots and simplifying naming.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

- 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.
@github-actions github-actions Bot added pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package labels Jun 20, 2026
Comment thread src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md Outdated
@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.98%. Comparing base (6b4c6fc) to head (8cffbbd).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ometheus.AspNetCore/PrometheusAspNetCoreOptions.cs 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
unittests-PowerShellScripts ?
unittests-Project-Experimental 89.89% <96.00%> (-0.02%) ⬇️
unittests-Project-Stable 89.95% <96.00%> (-0.02%) ⬇️
unittests-UnstableCoreLibraries-Experimental 48.85% <96.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ner/Internal/Shared/PrometheusCollectionManager.cs 90.35% <100.00%> (+0.08%) ⬆️
...HttpListener/Internal/Shared/PrometheusExporter.cs 100.00% <100.00%> (ø)
...tener/Internal/Shared/PrometheusExporterOptions.cs 100.00% <100.00%> (ø)
...rnal/Shared/Serialization/OpenMetricsSerializer.cs 100.00% <100.00%> (ø)
...l/Shared/Serialization/PrometheusTextSerializer.cs 100.00% <ø> (ø)
...ernal/Shared/Serialization/TextFormatSerializer.cs 100.00% <100.00%> (ø)
...hared/Serialization/TextFormatSerializerOptions.cs 100.00% <100.00%> (ø)
...theusHttpListenerMeterProviderBuilderExtensions.cs 81.81% <100.00%> (+0.56%) ⬆️
...heus.HttpListener/PrometheusHttpListenerOptions.cs 100.00% <100.00%> (ø)
...ometheus.AspNetCore/PrometheusAspNetCoreOptions.cs 50.00% <50.00%> (ø)

... and 10 files with indirect coverage changes

Comment thread src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md Outdated
Copilot AI review requested due to automatic review settings June 24, 2026 07:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ScopeInfoEnabled on PrometheusHttpListenerOptions and PrometheusAspNetCoreOptions (default true) and wires it into the exporter pipeline.
  • Threads a new TextFormatSerializerOptions through 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.
@martincostello martincostello added the keep-open Prevents issues and pull requests being closed as stale label Jun 28, 2026
@Kielek
Kielek added this pull request to the merge queue Jun 29, 2026
Merged via the queue into open-telemetry:main with commit 816ccc1 Jun 29, 2026
77 checks passed
This was referenced Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package spec-compliance Issues related to compliance with the OpenTelemetry Specification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Exporter.Prometheus] Support scope info configuration [Exporter.Prometheus] Possibility to disable otel_scope attributes

3 participants