Skip to content

[Exporter.Prometheus] Add translation strategy infra#7503

Open
martincostello wants to merge 2 commits into
open-telemetry:mainfrom
martincostello:gh-7156
Open

[Exporter.Prometheus] Add translation strategy infra#7503
martincostello wants to merge 2 commits into
open-telemetry:mainfrom
martincostello:gh-7156

Conversation

@martincostello

Copy link
Copy Markdown
Member

Contributes to #7156

Changes

Introduce internal PrometheusTranslationStrategy enum and thread a metric-name suffix-suppression policy from options through to PrometheusMetric.

A follow-up PR will expose the option into the public API and configure how it interacts with the Accept header to determine precedence.

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)

Introduce internal `PrometheusTranslationStrategy` enum and thread a metric-name suffix-suppression policy from options through to `PrometheusMetric`.

Contributes to open-telemetry#7156.
@github-actions github-actions Bot added the pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package label Jul 8, 2026
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.26%. Comparing base (af56ce6) to head (1cb8907).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
.../Shared/PrometheusTranslationStrategyExtensions.cs 87.50% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #7503   +/-   ##
=======================================
  Coverage   90.26%   90.26%           
=======================================
  Files         288      289    +1     
  Lines       15658    15687   +29     
=======================================
+ Hits        14133    14160   +27     
- Misses       1525     1527    +2     
Flag Coverage Δ
unittests-Project-Experimental 90.17% <94.44%> (-0.16%) ⬇️
unittests-Project-Stable 90.28% <94.44%> (-0.06%) ⬇️
unittests-UnstableCoreLibraries-Experimental 51.10% <94.44%> (+0.08%) ⬆️

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 92.37% <100.00%> (ø)
...HttpListener/Internal/Shared/PrometheusExporter.cs 100.00% <100.00%> (ø)
...tener/Internal/Shared/PrometheusExporterOptions.cs 100.00% <100.00%> (ø)
...s.HttpListener/Internal/Shared/PrometheusMetric.cs 99.59% <100.00%> (+0.01%) ⬆️
.../Shared/PrometheusTranslationStrategyExtensions.cs 87.50% <87.50%> (ø)

Clarify comment based on review by Claude.
@martincostello martincostello marked this pull request as ready for review July 8, 2026 13:11
@martincostello martincostello requested a review from a team as a code owner July 8, 2026 13:11
Copilot AI review requested due to automatic review settings July 8, 2026 13:11

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

Introduces internal infrastructure for Prometheus translation strategy selection and threads a “metric name suffix suppression” policy from exporter options into PrometheusMetric, enabling future configuration of name translation behavior.

Changes:

  • Add internal PrometheusTranslationStrategy enum plus extension helpers for mapping strategy → escaping scheme and suffix behavior.
  • Plumb TranslationStrategy from PrometheusExporterOptionsPrometheusExporterPrometheusCollectionManagerPrometheusMetric to control whether unit/_total suffixes are appended.
  • Add/extend unit tests to validate suffix-suppression behavior and strategy mappings.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusTranslationStrategyTests.cs Adds unit tests for strategy defaults and mapping behavior.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusMetricTests.cs Adds test coverage for appendSuffixes: false behavior across escaping schemes and counter naming.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusTranslationStrategyExtensions.cs Adds internal mapping helpers from translation strategy to escaping/suffix behavior.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusTranslationStrategy.cs Introduces the internal translation strategy enum.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusMetric.cs Implements suffix suppression in name generation and threads appendSuffixes through all name builders.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusExporterOptions.cs Adds TranslationStrategy option with default.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusExporter.cs Stores the configured strategy and exposes AppendSuffixes derived from it.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusCollectionManager.cs Passes exporter suffix policy into PrometheusMetric.Create.

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

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.

2 participants