From e440b5a6bebcc558620a6ee0bc61d6a45dc5ac73 Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Mon, 1 Jun 2026 00:11:11 +0300 Subject: [PATCH] fix: strip skip_sentry from Sentry context; drop dead is_X_installed conjuncts DES-4: enrich_sentry_event_from_structlog_log was already returning None (suppressing the event) when skip_sentry was truthy, but for falsy values (False, missing, "") the flag itself was not stripped from the structlog payload before it was attached to event["contexts"]["structlog"]. Add "skip_sentry" to IGNORED_STRUCTLOG_ATTRIBUTES so the field never leaks into Sentry context noise. Regression test added as a parametrize case on the existing test_modify. DES-5: each affected instrument's is_ready() returned ` and import_checker.is_X_installed`. The conjunct is provably dead: BaseBootstrapper calls check_dependencies() in _register_or_skip before instantiating the instrument, and only invokes is_ready() if check_dependencies() returned True. Drop the redundant conjunct from SentryInstrument, LoggingInstrument, OpenTelemetryInstrument, and PyroscopeInstrument. Behavior is unchanged. Closes DES-4 and DES-5 from the audit. --- lite_bootstrap/instruments/logging_instrument.py | 2 +- lite_bootstrap/instruments/opentelemetry_instrument.py | 5 +---- lite_bootstrap/instruments/pyroscope_instrument.py | 2 +- lite_bootstrap/instruments/sentry_instrument.py | 4 ++-- tests/instruments/test_sentry_instrument.py | 10 ++++++++++ 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lite_bootstrap/instruments/logging_instrument.py b/lite_bootstrap/instruments/logging_instrument.py index d12c216..a830520 100644 --- a/lite_bootstrap/instruments/logging_instrument.py +++ b/lite_bootstrap/instruments/logging_instrument.py @@ -137,7 +137,7 @@ def structlog_pre_chain_processors(self) -> list[typing.Any]: ] def is_ready(self) -> bool: - return self.bootstrap_config.logging_enabled and import_checker.is_structlog_installed + return self.bootstrap_config.logging_enabled @staticmethod def check_dependencies() -> bool: diff --git a/lite_bootstrap/instruments/opentelemetry_instrument.py b/lite_bootstrap/instruments/opentelemetry_instrument.py index bcad0ee..bf80150 100644 --- a/lite_bootstrap/instruments/opentelemetry_instrument.py +++ b/lite_bootstrap/instruments/opentelemetry_instrument.py @@ -83,10 +83,7 @@ class OpenTelemetryInstrument(BaseInstrument): ) def is_ready(self) -> bool: - return ( - bool(self.bootstrap_config.opentelemetry_endpoint or self.bootstrap_config.opentelemetry_log_traces) - and import_checker.is_opentelemetry_installed - ) + return bool(self.bootstrap_config.opentelemetry_endpoint or self.bootstrap_config.opentelemetry_log_traces) @staticmethod def check_dependencies() -> bool: diff --git a/lite_bootstrap/instruments/pyroscope_instrument.py b/lite_bootstrap/instruments/pyroscope_instrument.py index d6bf89e..a5f293a 100644 --- a/lite_bootstrap/instruments/pyroscope_instrument.py +++ b/lite_bootstrap/instruments/pyroscope_instrument.py @@ -26,7 +26,7 @@ class PyroscopeInstrument(BaseInstrument): missing_dependency_message = "pyroscope is not installed" def is_ready(self) -> bool: - return bool(self.bootstrap_config.pyroscope_endpoint) and import_checker.is_pyroscope_installed + return bool(self.bootstrap_config.pyroscope_endpoint) @staticmethod def check_dependencies() -> bool: diff --git a/lite_bootstrap/instruments/sentry_instrument.py b/lite_bootstrap/instruments/sentry_instrument.py index 5badb17..370e86f 100644 --- a/lite_bootstrap/instruments/sentry_instrument.py +++ b/lite_bootstrap/instruments/sentry_instrument.py @@ -17,7 +17,7 @@ IGNORED_STRUCTLOG_ATTRIBUTES: typing.Final = frozenset( - {"event", "level", "logger", "tracing", "timestamp", "exception"} + {"event", "level", "logger", "tracing", "timestamp", "exception", "skip_sentry"} ) @@ -98,7 +98,7 @@ class SentryInstrument(BaseInstrument): missing_dependency_message = "sentry_sdk is not installed" def is_ready(self) -> bool: - return bool(self.bootstrap_config.sentry_dsn) and import_checker.is_sentry_installed + return bool(self.bootstrap_config.sentry_dsn) @staticmethod def check_dependencies() -> bool: diff --git a/tests/instruments/test_sentry_instrument.py b/tests/instruments/test_sentry_instrument.py index 0473744..38edf4d 100644 --- a/tests/instruments/test_sentry_instrument.py +++ b/tests/instruments/test_sentry_instrument.py @@ -108,6 +108,16 @@ def test_skip(self, event: "sentry_types.Event") -> None: "contexts": {"structlog": {"foo": "bar"}}, }, ), + ( + { + "logentry": {"formatted": '{"event": "event name", "skip_sentry": false, "foo": "bar"}'}, + "contexts": {}, + }, + { + "logentry": {"formatted": "event name"}, + "contexts": {"structlog": {"foo": "bar"}}, + }, + ), ], ) def test_modify(self, event_before: "sentry_types.Event", event_after: "sentry_types.Event") -> None: