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
5 changes: 3 additions & 2 deletions lite_bootstrap/instruments/logging_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ class LoggingConfig(BaseConfig):
default_factory=list,
)
logging_time_stamper: "structlog.processors.TimeStamper | None" = None
logging_enabled: bool = True


@dataclasses.dataclass(kw_only=True, slots=True, frozen=True)
class LoggingInstrument(BaseInstrument):
bootstrap_config: LoggingConfig
not_ready_message = "service_debug is True"
not_ready_message = "logging_enabled is False"
missing_dependency_message = "structlog is not installed"
_logger_factory: "MemoryLoggerFactory | None" = dataclasses.field(
default_factory=lambda: None, init=False, repr=False, compare=False
Expand All @@ -136,7 +137,7 @@ def structlog_pre_chain_processors(self) -> list[typing.Any]:
]

def is_ready(self) -> bool:
return not self.bootstrap_config.service_debug and import_checker.is_structlog_installed
return self.bootstrap_config.logging_enabled and import_checker.is_structlog_installed

@staticmethod
def check_dependencies() -> bool:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_free_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def test_free_bootstrap(free_bootstrapper_config: FreeBootstrapperConfig) -> Non
bootstrapper.teardown()


def test_free_bootstrap_logging_not_ready() -> None:
def test_free_bootstrap_logging_disabled() -> None:
with capture_logs() as cap_logs:
FreeBootstrapper(
bootstrap_config=FreeBootstrapperConfig(
service_debug=True,
logging_enabled=False,
opentelemetry_instrumentors=[CustomInstrumentor()],
opentelemetry_log_traces=True,
sentry_dsn="https://testdsn@localhost/1",
Expand All @@ -44,7 +44,7 @@ def test_free_bootstrap_logging_not_ready() -> None:
),
)
assert cap_logs == [
{"event": "LoggingInstrument is not ready: service_debug is True", "log_level": "info"},
{"event": "LoggingInstrument is not ready: logging_enabled is False", "log_level": "info"},
{"event": "PyroscopeInstrument is not ready: pyroscope_endpoint is empty", "log_level": "info"},
]

Expand Down
Loading