|
2 | 2 | import dataclasses |
3 | 3 | import time |
4 | 4 | import typing |
5 | | -from collections.abc import AsyncGenerator |
| 5 | +from collections.abc import AsyncGenerator, Mapping |
6 | 6 |
|
7 | 7 | from lite_bootstrap import import_checker |
8 | 8 | from lite_bootstrap.bootstrappers.base import BaseBootstrapper |
@@ -63,10 +63,27 @@ class FastAPIConfig( |
63 | 63 | application_kwargs: dict[str, typing.Any] = dataclasses.field(default_factory=dict) |
64 | 64 | # Not on OpenTelemetryConfig: only the FastAPI and Litestar instrumentors take `exclude_spans`. |
65 | 65 | opentelemetry_exclude_spans: list[typing.Literal["receive", "send"]] = dataclasses.field(default_factory=list) |
66 | | - prometheus_instrumentator_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict) |
67 | | - prometheus_instrument_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict) |
68 | | - prometheus_expose_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict) |
69 | | - fastapi_logging_middleware_enabled: bool = False |
| 66 | + prometheus_instrumentator_additional_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict) |
| 67 | + prometheus_instrument_additional_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict) |
| 68 | + prometheus_expose_additional_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict) |
| 69 | + logging_access_log_enabled: bool = False |
| 70 | + # Deprecated names, removed in 2.0. |
| 71 | + _renamed_fields: typing.ClassVar[Mapping[str, str]] = { |
| 72 | + "prometheus_instrumentator_params": "prometheus_instrumentator_additional_params", |
| 73 | + "prometheus_instrument_params": "prometheus_instrument_additional_params", |
| 74 | + "prometheus_expose_params": "prometheus_expose_additional_params", |
| 75 | + "fastapi_logging_middleware_enabled": "logging_access_log_enabled", |
| 76 | + } |
| 77 | + prometheus_instrumentator_params: dict[str, typing.Any] | UnsetType = dataclasses.field( |
| 78 | + default=UNSET, repr=False, compare=False |
| 79 | + ) |
| 80 | + prometheus_instrument_params: dict[str, typing.Any] | UnsetType = dataclasses.field( |
| 81 | + default=UNSET, repr=False, compare=False |
| 82 | + ) |
| 83 | + prometheus_expose_params: dict[str, typing.Any] | UnsetType = dataclasses.field( |
| 84 | + default=UNSET, repr=False, compare=False |
| 85 | + ) |
| 86 | + fastapi_logging_middleware_enabled: bool | UnsetType = dataclasses.field(default=UNSET, repr=False, compare=False) |
70 | 87 |
|
71 | 88 | def __post_init__(self) -> None: |
72 | 89 | # @dataclass(slots=True) replaces the class object, breaking bare super(). |
@@ -158,7 +175,7 @@ async def send_wrapper(message: "Message") -> None: |
158 | 175 | class FastAPILoggingInstrument(LoggingInstrument[FastAPIConfig]): |
159 | 176 | def bootstrap(self) -> None: |
160 | 177 | super().bootstrap() |
161 | | - if not self.bootstrap_config.fastapi_logging_middleware_enabled: |
| 178 | + if not self.bootstrap_config.logging_access_log_enabled: |
162 | 179 | return |
163 | 180 | self.bootstrap_config.app.add_middleware(_AccessLogMiddleware, excluded_paths=self._build_excluded_paths()) |
164 | 181 |
|
@@ -218,14 +235,14 @@ def dependencies_installed() -> bool: |
218 | 235 | def bootstrap(self) -> None: |
219 | 236 | config = self.bootstrap_config |
220 | 237 | application = config.app |
221 | | - Instrumentator(**config.prometheus_instrumentator_params).instrument( |
| 238 | + Instrumentator(**config.prometheus_instrumentator_additional_params).instrument( |
222 | 239 | application, |
223 | | - **config.prometheus_instrument_params, |
| 240 | + **config.prometheus_instrument_additional_params, |
224 | 241 | ).expose( |
225 | 242 | application, |
226 | 243 | endpoint=config.prometheus_metrics_path, |
227 | 244 | include_in_schema=config.prometheus_metrics_include_in_schema, |
228 | | - **config.prometheus_expose_params, |
| 245 | + **config.prometheus_expose_additional_params, |
229 | 246 | ) |
230 | 247 |
|
231 | 248 |
|
|
0 commit comments