Skip to content

Don't hard-code the global REGISTRY in PrometheusMetricReader #4713

@bcmills

Description

@bcmills

Is your feature request related to a problem?

The PrometheusMetricReader currently hard-codes use of the global REGISTRY instance. That makes it incompatible with programs that construct (and expect to use) a fresh CollectorRegistry for each test (for example, to check that the published metrics accurately reflect the calls expected to occur during the test).

Describe the solution you'd like

Ideally:

  • PrometheusMetricReader.__init__() should accept a keyword argument for the CollectorRegistry to use (still defaulting to the global REGISTRY), and
  • it should be possible to call metrics.set_meter_provider repeated in the same program to change the configured MeterProvider.

Describe alternatives you've considered

  • The program can currently monkey-patch opentelemetry.exporter.prometheus.REGISTRY prior to creating its PrometheusMetricsReader.
    • This approach is viable but extremely hacky.
  • Or, the user can refactor all of their tests to run each test that needs a fresh CollectorRegistry as a subprocess.
    • This approach is not viable, because it requires global refactoring to accommodate an arbitrary (local) design decision within the opentelemetry-python library.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions