[Exporter.Prometheus] Add TargetInfoEnabled option#7438
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.
Add PR number.
Add new `TargetInfoEnabled` option that allows a user to opt-out of `target_info` metrics being written to the scrape response. Fixes open-telemetry#7158.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7438 +/- ##
==========================================
+ Coverage 90.17% 90.19% +0.01%
==========================================
Files 285 279 -6
Lines 15336 14813 -523
==========================================
- Hits 13830 13361 -469
+ Misses 1506 1452 -54
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Add PR number.
- Add missing condition. - Use deterministic sort for test. - Fix test name.
There was a problem hiding this comment.
Pull request overview
This PR adds a configurable TargetInfoEnabled option to the Prometheus exporters (HttpListener and ASP.NET Core) so users can opt out of emitting the target_info metric in scrape responses, aligning with the OpenTelemetry Prometheus exporter spec guidance.
Changes:
- Add
TargetInfoEnabledtoPrometheusHttpListenerOptionsandPrometheusAspNetCoreOptions(defaulttrue) and track the new public APIs. - Wire the option through the exporter pipeline and conditionally skip writing
target_infoduring serialization. - Add/extend integration tests with snapshots covering both enabled and disabled behaviors, and document the new option.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithTargetInfoEnabledConfigured_targetInfoEnabled=True.verified.text | New snapshot verifying target_info is present when enabled. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunWithTargetInfoEnabledConfigured_targetInfoEnabled=False.verified.text | New snapshot verifying target_info is omitted when disabled. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunHttpServerWithTargetInfoEnabledConfigured_targetInfoEnabled=True.verified.text | New snapshot for HttpListener integration path with target_info enabled. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/snapshots/PrometheusSerializer.RunHttpServerWithTargetInfoEnabledConfigured_targetInfoEnabled=False.verified.text | New snapshot for HttpListener integration path with target_info disabled. |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs | Adds theory test to validate HttpListener option toggling end-to-end. |
| test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs | Adds theory test to validate ASP.NET Core middleware option toggling end-to-end. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/README.md | Documents TargetInfoEnabled and adds it to the configuration property list. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerOptions.cs | Introduces public TargetInfoEnabled option with default true. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerMeterProviderBuilderExtensions.cs | Propagates TargetInfoEnabled into exporter options used by the metric reader. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusExporterOptions.cs | Adds TargetInfoEnabled to shared exporter options (default true). |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusExporter.cs | Stores TargetInfoEnabled on the exporter instance for downstream use. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusCollectionManager.cs | Conditionally writes target_info based on the new option. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md | Adds Unreleased entry describing the new option. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/.publicApi/PublicAPI.Unshipped.txt | Tracks the new public TargetInfoEnabled API on PrometheusHttpListenerOptions. |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/README.md | Documents TargetInfoEnabled for the ASP.NET Core exporter options. |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusAspNetCoreOptions.cs | Introduces public TargetInfoEnabled option (backed by shared exporter options). |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md | Adds Unreleased entry describing the new option. |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/.publicApi/PublicAPI.Unshipped.txt | Tracks the new public TargetInfoEnabled API on PrometheusAspNetCoreOptions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fixes #7158
Changes
Add new
TargetInfoEnabledoption that allows a user to opt-out oftarget_infometrics being written to the scrape response.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes