Skip to content

Commit bdf98ad

Browse files
authored
feat: rename inconsistent config fields, keeping the old names as deprecated aliases (#351)
* feat: rename inconsistent config fields, keeping the old names as deprecated aliases * docs: say which OpenAPIConfig arguments swagger_additional_params cannot repeat
1 parent d80ebc2 commit bdf98ad

17 files changed

Lines changed: 210 additions & 63 deletions

‎benchmarks/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ structlog 26.1.0. In-process, baseline 17.7 µs per request. The handler does no
200200
| scenario | +µs/req | note |
201201
|---|---:|---|
202202
| logging configured, no records | +0.1 | |
203-
| `fastapi_logging_middleware_enabled=True` | +18.3 | one access-log record per request, about 10 µs of it the record |
203+
| `logging_access_log_enabled=True` | +18.3 | one access-log record per request, about 10 µs of it the record |
204204
| Prometheus | +19.1 | |
205205
| OpenTelemetry, 100% sampling | +147.9 | |
206206
| OpenTelemetry, `opentelemetry_exclude_spans=["receive", "send"]` | +101.6 | -46.3 |
@@ -354,7 +354,7 @@ prometheus-client 0.26.0, structlog 26.1.0. In-process, baseline 12.1 µs per re
354354
|---|---:|---|
355355
| logging configured, no records | -0.1 | free until something logs |
356356
| logging, 3 structlog records in the handler | +33.8 | 11.3 µs per record |
357-
| `litestar_logging_middleware_enabled=True` | +70.7 | 2 records per request, each written twice; a second run gave +74.4 |
357+
| `logging_access_log_enabled=True` | +70.7 | 2 records per request, each written twice; a second run gave +74.4 |
358358
| Prometheus | +11.6 | |
359359
| Prometheus, `prometheus_group_path=False` | +11.8 | |
360360
| OpenTelemetry, 100% sampling | +145.4 | a second run gave +131.8 |
@@ -477,7 +477,7 @@ it FastMCP and the MCP SDK. Noise on this suite is about ±30 µs even with 3 re
477477
| scenario | +µs/call | note |
478478
|---|---:|---|
479479
| logging configured | +15 | noise |
480-
| `fastmcp_logging_middleware_enabled=True` | +51 | one record per MCP message |
480+
| `logging_access_log_enabled=True` | +51 | one record per MCP message |
481481
| Prometheus (HTTP instrumentator and tool-call middleware) | +35 | the split between the two is within noise |
482482
| OpenTelemetry, 100% | +272 | 3 ASGI spans plus FastMCP's own server span |
483483
| OpenTelemetry, 100%, FastMCP's own spans replaced by a no-op tracer | +226 | FastMCP's spans cost 46 |

‎benchmarks/frameworks/fastapi_suite.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
SCENARIOS: typing.Final = {
3232
"bare": Scenario(config=base_config()),
3333
"log": Scenario(config=base_config(**LOG)),
34-
"log_mw": Scenario(config=base_config(**LOG, fastapi_logging_middleware_enabled=True)),
34+
"log_mw": Scenario(config=base_config(**LOG, logging_access_log_enabled=True)),
3535
"prom": Scenario(config=base_config(**PROM)),
3636
"otel": Scenario(config=base_config(**OTEL)),
3737
"otel_excl": Scenario(config=base_config(**OTEL, **EXCL)),

‎benchmarks/frameworks/fastmcp_suite.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def no_fastmcp_spans() -> None:
4141
SCENARIOS: typing.Final = {
4242
"bare": Scenario(config=base_config()),
4343
"log": Scenario(config=base_config(**LOG)),
44-
"log_mw": Scenario(config=base_config(**LOG, fastmcp_logging_middleware_enabled=True)),
44+
"log_mw": Scenario(config=base_config(**LOG, logging_access_log_enabled=True)),
4545
"prom": Scenario(config=base_config(**PROM)),
4646
"otel": Scenario(config=base_config(**OTEL)),
4747
"otel_nofastmcp_spans": Scenario(config=base_config(**OTEL), patch=no_fastmcp_spans),

‎benchmarks/frameworks/litestar_suite.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"defaults_noobs": Scenario(config=base_config(**LITESTAR_DEFAULTS)),
4646
"log": Scenario(config=base_config(**LOG)),
4747
"log_log3": Scenario(config=base_config(**LOG), kind="structlog"),
48-
"log_mw": Scenario(config=base_config(**LOG, litestar_logging_middleware_enabled=True)),
48+
"log_mw": Scenario(config=base_config(**LOG, logging_access_log_enabled=True)),
4949
"prom": Scenario(config=base_config(**PROM)),
5050
"prom_nogroup": Scenario(config=base_config(**PROM, prometheus_group_path=False)),
5151
"otel": Scenario(config=base_config(**OTEL)),

‎docs/integrations/fastapi.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ place to add a log record. Turn it on explicitly:
5858
```python
5959
FastAPIConfig(
6060
service_name="microservice",
61-
fastapi_logging_middleware_enabled=True,
61+
logging_access_log_enabled=True,
6262
)
6363
```
6464

@@ -81,7 +81,7 @@ structured one, clear uvicorn's handlers:
8181
```python
8282
FastAPIConfig(
8383
service_name="microservice",
84-
fastapi_logging_middleware_enabled=True,
84+
logging_access_log_enabled=True,
8585
logging_unset_handlers=["uvicorn.access"],
8686
)
8787
```

‎docs/integrations/fastmcp.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ explicitly:
5555
```python
5656
FastMcpConfig(
5757
service_name="microservice",
58-
fastmcp_logging_middleware_enabled=True,
58+
logging_access_log_enabled=True,
5959
)
6060
```
6161

‎docs/integrations/litestar.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Swagger bundle into your logs. Turn it on explicitly:
6868
```python
6969
LitestarConfig(
7070
service_name="microservice",
71-
litestar_logging_middleware_enabled=True,
71+
logging_access_log_enabled=True,
7272
)
7373
```
7474

@@ -92,7 +92,7 @@ from litestar.middleware.logging import LoggingMiddlewareConfig
9292

9393
LitestarConfig(
9494
service_name="microservice",
95-
litestar_logging_middleware_enabled=True,
95+
logging_access_log_enabled=True,
9696
litestar_logging_middleware_config=LoggingMiddlewareConfig(request_log_fields=("path", "method", "content_type")),
9797
)
9898
```

‎docs/introduction/configuration.md‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ Prometheus's integration for FastAPI uses `prometheus_fastapi_instrumentator` pa
9393

9494
Additional parameters for FastAPI integration:
9595

96-
- `prometheus_instrumentator_params` - passed to `prometheus_fastapi_instrumentator.Instrumentator`
97-
- `prometheus_instrument_params` - passed to `method Instrumentator(...).instrument`
98-
- `prometheus_expose_params` - passed to `method Instrumentator(...).expose`.
96+
- `prometheus_instrumentator_additional_params` - passed to `prometheus_fastapi_instrumentator.Instrumentator`
97+
- `prometheus_instrument_additional_params` - passed to `method Instrumentator(...).instrument`
98+
- `prometheus_expose_additional_params` - passed to `method Instrumentator(...).expose`.
9999

100100
### Prometheus FastMCP
101101

@@ -110,9 +110,9 @@ route itself is not counted. Tool calls are counted in `fastmcp_tool_calls_total
110110

111111
Additional parameters for FastMCP integration:
112112

113-
- `prometheus_instrumentator_params` - passed to `prometheus_fastapi_instrumentator.Instrumentator`;
113+
- `prometheus_instrumentator_additional_params` - passed to `prometheus_fastapi_instrumentator.Instrumentator`;
114114
`excluded_handlers` defaults to the metrics route.
115-
- `prometheus_instrument_params` - passed to `method Instrumentator(...).instrument`.
115+
- `prometheus_instrument_additional_params` - passed to `method Instrumentator(...).instrument`.
116116
- `fastmcp_prometheus_tool_metrics_enabled` - count and time tool calls (default: `True`).
117117

118118

@@ -321,16 +321,16 @@ async def handler(request: Request) -> dict[str, str]:
321321

322322
Additional parameters for Litestar's access-log middleware:
323323

324-
- `litestar_logging_middleware_enabled` - turn on request/response access logging (default: `False`).
325-
- `litestar_logging_middleware_config` - a caller-supplied `LoggingMiddlewareConfig` that replaces the built-in defaults wholesale. It is ignored, with a warning, unless `litestar_logging_middleware_enabled` is `True`.
324+
- `logging_access_log_enabled` - turn on request/response access logging (default: `False`).
325+
- `litestar_logging_middleware_config` - a caller-supplied `LoggingMiddlewareConfig` that replaces the built-in defaults wholesale. It is ignored, with a warning, unless `logging_access_log_enabled` is `True`.
326326

327327
See [the Litestar integration guide](../integrations/litestar.md#logging) for what gets logged and why access logging defaults to off.
328328

329329
### Structlog FastAPI
330330

331331
FastAPI ships no access log of its own, so lite-bootstrap provides one. It is **off by default**:
332332

333-
- `fastapi_logging_middleware_enabled` - turn on the structured access log (default: `False`).
333+
- `logging_access_log_enabled` - turn on the structured access log (default: `False`).
334334

335335
See [the FastAPI integration guide](../integrations/fastapi.md#logging) for what gets logged and why
336336
it defaults to off.
@@ -339,7 +339,7 @@ it defaults to off.
339339

340340
The per-MCP-message access log is **off by default**:
341341

342-
- `fastmcp_logging_middleware_enabled` - turn on the access log (default: `False`).
342+
- `logging_access_log_enabled` - turn on the access log (default: `False`).
343343

344344
See [the FastMCP integration guide](../integrations/fastmcp.md#logging) for what gets logged.
345345

@@ -383,6 +383,7 @@ To bootstrap swagger, you have the following parameters:
383383
- `swagger_static_path` - path for offline docs static
384384
- `swagger_path`
385385
- `swagger_offline_docs` - option to turn on offline docs.
386+
- `swagger_additional_params` - Litestar only: extra keyword arguments for `litestar.openapi.OpenAPIConfig`. It cannot repeat `path`, `title`, `version`, `description` or `render_plugins`, which lite-bootstrap already passes.
386387

387388
Swagger is on by default at `swagger_path` (default: `/docs`). For Litestar, set `swagger_path` to an empty string to disable it.
388389

‎docs/introduction/performance.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ so there is nothing else material hiding in it. That configuration is:
5959
--8<-- "benchmarks/README.md:tuned"
6060

6161
One thing to leave off rather than turn on: the FastAPI access log
62-
([`fastapi_logging_middleware_enabled`](../integrations/fastapi.md#logging)) is off by default, and
62+
([`logging_access_log_enabled`](../integrations/fastapi.md#logging)) is off by default, and
6363
turning it on makes every request emit a log record. On a service that otherwise logs nothing per
6464
request, every request then pays the per-record cost measured here:
6565

@@ -102,7 +102,7 @@ The same app on Granian, over real sockets:
102102

103103
**Sentry costs more on Litestar than on FastAPI**, and all of it is `LitestarIntegration`: turning
104104
off auto-enabling integrations removes the cost and, with it, request error capture. The access log
105-
([`litestar_logging_middleware_enabled`](../integrations/litestar.md#logging)) is the other large opt-in
105+
([`logging_access_log_enabled`](../integrations/litestar.md#logging)) is the other large opt-in
106106
item, at about 70 µs per request in-process.
107107

108108
## FastStream

‎lite_bootstrap/bootstrappers/fastapi_bootstrapper.py‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import dataclasses
33
import time
44
import typing
5-
from collections.abc import AsyncGenerator
5+
from collections.abc import AsyncGenerator, Mapping
66

77
from lite_bootstrap import import_checker
88
from lite_bootstrap.bootstrappers.base import BaseBootstrapper
@@ -63,10 +63,27 @@ class FastAPIConfig(
6363
application_kwargs: dict[str, typing.Any] = dataclasses.field(default_factory=dict)
6464
# Not on OpenTelemetryConfig: only the FastAPI and Litestar instrumentors take `exclude_spans`.
6565
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)
7087

7188
def __post_init__(self) -> None:
7289
# @dataclass(slots=True) replaces the class object, breaking bare super().
@@ -158,7 +175,7 @@ async def send_wrapper(message: "Message") -> None:
158175
class FastAPILoggingInstrument(LoggingInstrument[FastAPIConfig]):
159176
def bootstrap(self) -> None:
160177
super().bootstrap()
161-
if not self.bootstrap_config.fastapi_logging_middleware_enabled:
178+
if not self.bootstrap_config.logging_access_log_enabled:
162179
return
163180
self.bootstrap_config.app.add_middleware(_AccessLogMiddleware, excluded_paths=self._build_excluded_paths())
164181

@@ -218,14 +235,14 @@ def dependencies_installed() -> bool:
218235
def bootstrap(self) -> None:
219236
config = self.bootstrap_config
220237
application = config.app
221-
Instrumentator(**config.prometheus_instrumentator_params).instrument(
238+
Instrumentator(**config.prometheus_instrumentator_additional_params).instrument(
222239
application,
223-
**config.prometheus_instrument_params,
240+
**config.prometheus_instrument_additional_params,
224241
).expose(
225242
application,
226243
endpoint=config.prometheus_metrics_path,
227244
include_in_schema=config.prometheus_metrics_include_in_schema,
228-
**config.prometheus_expose_params,
245+
**config.prometheus_expose_additional_params,
229246
)
230247

231248

0 commit comments

Comments
 (0)