Skip to content

Commit 5cef5b6

Browse files
authored
Merge pull request #28 from community-of-python/exclude-metrics-from-openapi-schema
Exclude `/metrics` from OpenAPI schema by default & allow to configure the exclusion
2 parents ad9e64e + 6bb2ccd commit 5cef5b6

File tree

4 files changed

+5
-0
lines changed

4 files changed

+5
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class YourFastApiSettings(FastApiSettings):
233233
service_name: str
234234

235235
prometheus_metrics_path: str = "/metrics"
236+
prometheus_metrics_include_in_schema: bool = False
236237
prometheus_instrumentator_params: dict[str, typing.Any] = {}
237238
prometheus_instrument_params: dict[str, typing.Any] = {}
238239
prometheus_expose_params: dict[str, typing.Any] = {}
@@ -244,6 +245,7 @@ Parameters description:
244245

245246
- `service_name` - will be attached to metric's names, but has to be named in [snake_case](https://en.wikipedia.org/wiki/Snake_case).
246247
- `prometheus_metrics_path` - path to metrics handler.
248+
- `prometheus_metrics_include_in_schema` - whether to include metrics route in OpenAPI schema.
247249
- `prometheus_instrumentator_params` - will be passed to `Instrumentor` during initialization.
248250
- `prometheus_instrument_params` - will be passed to `Instrumentor.instrument(...)`.
249251
- `prometheus_expose_params` - will be passed to `Instrumentor.expose(...)`.

microbootstrap/bootstrappers/fastapi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def bootstrap_after(self, application: fastapi.FastAPI) -> fastapi.FastAPI:
106106
).expose(
107107
application,
108108
endpoint=self.instrument_config.prometheus_metrics_path,
109+
include_in_schema=self.instrument_config.prometheus_metrics_include_in_schema,
109110
**self.instrument_config.prometheus_expose_params,
110111
)
111112
return application

microbootstrap/bootstrappers/litestar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class LitestarPrometheusInstrument(PrometheusInstrument[LitestarPrometheusConfig
124124
def bootstrap_before(self) -> dict[str, typing.Any]:
125125
class LitestarPrometheusController(PrometheusController):
126126
path = self.instrument_config.prometheus_metrics_path
127+
include_in_schema = self.instrument_config.prometheus_metrics_include_in_schema
127128
openmetrics_format = True
128129

129130
litestar_prometheus_config: typing.Final = PrometheusConfig(

microbootstrap/instruments/prometheus_instrument.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class BasePrometheusConfig(BaseInstrumentConfig):
1414
service_name: str = "micro-service"
1515

1616
prometheus_metrics_path: str = "/metrics"
17+
prometheus_metrics_include_in_schema: bool = False
1718

1819

1920
class LitestarPrometheusConfig(BasePrometheusConfig):

0 commit comments

Comments
 (0)