Repository navigation
FastStream Prometheus: use the default registry and make the metrics path opt-in - #375
Merged
Merged
Conversation
This was referenced Oct 29, 2026
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.
Closes #321.
FastStream's Prometheus instrument now follows the same rule as FastAPI, Litestar and FastMCP: it serves
prometheus_client.REGISTRYand is configured by its path alone. The path now defaults to empty, so on FastStream the endpoint is opt-in.FastStreamConfigoverridesprometheus_metrics_path: str = "".FastStreamPrometheusInstrumentno longer overridesis_configuredor extendsnot_configured_reason. A config with no path is skipped with the base reason, "prometheus_metrics_path is empty or not valid".prometheus_collector_registry, the instrument usesprometheus_client.REGISTRY, and_make_collector_registryis gone.prometheus_collector_registryis still how you pass a private registry.A second bootstrap, or several brokers, on the global registry needs no reuse code. faststream's
MetricsContainerlooks up a collector in the registry before creating one, and it already did at our 0.6 floor (faststream/prometheus/container.pyin 0.6.0 and 0.7.8).Tests
Written first. These failed on main:
test_faststream_prometheus_is_skipped_without_metrics_path: withprometheus_middleware_clsset and no path, the instrument was configured.test_faststream_prometheus_serves_the_default_registry: with a path and neither a middleware nor a registry, the instrument was skipped. It now asserts thatcollector_registry is prometheus_client.REGISTRY, and that/metricsserves a counter registered on the default registry pluspython_infofrom the default platform collector.test_faststream_default_registry_takes_two_brokers_and_a_second_bootstrappins the multi-broker case from #299. It bootstraps two Redis brokers withRedisPrometheusMiddlewareon the default registry, twice in one process, and checks that each broker gets its middleware. It passed on main too, where every bootstrap built a fresh registry.These replace
test_faststream_prometheus_is_skipped_without_middleware_or_registry, which asserted the rule this PR removes.The full suite passes, 590 tests at 100% coverage (
just test-ci).just lint(includingty),just adr-checkandjust docs-buildpass too. No floor changes.Docs
configuration.md: the Prometheus intro notes the FastStream exception, and "Prometheus FastStream" describes the empty default and the default registry. The paragraph explaining the private registry is gone.faststream.md: the multiple-brokers example setsprometheus_metrics_path. Without it, under the new default, its Prometheus middleware would be skipped.Breaking changes
prometheus_middleware_cls,/metricsis no longer mounted and the broker middleware is no longer added until you setprometheus_metrics_path.