structlog-sentry is a Python library that provides seamless integration between structlog, a structured logging library, and Sentry, an error tracking and performance monitoring platform. It allows users to send structured log events from their applications directly to Sentry, enhancing debugging and observability. The current version is 2.2.1, and the library is actively maintained with regular releases.
pip install structlog-sentryVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure `structlog` to use `SentryProcessor` to send structured logs and exceptions to Sentry. Ensure `sentry_sdk.init()` is called with your DSN and `structlog.stdlib.add_log_level` (and optionally `add_logger_name`) are placed before `SentryProcessor`.
Replace `SentryProcessor(hub=...)` with `SentryProcessor(scope=...)`.
Update `as_extra=True/False` to `as_context=True/False` in `SentryProcessor` initialization.
Remove `SentryJSONProcessor`. Use `SentryProcessor` and consider passing `integrations=[sentry_sdk.integrations.logging.LoggingIntegration(event_level=None, level=None)]` to `sentry_sdk.init()` for JSON logging setups.
Rename `level` to `event_level` for event reporting. If breadcrumb level control is needed, use the new `level` argument: `SentryProcessor(event_level=logging.ERROR, level=logging.INFO)`.
Adjust the order of processors in `structlog.configure()` to ensure `add_log_level` and `add_logger_name` come before `SentryProcessor`.
Reorder processors: `SentryProcessor(...)`, then `structlog.processors.format_exc_info`.
Explicitly disable `sentry-sdk`'s `LoggingIntegration` when initializing the Sentry SDK by passing `integrations=[sentry_sdk.integrations.logging.LoggingIntegration(event_level=None, level=None)]` to `sentry_sdk.init()`.