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
8 changes: 4 additions & 4 deletions lite_bootstrap/bootstrappers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
InstrumentDependencyMissingWarning,
collect_teardown_errors,
)
from lite_bootstrap.instruments.base import BaseConfig, BaseInstrument
from lite_bootstrap.instruments.base import BaseInstrument, ConfigT
from lite_bootstrap.types import ApplicationT


Expand All @@ -19,20 +19,20 @@
InstrumentT = typing.TypeVar("InstrumentT", bound=BaseInstrument)


class BaseBootstrapper(abc.ABC, typing.Generic[ApplicationT]):
class BaseBootstrapper(abc.ABC, typing.Generic[ApplicationT, ConfigT]):
instruments_types: typing.ClassVar[list[type[BaseInstrument]]]
not_ready_message: typing.ClassVar[str]
instruments: list[BaseInstrument]
skipped_instruments: list[tuple[type[BaseInstrument], str]]
bootstrap_config: BaseConfig
bootstrap_config: ConfigT
_application: ApplicationT

# Marker tagged on a user-supplied app (or its config) once this bootstrapper has
# attached its teardown to the framework's shutdown lifecycle. Prevents a second
# bootstrapper on the same app from re-attaching. Its accepted limits: ADR-0003.
_TEARDOWN_MARKER: typing.ClassVar[str] = "_lite_bootstrap_teardown_attached"

def __init__(self, bootstrap_config: BaseConfig) -> None:
def __init__(self, bootstrap_config: ConfigT) -> None:
self.is_bootstrapped = False
self._torn_down = False
# Set when another bootstrapper already owns this application; bootstrap() then refuses.
Expand Down
3 changes: 1 addition & 2 deletions lite_bootstrap/bootstrappers/fastapi_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def bootstrap(self) -> None:
enable_offline_docs(application, static_path=config.swagger_static_path)


class FastAPIBootstrapper(BaseBootstrapper["fastapi.FastAPI"]):
class FastAPIBootstrapper(BaseBootstrapper["fastapi.FastAPI", FastAPIConfig]):
__slots__ = "bootstrap_config", "instruments"

instruments_types: typing.ClassVar = [
Expand All @@ -284,7 +284,6 @@ class FastAPIBootstrapper(BaseBootstrapper["fastapi.FastAPI"]):
FastAPIPrometheusInstrument,
FastAPISwaggerInstrument,
]
bootstrap_config: FastAPIConfig # ty: ignore[invalid-mutable-override]
not_ready_message = "fastapi is not installed"

@contextlib.asynccontextmanager
Expand Down
3 changes: 1 addition & 2 deletions lite_bootstrap/bootstrappers/fastmcp_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def bootstrap(self) -> None:
self.bootstrap_config.application.add_middleware(FastMcpLoggingMiddleware())


class FastMcpBootstrapper(BaseBootstrapper["FastMCP[typing.Any]"]):
class FastMcpBootstrapper(BaseBootstrapper["FastMCP[typing.Any]", FastMcpConfig]):
__slots__ = "bootstrap_config", "instruments"

instruments_types: typing.ClassVar = [
Expand All @@ -392,7 +392,6 @@ class FastMcpBootstrapper(BaseBootstrapper["FastMCP[typing.Any]"]):
FastMcpLoggingInstrument,
FastMcpPrometheusInstrument,
]
bootstrap_config: FastMcpConfig # ty: ignore[invalid-mutable-override]
not_ready_message = "fastmcp is not installed"

def is_ready(self) -> bool:
Expand Down
3 changes: 1 addition & 2 deletions lite_bootstrap/bootstrappers/faststream_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def bootstrap(self) -> None:
broker.add_middleware(middleware_cls(registry=self.collector_registry))


class FastStreamBootstrapper(BaseBootstrapper["AsgiFastStream"]):
class FastStreamBootstrapper(BaseBootstrapper["AsgiFastStream", FastStreamConfig]):
__slots__ = "bootstrap_config", "instruments"

instruments_types: typing.ClassVar = [
Expand All @@ -233,7 +233,6 @@ class FastStreamBootstrapper(BaseBootstrapper["AsgiFastStream"]):
FastStreamLoggingInstrument,
FastStreamPrometheusInstrument,
]
bootstrap_config: FastStreamConfig # ty: ignore[invalid-mutable-override]
not_ready_message = "faststream is not installed"

def is_ready(self) -> bool:
Expand Down
3 changes: 1 addition & 2 deletions lite_bootstrap/bootstrappers/free_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class FreeConfig(LoggingConfig, OpenTelemetryConfig, PyroscopeConfig, SentryConfig): ...


class FreeBootstrapper(BaseBootstrapper[None]):
class FreeBootstrapper(BaseBootstrapper[None, FreeConfig]):
__slots__ = "bootstrap_config", "instruments"

instruments_types: typing.ClassVar = [
Expand All @@ -21,7 +21,6 @@ class FreeBootstrapper(BaseBootstrapper[None]):
OpenTelemetryInstrument,
PyroscopeInstrument,
]
bootstrap_config: FreeConfig # ty: ignore[invalid-mutable-override]
not_ready_message = ""

def is_ready(self) -> bool:
Expand Down
3 changes: 1 addition & 2 deletions lite_bootstrap/bootstrappers/litestar_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def bootstrap(self) -> None:
)


class LitestarBootstrapper(BaseBootstrapper["litestar.Litestar"]):
class LitestarBootstrapper(BaseBootstrapper["litestar.Litestar", LitestarConfig]):
__slots__ = "bootstrap_config", "instruments"

instruments_types: typing.ClassVar = [
Expand All @@ -492,7 +492,6 @@ class LitestarBootstrapper(BaseBootstrapper["litestar.Litestar"]):
LitestarPrometheusInstrument,
LitestarSwaggerInstrument,
]
bootstrap_config: LitestarConfig # ty: ignore[invalid-mutable-override]
not_ready_message = "litestar is not installed"

def __init__(self, bootstrap_config: LitestarConfig) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/instruments/test_logging_record_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def test_bootstrap_teardown_bootstrap_attaches_each_filter_once() -> None:

BootstrapperBuilder = typing.Callable[
[dict[str, tuple[logging.Filter, ...]]],
BaseBootstrapper[typing.Any],
BaseBootstrapper[typing.Any, typing.Any],
]


Expand Down
Loading