Skip to content

feat: support metric name filtering in OpenTelemetry exporter - #2344

Merged
zeitlinger merged 5 commits into
prometheus:mainfrom
subhramit:otel-exporter-metric-filtering
Jul 28, 2026
Merged

feat: support metric name filtering in OpenTelemetry exporter#2344
zeitlinger merged 5 commits into
prometheus:mainfrom
subhramit:otel-exporter-metric-filtering

Conversation

@subhramit

@subhramit subhramit commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Closes the last pending high-priority item in #1816 (as all others have already been addressed).

Currently, PrometheusMetricProducer always exported all metrics in the registry unconditionally. The code already had a TODO sketching how filtering could be added:

// Note: Currently all metrics from the registry are exported. To add metric filtering
// similar to the Servlet exporter, one could:
// 1. Add filter properties to ExporterOpenTelemetryProperties (allowedNames, excludedNames,
// etc.)
// 2. Convert these properties to a Predicate<String> using MetricNameFilter.builder()
// 3. Call registry.scrape(filter) instead of registry.scrape()
// OpenTelemetry also provides its own Views API for filtering and aggregation, which may be
// preferred for OpenTelemetry-specific deployments.

this PR implements that by reusing ExporterFilterProperties and MetricNameFilter, as already done by PrometheusScrapeHandler.

As a result, the OpenTelemetry exporter now honors the shared io.prometheus.exporter.filter.* configuration, making its behavior consistent with the HTTP/Servlet exporters.

Signed-off-by: subhramit <subhramit.bb@live.in>
@subhramit

Copy link
Copy Markdown
Contributor Author

cc @zeitlinger :)

@zeitlinger zeitlinger left a comment

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.

The filtering implementation is consistent with PrometheusScrapeHandler: it builds the same MetricNameFilter from all four ExporterFilterProperties fields and uses registry.scrape(predicate). I ran the exporter module test reactor locally and it passed (including all 35 exporter-module tests). The two new tests cover exact-name exclusion and allowed-prefix filtering; please also add coverage through the user-facing configuration path (OtelAutoConfig) rather than only constructing PrometheusMetricProducer directly, so the wiring itself is protected against regression.

Signed-off-by: subhramit <subhramit.bb@live.in>
Signed-off-by: subhramit <subhramit.bb@live.in>
@subhramit
subhramit requested a review from zeitlinger July 27, 2026 13:26
@subhramit

Copy link
Copy Markdown
Contributor Author

please also add coverage through the user-facing configuration path (OtelAutoConfig) rather than only constructing PrometheusMetricProducer directly, so the wiring itself is protected against regression.

This is also added now.

@zeitlinger zeitlinger left a comment

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.

Could you add a short note to docs/content/otel/otlp.md that the OpenTelemetry exporter now honors the shared io.prometheus.exporter.filter.* metric-name filter properties, with a link to the existing “Exporter Filter Properties” section in docs/content/config/config.md? The property keys are already documented there, so a separate page is not needed.

Signed-off-by: subhramit <subhramit.bb@live.in>
@subhramit

Copy link
Copy Markdown
Contributor Author

Could you add a short note to docs/content/otel/otlp.md that the OpenTelemetry exporter now honors the shared io.prometheus.exporter.filter.* metric-name filter properties, with a link to the existing “Exporter Filter Properties” section in docs/content/config/config.md? The property keys are already documented there, so a separate page is not needed.

Added.

@subhramit
subhramit requested a review from zeitlinger July 27, 2026 16:52

@zeitlinger zeitlinger left a comment

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.

Thanks for addressing the builder API, end-to-end wiring test, and documentation. The filtering behavior now matches the existing scrape-handler path, and CI is green.

@zeitlinger
zeitlinger enabled auto-merge (squash) July 28, 2026 14:33
@zeitlinger

zeitlinger commented Jul 28, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution!

@zeitlinger
zeitlinger merged commit 9b0ede8 into prometheus:main Jul 28, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants