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
3 changes: 2 additions & 1 deletion lite_bootstrap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from lite_bootstrap.bootstrappers.fastapi_bootstrapper import FastAPIBootstrapper, FastAPIConfig
from lite_bootstrap.bootstrappers.faststream_bootstrapper import FastStreamBootstrapper, FastStreamConfig
from lite_bootstrap.bootstrappers.free_bootstrapper import FreeBootstrapper, FreeBootstrapperConfig
from lite_bootstrap.bootstrappers.free_bootstrapper import FreeBootstrapper, FreeBootstrapperConfig, FreeConfig
from lite_bootstrap.bootstrappers.litestar_bootstrapper import LitestarBootstrapper, LitestarConfig
from lite_bootstrap.exceptions import (
BootstrapperNotReadyError,
Expand All @@ -23,6 +23,7 @@
"FastStreamConfig",
"FreeBootstrapper",
"FreeBootstrapperConfig",
"FreeConfig",
"InstrumentDependencyMissingWarning",
"InstrumentNotReadyWarning",
"InstrumentSkippedWarning",
Expand Down
4 changes: 2 additions & 2 deletions lite_bootstrap/bootstrappers/fastapi_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
HealthCheckTypedDict,
)
from lite_bootstrap.instruments.logging_instrument import LoggingConfig, LoggingInstrument
from lite_bootstrap.instruments.opentelemetry_instrument import OpentelemetryConfig, OpenTelemetryInstrument
from lite_bootstrap.instruments.opentelemetry_instrument import OpenTelemetryConfig, OpenTelemetryInstrument
from lite_bootstrap.instruments.prometheus_instrument import PrometheusConfig, PrometheusInstrument
from lite_bootstrap.instruments.pyroscope_instrument import PyroscopeConfig, PyroscopeInstrument
from lite_bootstrap.instruments.sentry_instrument import SentryConfig, SentryInstrument
Expand Down Expand Up @@ -42,7 +42,7 @@ class FastAPIConfig(
CorsConfig,
HealthChecksConfig,
LoggingConfig,
OpentelemetryConfig,
OpenTelemetryConfig,
PrometheusConfig,
PyroscopeConfig,
SentryConfig,
Expand Down
4 changes: 2 additions & 2 deletions lite_bootstrap/bootstrappers/faststream_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from lite_bootstrap.bootstrappers.base import BaseBootstrapper
from lite_bootstrap.instruments.healthchecks_instrument import HealthChecksConfig, HealthChecksInstrument
from lite_bootstrap.instruments.logging_instrument import LoggingConfig, LoggingInstrument
from lite_bootstrap.instruments.opentelemetry_instrument import OpentelemetryConfig, OpenTelemetryInstrument
from lite_bootstrap.instruments.opentelemetry_instrument import OpenTelemetryConfig, OpenTelemetryInstrument
from lite_bootstrap.instruments.prometheus_instrument import PrometheusConfig, PrometheusInstrument
from lite_bootstrap.instruments.pyroscope_instrument import PyroscopeConfig, PyroscopeInstrument
from lite_bootstrap.instruments.sentry_instrument import SentryConfig, SentryInstrument
Expand Down Expand Up @@ -62,7 +62,7 @@ def _make_asgi_faststream() -> "AsgiFastStream":

@dataclasses.dataclass(kw_only=True, slots=True, frozen=True)
class FastStreamConfig(
HealthChecksConfig, LoggingConfig, OpentelemetryConfig, PrometheusConfig, PyroscopeConfig, SentryConfig
HealthChecksConfig, LoggingConfig, OpenTelemetryConfig, PrometheusConfig, PyroscopeConfig, SentryConfig
):
application: "AsgiFastStream" = dataclasses.field(default_factory=_make_asgi_faststream)
opentelemetry_middleware_cls: type[FastStreamTelemetryMiddlewareProtocol] | None = None
Expand Down
12 changes: 8 additions & 4 deletions lite_bootstrap/bootstrappers/free_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

from lite_bootstrap.bootstrappers.base import BaseBootstrapper
from lite_bootstrap.instruments.logging_instrument import LoggingConfig, LoggingInstrument
from lite_bootstrap.instruments.opentelemetry_instrument import OpentelemetryConfig, OpenTelemetryInstrument
from lite_bootstrap.instruments.opentelemetry_instrument import OpenTelemetryConfig, OpenTelemetryInstrument
from lite_bootstrap.instruments.pyroscope_instrument import PyroscopeConfig, PyroscopeInstrument
from lite_bootstrap.instruments.sentry_instrument import SentryConfig, SentryInstrument


@dataclasses.dataclass(kw_only=True, slots=True, frozen=True)
class FreeBootstrapperConfig(LoggingConfig, OpentelemetryConfig, PyroscopeConfig, SentryConfig): ...
class FreeConfig(LoggingConfig, OpenTelemetryConfig, PyroscopeConfig, SentryConfig): ...


class FreeBootstrapper(BaseBootstrapper[None]):
Expand All @@ -21,14 +21,18 @@ class FreeBootstrapper(BaseBootstrapper[None]):
OpenTelemetryInstrument,
PyroscopeInstrument,
]
bootstrap_config: FreeBootstrapperConfig
bootstrap_config: FreeConfig
not_ready_message = ""

def is_ready(self) -> bool:
return True

def __init__(self, bootstrap_config: FreeBootstrapperConfig) -> None:
def __init__(self, bootstrap_config: FreeConfig) -> None:
super().__init__(bootstrap_config)

def _prepare_application(self) -> None:
return None


# Backward-compatible alias preserved for users importing the old name.
FreeBootstrapperConfig = FreeConfig
4 changes: 2 additions & 2 deletions lite_bootstrap/bootstrappers/litestar_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
HealthCheckTypedDict,
)
from lite_bootstrap.instruments.logging_instrument import LoggingConfig, LoggingInstrument
from lite_bootstrap.instruments.opentelemetry_instrument import OpentelemetryConfig, OpenTelemetryInstrument
from lite_bootstrap.instruments.opentelemetry_instrument import OpenTelemetryConfig, OpenTelemetryInstrument
from lite_bootstrap.instruments.prometheus_instrument import (
PrometheusConfig as PrometheusBootstrapperConfig,
)
Expand Down Expand Up @@ -104,7 +104,7 @@ class LitestarConfig(
CorsConfig,
HealthChecksConfig,
LoggingConfig,
OpentelemetryConfig,
OpenTelemetryConfig,
PrometheusBootstrapperConfig,
PyroscopeConfig,
SentryConfig,
Expand Down
8 changes: 6 additions & 2 deletions lite_bootstrap/instruments/opentelemetry_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class OpenTelemetryServiceFieldsConfig(BaseConfig):


@dataclasses.dataclass(kw_only=True, frozen=True)
class OpentelemetryConfig(OpenTelemetryServiceFieldsConfig):
class OpenTelemetryConfig(OpenTelemetryServiceFieldsConfig):
opentelemetry_container_name: str | None = dataclasses.field(
default_factory=lambda: os.environ.get("HOSTNAME") or None
)
Expand Down Expand Up @@ -78,7 +78,7 @@ def force_flush(self, timeout_millis: int = 30000) -> bool: # pragma: no cover


@dataclasses.dataclass(kw_only=True, slots=True)
class OpenTelemetryInstrument(BaseInstrument[OpentelemetryConfig]):
class OpenTelemetryInstrument(BaseInstrument[OpenTelemetryConfig]):
not_ready_message = "opentelemetry_endpoint is empty and opentelemetry_log_traces is False"
missing_dependency_message = "opentelemetry is not installed"
_tracer_provider: "TracerProvider | None" = dataclasses.field(
Expand Down Expand Up @@ -153,3 +153,7 @@ def teardown(self) -> None:
self._tracer_provider.shutdown()
finally:
self._tracer_provider = None


# Backward-compatible alias preserved for users importing the old (lowercase t) spelling.
OpentelemetryConfig = OpenTelemetryConfig
4 changes: 2 additions & 2 deletions tests/instruments/test_logging_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from lite_bootstrap.instruments.logging_factory import _MemoryLoggerFactoryConfig
from lite_bootstrap.instruments.logging_instrument import LoggingConfig, LoggingInstrument, MemoryLoggerFactory
from lite_bootstrap.instruments.opentelemetry_instrument import OpentelemetryConfig, OpenTelemetryInstrument
from lite_bootstrap.instruments.opentelemetry_instrument import OpenTelemetryConfig, OpenTelemetryInstrument
from tests.conftest import LoggingMock


Expand Down Expand Up @@ -51,7 +51,7 @@ def test_logging_instrument_tracer_injection(logging_mock: LoggingMock) -> None:
)
)
opentelemetry_instrument = OpenTelemetryInstrument(
bootstrap_config=OpentelemetryConfig(
bootstrap_config=OpenTelemetryConfig(
opentelemetry_log_traces=True,
)
)
Expand Down
10 changes: 5 additions & 5 deletions tests/instruments/test_opentelemetry_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

from lite_bootstrap.instruments.opentelemetry_instrument import (
InstrumentorWithParams,
OpentelemetryConfig,
OpenTelemetryConfig,
OpenTelemetryInstrument,
)
from tests.conftest import CustomInstrumentor


def test_opentelemetry_instrument() -> None:
opentelemetry_instrument = OpenTelemetryInstrument(
bootstrap_config=OpentelemetryConfig(
bootstrap_config=OpenTelemetryConfig(
opentelemetry_instrumentors=[
InstrumentorWithParams(instrumentor=CustomInstrumentor(), additional_params={"key": "value"}),
CustomInstrumentor(),
Expand All @@ -28,7 +28,7 @@ def test_opentelemetry_instrument() -> None:

def test_opentelemetry_instrument_empty_instruments() -> None:
opentelemetry_instrument = OpenTelemetryInstrument(
bootstrap_config=OpentelemetryConfig(
bootstrap_config=OpenTelemetryConfig(
opentelemetry_log_traces=True,
)
)
Expand All @@ -40,7 +40,7 @@ def test_opentelemetry_instrument_empty_instruments() -> None:

def test_opentelemetry_instrument_teardown_shuts_down_tracer_provider() -> None:
instrument = OpenTelemetryInstrument(
bootstrap_config=OpentelemetryConfig(opentelemetry_log_traces=True),
bootstrap_config=OpenTelemetryConfig(opentelemetry_log_traces=True),
)
instrument.bootstrap()
tracer_provider = instrument._tracer_provider # noqa: SLF001
Expand All @@ -55,7 +55,7 @@ def test_opentelemetry_instrument_teardown_shuts_down_tracer_provider() -> None:

def test_opentelemetry_instrument_teardown_resets_tracer_provider_when_shutdown_raises() -> None:
instrument = OpenTelemetryInstrument(
bootstrap_config=OpentelemetryConfig(opentelemetry_log_traces=True),
bootstrap_config=OpenTelemetryConfig(opentelemetry_log_traces=True),
)
instrument.bootstrap()
tracer_provider = instrument._tracer_provider # noqa: SLF001
Expand Down
8 changes: 4 additions & 4 deletions tests/instruments/test_pyroscope_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter

import lite_bootstrap.instruments.opentelemetry_instrument as otel_module
from lite_bootstrap import FreeBootstrapperConfig
from lite_bootstrap import FreeConfig
from lite_bootstrap.instruments.opentelemetry_instrument import OpenTelemetryInstrument
from lite_bootstrap.instruments.pyroscope_instrument import PyroscopeConfig, PyroscopeInstrument

Expand Down Expand Up @@ -52,7 +52,7 @@ def test_pyroscope_instrument_bootstrap_and_teardown() -> None:


def test_pyroscope_bootstrap_uses_opentelemetry_service_name() -> None:
config = FreeBootstrapperConfig(
config = FreeConfig(
service_name="fallback",
pyroscope_endpoint="http://pyroscope:4040",
opentelemetry_service_name="otel-name",
Expand All @@ -78,7 +78,7 @@ def test_pyroscope_standalone_config_accepts_otel_fields() -> None:


def test_pyroscope_bootstrap_merges_namespace_tag() -> None:
config = FreeBootstrapperConfig(
config = FreeConfig(
service_name="svc",
pyroscope_endpoint="http://pyroscope:4040",
pyroscope_tags={"env": "prod"},
Expand Down Expand Up @@ -165,7 +165,7 @@ def test_pyroscope_span_processor_on_start_remote_parent() -> None:

def test_pyroscope_otel_adds_span_processor_when_configured() -> None:
"""OTel instrument adds PyroscopeSpanProcessor when pyroscope_endpoint is set."""
config = FreeBootstrapperConfig(
config = FreeConfig(
service_name="test-svc",
opentelemetry_log_traces=True,
pyroscope_endpoint="http://pyroscope:4040",
Expand Down
18 changes: 9 additions & 9 deletions tests/test_free_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from lite_bootstrap import (
FreeBootstrapper,
FreeBootstrapperConfig,
FreeConfig,
InstrumentNotReadyWarning,
TeardownError,
)
Expand All @@ -17,8 +17,8 @@


@pytest.fixture
def free_bootstrapper_config() -> FreeBootstrapperConfig:
return FreeBootstrapperConfig(
def free_bootstrapper_config() -> FreeConfig:
return FreeConfig(
service_debug=False,
opentelemetry_instrumentors=[CustomInstrumentor()],
opentelemetry_log_traces=True,
Expand All @@ -27,7 +27,7 @@ def free_bootstrapper_config() -> FreeBootstrapperConfig:
)


def test_free_bootstrap(free_bootstrapper_config: FreeBootstrapperConfig) -> None:
def test_free_bootstrap(free_bootstrapper_config: FreeConfig) -> None:
bootstrapper = FreeBootstrapper(bootstrap_config=free_bootstrapper_config)
bootstrapper.bootstrap()
try:
Expand All @@ -39,7 +39,7 @@ def test_free_bootstrap(free_bootstrapper_config: FreeBootstrapperConfig) -> Non
def test_free_bootstrap_logging_disabled() -> None:
with pytest.warns(InstrumentNotReadyWarning) as records:
FreeBootstrapper(
bootstrap_config=FreeBootstrapperConfig(
bootstrap_config=FreeConfig(
logging_enabled=False,
opentelemetry_instrumentors=[CustomInstrumentor()],
opentelemetry_log_traces=True,
Expand All @@ -53,7 +53,7 @@ def test_free_bootstrap_logging_disabled() -> None:
assert "PyroscopeInstrument is not ready: pyroscope_endpoint is empty" in messages


def test_teardown_error_isolation(free_bootstrapper_config: FreeBootstrapperConfig) -> None:
def test_teardown_error_isolation(free_bootstrapper_config: FreeConfig) -> None:
bootstrapper = FreeBootstrapper(bootstrap_config=free_bootstrapper_config)
bootstrapper.bootstrap()

Expand All @@ -73,7 +73,7 @@ def test_teardown_error_isolation(free_bootstrapper_config: FreeBootstrapperConf
assert excinfo.value.errors == [("MagicMock", excinfo.value.__cause__)]


def test_teardown_error_aggregates_all_failures(free_bootstrapper_config: FreeBootstrapperConfig) -> None:
def test_teardown_error_aggregates_all_failures(free_bootstrapper_config: FreeConfig) -> None:
bootstrapper = FreeBootstrapper(bootstrap_config=free_bootstrapper_config)
bootstrapper.bootstrap()

Expand Down Expand Up @@ -104,13 +104,13 @@ def test_teardown_error_aggregates_all_failures(free_bootstrapper_config: FreeBo
],
)
def test_free_bootstrapper_with_missing_instrument_dependency(
free_bootstrapper_config: FreeBootstrapperConfig, package_name: str
free_bootstrapper_config: FreeConfig, package_name: str
) -> None:
with emulate_package_missing(package_name), pytest.warns(UserWarning, match=package_name):
FreeBootstrapper(bootstrap_config=free_bootstrapper_config)


def test_teardown_is_idempotent(free_bootstrapper_config: FreeBootstrapperConfig) -> None:
def test_teardown_is_idempotent(free_bootstrapper_config: FreeConfig) -> None:
bootstrapper = FreeBootstrapper(bootstrap_config=free_bootstrapper_config)
bootstrapper.bootstrap()

Expand Down
Loading