Skip to content

[Exporter.Prometheus] Add TargetInfoEnabled option#7438

Merged
martincostello merged 17 commits into
open-telemetry:mainfrom
martincostello:gh-7158
Jun 30, 2026
Merged

[Exporter.Prometheus] Add TargetInfoEnabled option#7438
martincostello merged 17 commits into
open-telemetry:mainfrom
martincostello:gh-7158

Conversation

@martincostello

@martincostello martincostello commented Jun 21, 2026

Copy link
Copy Markdown
Member

Fixes #7158

Changes

Add new TargetInfoEnabled option that allows a user to opt-out of target_info metrics being written to the scrape response.

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.
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.
@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 21, 2026
Comment thread src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md Outdated
Comment thread src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md Outdated
@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.19%. Comparing base (f830613) to head (25ed7e7).
✅ 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    #7438      +/-   ##
==========================================
+ Coverage   90.17%   90.19%   +0.01%     
==========================================
  Files         285      279       -6     
  Lines       15336    14813     -523     
==========================================
- Hits        13830    13361     -469     
+ Misses       1506     1452      -54     
Flag Coverage Δ
unittests-PowerShellScripts ?
unittests-Project-Experimental 90.04% <87.50%> (-0.10%) ⬇️
unittests-Project-Stable 90.09% <87.50%> (-0.06%) ⬇️
unittests-UnstableCoreLibraries-Experimental 49.68% <87.50%> (-0.01%) ⬇️

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.37% <100.00%> (+0.02%) ⬆️
...HttpListener/Internal/Shared/PrometheusExporter.cs 100.00% <100.00%> (ø)
...tener/Internal/Shared/PrometheusExporterOptions.cs 100.00% <100.00%> (ø)
...theusHttpListenerMeterProviderBuilderExtensions.cs 82.35% <100.00%> (+0.53%) ⬆️
...heus.HttpListener/PrometheusHttpListenerOptions.cs 100.00% <100.00%> (ø)
...ometheus.AspNetCore/PrometheusAspNetCoreOptions.cs 50.00% <50.00%> (ø)

... and 12 files with indirect coverage changes

@martincostello martincostello added the keep-open Prevents issues and pull requests being closed as stale label Jun 28, 2026
@martincostello
martincostello marked this pull request as ready for review June 29, 2026 10:35
@martincostello
martincostello requested a review from a team as a code owner June 29, 2026 10:35
Copilot AI review requested due to automatic review settings June 29, 2026 10:35

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

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 TargetInfoEnabled to PrometheusHttpListenerOptions and PrometheusAspNetCoreOptions (default true) and track the new public APIs.
  • Wire the option through the exporter pipeline and conditionally skip writing target_info during 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.

@martincostello martincostello removed the keep-open Prevents issues and pull requests being closed as stale label Jun 29, 2026
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 target info configuration

3 participants