Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -619,15 +619,15 @@ record per MCP message), FastStream's own "Received" and "Processed" (filtered a

Linux, a 2-CPU container on the same Apple M2 under OrbStack, CPython 3.14.9, structlog 26.1.0,
orjson 3.11.9, sentry-sdk 2.67.1, opentelemetry-sdk 1.44.0. Output to a real `/dev/null` file,
50000 calls per round, loop overhead (0.06 µs) subtracted.
50000 calls per round, loop overhead (0.06 µs) subtracted. The `MemoryHandler` was removed afterwards
(#377), and 2.0 writes through the `StreamHandler` directly; the rows have not been rerun.

| call | µs/call |
|---|---:|
| `log.info("did a thing", a=1)` through lite-bootstrap's chain | 9.5 |
| same with 5 keyword values | 10.4 |
| `log.debug(...)` at INFO, filtered | 1.1 |
| info, JSON through stdlib `json` (the fallback without orjson) | 11.5 |
| info, `logging_buffer_capacity=1` | 10.5 |
| info inside a recording OpenTelemetry span | 10.7 |
| info with Sentry's LoggingIntegration, breadcrumb level INFO (default) | 15.7 |
| info with Sentry, `sentry_logging_breadcrumb_level=None` | 10.5 |
Expand Down
4 changes: 1 addition & 3 deletions benchmarks/frameworks/logging_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class LogScenario:
span: bool = False
native: bool = False
stdlib_json: bool = False
buffer_capacity: int = 10


SCENARIOS: typing.Final = {
Expand All @@ -37,7 +36,6 @@ class LogScenario:
"info_kw5": LogScenario(call="info_kw5"),
"debug_filtered": LogScenario(call="debug"),
"info_stdjson": LogScenario(call="info", stdlib_json=True),
"info_capacity1": LogScenario(call="info", buffer_capacity=1),
"info_span": LogScenario(call="info", span=True),
"info_sentry": LogScenario(call="info", sentry={}),
"info_sentry_nocrumb": LogScenario(call="info", sentry={"sentry_logging_breadcrumb_level": None}),
Expand Down Expand Up @@ -113,7 +111,7 @@ def setup(scenario: LogScenario) -> list[typing.Callable[[], object]]:
configure_native(devnull_bytes)
elif scenario.call != "noop":
with contextlib.redirect_stdout(devnull):
config = LoggingConfig(logging_enabled=True, logging_buffer_capacity=scenario.buffer_capacity)
config = LoggingConfig(logging_enabled=True)
LoggingInstrument(bootstrap_config=config).bootstrap()

if scenario.sentry is not None:
Expand Down
1 change: 0 additions & 1 deletion docs/integrations/fastmcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ bootstrapper_config = FastMcpConfig(
sentry_dsn="https://testdsn@localhost/1",
prometheus_metrics_path="/custom-metrics/",
health_checks_path="/custom-health/",
logging_buffer_capacity=0,
)
bootstrapper = FastMcpBootstrapper(bootstrap_config=bootstrapper_config)
application: FastMCP = bootstrapper.bootstrap()
Expand Down
1 change: 0 additions & 1 deletion docs/integrations/faststream.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ bootstrapper_config = FastStreamConfig(
prometheus_middleware_cls=RedisPrometheusMiddleware,
sentry_dsn="https://testdsn@localhost/1",
health_checks_path="/custom-health/",
logging_buffer_capacity=0,
application=AsgiFastStream(broker),
)
bootstrapper = FastStreamBootstrapper(bootstrapper_config)
Expand Down
2 changes: 0 additions & 2 deletions docs/introduction/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,6 @@ Additional parameters:

- `logging_enabled` - whether to configure structlog (default: `True`).
- `logging_log_level`
- `logging_flush_level`
- `logging_buffer_capacity`
- `logging_extra_processors`
- `logging_unset_handlers`
- `logging_record_filters` - standard-library `logging.Filter` instances to attach to named loggers (see below).
Expand Down
17 changes: 3 additions & 14 deletions lite_bootstrap/instruments/logging_factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import dataclasses
import json
import logging
import logging.handlers
import sys
import typing

Expand All @@ -14,8 +13,6 @@

@dataclasses.dataclass(kw_only=True, slots=True, frozen=True)
class _MemoryLoggerFactoryConfig:
logging_buffer_capacity: int
logging_flush_level: int
logging_log_level: int
# default_factory, not a bare default: a bare one binds sys.stdout at import time, so a
# process that rebinds stdout before bootstrap would keep logging to the stale stream.
Expand Down Expand Up @@ -102,20 +99,15 @@ def __init__(
kwargs["ignore_frame_names"] = [*(kwargs.get("ignore_frame_names") or ()), __name__]
super().__init__(*args, **kwargs)
self.config = config
self._created_handlers: dict[logging.Logger, logging.handlers.MemoryHandler] = {}
self._created_handlers: dict[logging.Logger, logging.StreamHandler[typing.Any]] = {}
self._leveled_loggers: set[logging.Logger] = set()

def __call__(self, *args: typing.Any) -> logging.Logger: # noqa: ANN401
logger: typing.Final = super().__call__(*args)
if logger in self._created_handlers:
return logger
stream_handler: typing.Final = logging.StreamHandler(stream=self.config.log_stream)
stream_handler.setFormatter(_RenderedLineFormatter())
handler: typing.Final = logging.handlers.MemoryHandler(
capacity=self.config.logging_buffer_capacity,
flushLevel=self.config.logging_flush_level,
target=stream_handler,
)
handler: typing.Final = logging.StreamHandler(stream=self.config.log_stream)
handler.setFormatter(_RenderedLineFormatter())
logger.addHandler(handler)
if logger.level == logging.NOTSET:
logger.setLevel(self.config.logging_log_level)
Expand All @@ -130,9 +122,6 @@ def close_handlers(self) -> None:
created_logger.propagate = True
if created_logger in self._leveled_loggers:
created_logger.setLevel(logging.NOTSET)
target = handler.target
handler.close()
if target is not None:
target.close()
self._created_handlers.clear()
self._leveled_loggers.clear()
4 changes: 0 additions & 4 deletions lite_bootstrap/instruments/logging_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ def tracer_injection(_: "WrappedLogger", __: str, event_dict: "EventDict") -> "E
@dataclasses.dataclass(kw_only=True, frozen=True)
class LoggingConfig(BaseConfig):
logging_log_level: int = logging.INFO
logging_flush_level: int = logging.ERROR
logging_buffer_capacity: int = 10
logging_extra_processors: list[typing.Any] = dataclasses.field(default_factory=list)
logging_unset_handlers: list[str] = dataclasses.field(
default_factory=list,
Expand Down Expand Up @@ -150,8 +148,6 @@ def memory_logger_factory(self) -> "MemoryLoggerFactory":
config = self.bootstrap_config
cached = MemoryLoggerFactory(
config=_MemoryLoggerFactoryConfig(
logging_buffer_capacity=config.logging_buffer_capacity,
logging_flush_level=config.logging_flush_level,
logging_log_level=config.logging_log_level,
),
)
Expand Down
8 changes: 0 additions & 8 deletions scripts/floor_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ def _free() -> None:
service_name="floor-smoke",
service_version="1.0.0",
service_environment="test",
logging_buffer_capacity=0,
sentry_dsn=SENTRY_DSN,
sentry_additional_params=SENTRY_PARAMS,
sentry_tags={"floor": "smoke"},
Expand Down Expand Up @@ -170,7 +169,6 @@ async def floor_error() -> None:
bootstrap_config=FastAPIConfig(
service_name="floor-smoke",
service_version="1.0.0",
logging_buffer_capacity=0,
sentry_dsn=SENTRY_DSN,
sentry_additional_params=SENTRY_PARAMS,
application=application,
Expand All @@ -189,7 +187,6 @@ def _fastapi() -> None:
service_name="floor-smoke",
service_version="1.0.0",
service_debug=False,
logging_buffer_capacity=0,
cors_allowed_origins=["http://test"],
health_checks_path=HEALTH_PATH,
health_checks_include_in_schema=True,
Expand Down Expand Up @@ -225,7 +222,6 @@ async def floor_error() -> None:
service_name="floor-smoke",
service_version="1.0.0",
service_debug=False,
logging_buffer_capacity=0,
sentry_dsn=SENTRY_DSN,
sentry_additional_params=SENTRY_PARAMS,
application_config=AppConfig(route_handlers=[floor_error]),
Expand All @@ -244,7 +240,6 @@ def _litestar() -> None:
service_name="floor-smoke",
service_version="1.0.0",
service_debug=False,
logging_buffer_capacity=0,
cors_allowed_origins=["http://test"],
health_checks_path=HEALTH_PATH,
sentry_dsn=SENTRY_DSN,
Expand All @@ -267,7 +262,6 @@ def _faststream() -> None:
bootstrap_config=FastStreamConfig(
service_name="floor-smoke",
service_version="1.0.0",
logging_buffer_capacity=0,
health_checks_path=HEALTH_PATH,
sentry_dsn=SENTRY_DSN,
sentry_additional_params=SENTRY_PARAMS,
Expand All @@ -290,7 +284,6 @@ def _fastmcp_lean_sentry_capture() -> None:
bootstrap_config=FastMcpConfig(
service_name="floor-smoke",
service_version="1.0.0",
logging_buffer_capacity=0,
sentry_dsn=SENTRY_DSN,
sentry_additional_params=SENTRY_PARAMS,
)
Expand All @@ -314,7 +307,6 @@ def _fastmcp() -> None:
bootstrap_config=FastMcpConfig(
service_name="floor-smoke",
service_version="1.0.0",
logging_buffer_capacity=0,
health_checks_path=HEALTH_PATH,
sentry_dsn=SENTRY_DSN,
sentry_additional_params=SENTRY_PARAMS,
Expand Down
1 change: 0 additions & 1 deletion scripts/ft_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def main() -> None:
bootstrap_config=FastAPIConfig(
service_name="ft-smoke",
service_debug=False,
logging_buffer_capacity=0,
health_checks_path="/health/",
)
)
Expand Down
Loading
Loading