Skip to content

[Prometheus.AspNetCore] Support GZip#7274

Merged
martincostello merged 19 commits into
open-telemetry:mainfrom
martincostello:gh-7213
Jun 2, 2026
Merged

[Prometheus.AspNetCore] Support GZip#7274
martincostello merged 19 commits into
open-telemetry:mainfrom
martincostello:gh-7213

Conversation

@martincostello
Copy link
Copy Markdown
Member

@martincostello martincostello commented May 7, 2026

Fixes #7213

Changes

Add support for GZip compression.

Builds on top of #7252 and #7266.

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)

Observe client requests to abort scrape request processing, including via `X-Prometheus-Scrape-Timeout-Seconds`, and respond with an HTTP 408.
- Constrain accepted `X-Prometheus-Scrape-Timeout-Seconds` values.
- Check cancellation token source.
- Do not try to set the status if response has started.
Extend the ASP.NET Core integration tests to include interop between ASP.NET Core and Prometheus itself to scrape metrics.
- Log exceptions calling Prometheus.
- Use top-level cancellation instead of nested.
- Delete temporary configuration files.
@github-actions github-actions Bot added pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package 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 May 7, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.04%. Comparing base (12d60b1) to head (d2e5ec6).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7274      +/-   ##
==========================================
+ Coverage   89.99%   90.04%   +0.04%     
==========================================
  Files         276      276              
  Lines       14252    14271      +19     
==========================================
+ Hits        12826    12850      +24     
+ Misses       1426     1421       -5     
Flag Coverage Δ
unittests-Project-Experimental 89.78% <100.00%> (-0.17%) ⬇️
unittests-Project-Stable 89.71% <100.00%> (-0.28%) ⬇️
unittests-UnstableCoreLibraries-Experimental 48.53% <100.00%> (+0.10%) ⬆️

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

Files with missing lines Coverage Δ
...metheus.AspNetCore/PrometheusExporterMiddleware.cs 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

@github-actions github-actions Bot removed the pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package label May 7, 2026
Add support for GZip compression.

Resolves open-telemetry#7213.
@martincostello martincostello added the keep-open Prevents issues and pull requests being closed as stale label May 8, 2026
Comment thread src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs Outdated
@github-actions github-actions Bot removed the pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package label May 19, 2026
ASP.NET Core doesn't have a synchronisation context so `ConfigureAwait(false)` is redundant.
@martincostello martincostello marked this pull request as ready for review May 19, 2026 11:32
@martincostello martincostello requested a review from a team as a code owner May 19, 2026 11:32
Copilot AI review requested due to automatic review settings May 19, 2026 11:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds gzip response compression support to the Prometheus ASP.NET Core scrape endpoint when clients request it with Accept-Encoding: gzip.

Changes:

  • Adds gzip compression path in PrometheusExporterMiddleware.
  • Updates negotiation tests to pass typed request headers.
  • Adds an integration test and changelog entry for gzip support.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs Adds gzip detection and compressed response writing.
src/OpenTelemetry.Exporter.Prometheus.AspNetCore/OpenTelemetry.Exporter.Prometheus.AspNetCore.csproj Suppresses CA2007 warnings for the project.
src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md Documents gzip scrape response support.
test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusIntegrationTests.cs Adds integration coverage for gzip responses.
test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs Updates negotiation tests for the new typed-header signature.

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

Comment thread src/OpenTelemetry.Exporter.Prometheus.AspNetCore/PrometheusExporterMiddleware.cs Outdated
<PackageTags>$(PackageTags);prometheus;metrics</PackageTags>
<MinVerTagPrefix>coreunstable-</MinVerTagPrefix>
<DefineConstants>$(DefineConstants);PROMETHEUS_ASPNETCORE</DefineConstants>
<NoWarn>$(NoWarn);CA2007</NoWarn>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

AspNetCore has no synchronisation context so ConfigureAwait(false) has no effect.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

True, I would consider keeping this calls just in case we need to share with httplistener similar code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

At the moment the code reuse is one way from HttpListener to AspNetCore, so I don't think we need to worry about that in practice as if it needs to be shared it'll go in the other project which doesn't supress CA2007.

- Honour the Quality parameter for `Accept-Encoding`.
- Use `HeaderNames.ContentEncoding` constant.
- Specify `Vary: Accept-Encoding`.
- Fix swapped xunit assertion.
@martincostello martincostello enabled auto-merge May 19, 2026 12:02
Comment thread src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md Outdated
Copy link
Copy Markdown
Member

@Kielek Kielek left a comment

Choose a reason for hiding this comment

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

Pushed some direct feedback, needs to resolve conflicts arreound changelog. LGTM

@martincostello
Copy link
Copy Markdown
Member Author

Pushed some direct feedback

Thanks for spotting I'd put the Copilot suggestion in the wrong place 👍

@martincostello martincostello added this pull request to the merge queue Jun 2, 2026
Merged via the queue into open-telemetry:main with commit 78f6d59 Jun 2, 2026
75 checks passed
@martincostello martincostello deleted the gh-7213 branch June 2, 2026 11:56
@martincostello martincostello removed the keep-open Prevents issues and pull requests being closed as stale label Jun 2, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Exporter.Prometheus.AspNetCore] Support GZip compression

3 participants