Skip to content

[Prometheus.HttpListener] Support scrape HTTP response caching#7189

Merged
martincostello merged 6 commits into
open-telemetry:mainfrom
martincostello:prometheus-http-cache
Apr 28, 2026
Merged

[Prometheus.HttpListener] Support scrape HTTP response caching#7189
martincostello merged 6 commits into
open-telemetry:mainfrom
martincostello:prometheus-http-cache

Conversation

@martincostello

Copy link
Copy Markdown
Member

Changes

Add support for caching HTTP responses in OpenTelementry.Exporter.Prometheus.HttpListener.

This creates parity with the ASP.NET Core exporter instead of forcing it to be disabled.

If we'd rather keep the current behaviour by default, I can change the default back to 0.

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)

Add support for caching HTTP responses.
@github-actions github-actions Bot added the pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package label Apr 27, 2026
@codecov

codecov Bot commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.58%. Comparing base (86f0c3f) to head (dff3178).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7189      +/-   ##
==========================================
+ Coverage   89.25%   89.58%   +0.33%     
==========================================
  Files         271      272       +1     
  Lines       13093    13445     +352     
==========================================
+ Hits        11686    12045     +359     
+ Misses       1407     1400       -7     
Flag Coverage Δ
unittests-Project-Experimental 89.38% <100.00%> (+0.25%) ⬆️
unittests-Project-Stable 89.38% <100.00%> (+0.24%) ⬆️
unittests-UnstableCoreLibraries-Experimental 40.99% <100.00%> (+0.05%) ⬆️

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

Files with missing lines Coverage Δ
...theusHttpListenerMeterProviderBuilderExtensions.cs 81.25% <100.00%> (ø)
...heus.HttpListener/PrometheusHttpListenerOptions.cs 100.00% <100.00%> (ø)

... and 12 files with indirect coverage changes

Comment thread src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md Outdated
@martincostello martincostello marked this pull request as ready for review April 27, 2026 19:40
@martincostello martincostello requested a review from a team as a code owner April 27, 2026 19:40
Copilot AI review requested due to automatic review settings April 27, 2026 19:40

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 configurable scrape HTTP response caching for the Prometheus HttpListener exporter, bringing it to parity with the ASP.NET Core exporter and enabling caching by default.

Changes:

  • Introduces PrometheusHttpListenerOptions.ScrapeResponseCacheDurationMilliseconds (default 300ms; 0 disables caching).
  • Plumbs the configured cache duration into the PrometheusExporter created by AddPrometheusHttpListener.
  • Updates/extends unit tests and changelog/public API baselines for the new option.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerMeterProviderBuilderExtensionsTests.cs Adds a unit test asserting configured cache duration flows into the exporter.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusCollectionManagerTests.cs Updates theory inputs to align with new default caching behavior for HttpListener.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerOptions.cs Adds new cache duration option and sets default to 300ms.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/PrometheusHttpListenerMeterProviderBuilderExtensions.cs Passes the new HttpListener option through to the exporter options.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md Documents the new caching support in Unreleased.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/.publicApi/PublicAPI.Unshipped.txt Adds new public API surface for the cache duration property.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@martincostello martincostello marked this pull request as draft April 27, 2026 20:09
auto-merge was automatically disabled April 27, 2026 20:09

Pull request was converted to draft

Update out-of-date comments.
@martincostello martincostello marked this pull request as ready for review April 28, 2026 09:56
Comment thread src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md
Update README and CHANGELOG.
@martincostello martincostello added this pull request to the merge queue Apr 28, 2026
Merged via the queue into open-telemetry:main with commit 8e66b81 Apr 28, 2026
71 checks passed
@martincostello martincostello deleted the prometheus-http-cache branch April 28, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants