otelconf: register Prometheus reader with a MeterProvider in tests - #9475
Open
pujitha24 wants to merge 4 commits into
Open
otelconf: register Prometheus reader with a MeterProvider in tests#9475pujitha24 wants to merge 4 commits into
pujitha24 wants to merge 4 commits into
Conversation
Motivation: TestPrometheusIPv6 and TestPrometheusReaderConfigurationOptions in otelconf/v0.2.0 and otelconf/v0.3.0 call prometheusReader() directly to build a Prometheus-backed sdkmetric.Reader and then scrape its /metrics endpoint over HTTP, without ever registering the reader with an sdkmetric.MeterProvider. Because the reader is never registered, scraping triggers a "reader is not registered" error from the SDK, which the default global error handler logs to stderr. The tests still pass, but they print noisy, misleading error output on every run. Approach: Wrap the reader in sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader)) before scraping /metrics, and shut the MeterProvider down (which transitively shuts down the registered reader) instead of calling reader.Shutdown directly. This mirrors the existing pattern already used by TestPrometheusReaderDotStyleLabels in the same files. TestPrometheusReaderHostParsing was left untouched since it never scrapes /metrics and never triggered the warning. This is a test-only change; no production code or behavior is affected. Validation: Ran `go build ./...`, `go vet ./...`, and `go test ./... -race` in both otelconf/v0.2.0 and otelconf/v0.3.0 (all pass), and `golangci-lint run ./...` in both directories (0 issues). Confirmed via `go test ./... -v 2>&1 | grep -i "reader is not registered"` that the warning no longer appears in either module's test output, whereas it was present before this change. Report: open-telemetry#7641 Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
The changelog CI check requires every PR touch CHANGELOG.md unless it carries a "[chore]" title prefix or the "Skip Changelog" label. Add a Fixed entry for the otelconf Prometheus reader test fix to satisfy the check. Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9475 +/- ##
=====================================
Coverage 84.5% 84.5%
=====================================
Files 203 203
Lines 16805 16805
=====================================
+ Hits 14204 14215 +11
+ Misses 2121 2110 -11
Partials 480 480 🚀 New features to boost your workflow:
|
dashpole
reviewed
Aug 14, 2026
|
|
||
| // Register the reader with a MeterProvider so that scraping | ||
| // /metrics below does not log a "reader is not registered" error. | ||
| mp := sdkmetric.NewMeterProvider(sdkmetric.WithReader(rs)) |
Contributor
There was a problem hiding this comment.
Looks like TestPrometheusIPv6 in otelconf/x/metric_test.go has the same pattern and still logs this warning. Should we update that test as well?
| - Report `ot-baggage-*` extraction errors from `go.opentelemetry.io/contrib/propagators/ot` to `otel.Handle` instead of silently discarding them, while still attaching the successfully parsed baggage members to the context. (#9395) | ||
| - Set `error.type` on the `rpc.client.call.duration` and `rpc.server.call.duration` metrics in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` when the RPC fails with a non-OK status, per the RPC semantic conventions. (#9429) | ||
| - Reject OTLP exporter headers with an empty `name` in `go.opentelemetry.io/contrib/otelconf`, `go.opentelemetry.io/contrib/otelconf/x`, and `go.opentelemetry.io/contrib/otelconf/v0.3.0`, instead of forwarding invalid header names to OTLP exporters. (#9102) | ||
| - Register the Prometheus reader with a `sdkmetric.MeterProvider` in the `go.opentelemetry.io/contrib/otelconf` and `go.opentelemetry.io/contrib/otelconf/v0.3.0` test suites, removing a noisy "reader is not registered" error logged to stderr during test runs. (#9475) |
Contributor
There was a problem hiding this comment.
A changelog is not needed for this
…usIPv6 Also drop the changelog entry per review feedback (not needed for a test-only change). Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
iblancasa
reviewed
Aug 17, 2026
Comment on lines
+1620
to
+1621
| // Register the reader with a MeterProvider so that scraping | ||
| // /metrics below does not log a "reader is not registered" error. |
Member
There was a problem hiding this comment.
I don't think these comments are needed
Per review feedback, remove the explanatory comment restating that registering the reader with a MeterProvider avoids a "reader is not registered" log during scraping. Applied to all three instances added by this PR, not just the one flagged inline. Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
TestPrometheusIPv6 and TestPrometheusReaderConfigurationOptions in
otelconf/v0.2.0 and otelconf/v0.3.0 call prometheusReader() directly
to build a Prometheus-backed sdkmetric.Reader and then scrape its
/metrics endpoint over HTTP, without ever registering the reader with
an sdkmetric.MeterProvider. Because the reader is never registered,
scraping triggers a "reader is not registered" error from the SDK,
which the default global error handler logs to stderr. The tests still
pass, but they print noisy, misleading error output on every run.
Approach:
Wrap the reader in sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader))
before scraping /metrics, and shut the MeterProvider down (which
transitively shuts down the registered reader) instead of calling
reader.Shutdown directly. This mirrors the existing pattern already
used by TestPrometheusReaderDotStyleLabels in the same files.
TestPrometheusReaderHostParsing was left untouched since it never
scrapes /metrics and never triggered the warning.
This is a test-only change; no production code or behavior is
affected.
Validation:
Ran
go build ./...,go vet ./..., andgo test ./... -racein bothotelconf/v0.2.0 and otelconf/v0.3.0 (all pass), and
golangci-lint run ./...in both directories (0 issues). Confirmed viago test ./... -v 2>&1 | grep -i "reader is not registered"that thewarning no longer appears in either module's test output, whereas it
was present before this change.
Report: #7641
Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com
Fixes #7641