Skip to content

fix: make PrometheusMiddleware import-safe (fix #397) - #682

Open
vineoy wants to merge 1 commit into
taskiq-python:masterfrom
vineoy:fix/prometheus-duplicate-timeseries-397
Open

vineoy wants to merge 1 commit into
taskiq-python:masterfrom
vineoy:fix/prometheus-duplicate-timeseries-397

Conversation

@vineoy

@vineoy vineoy commented Sep 24, 2026

Copy link
Copy Markdown

Closes #397, relates #173.

Second PrometheusMiddleware() in the same process (e.g. broker module imported twice during --fs-discover) now reuses already-registered REGISTRY collectors instead of raising ValueError: Duplicated timeseries in CollectorRegistry.

Changes:

  • taskiq/middlewares/prometheus_middleware.py: get-or-create Counter/Histogram helpers + docstring fix
  • tests/middlewares/test_prometheus_middleware.py: regression for double instantiation and metric inc

Verified: new tests 2 passed, middlewares+cli 83 passed, full suite 370 passed (1 unrelated flaky opentelemetry test passes in isolation), ruff/black/mypy clean.

…eries

Creating multiple instances in the same process (e.g. when broker module is imported more than once during fs-discover) now reuses already registered collectors instead of raising ValueError: Duplicated timeseries in CollectorRegistry.

Closes taskiq-python#397, relates taskiq-python#173

This branch has not been deployed

No deployments
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.

How to split the tasks into different modules without PrometheusMiddleware crashing the worker

1 participant