From 3a8edd376c3ffaa15e065248b9bf4a30ef5d3cc6 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Fri, 2 Sep 2022 17:23:01 +0200 Subject: [PATCH] feat: allow specifying any Sentry option --- errbot/bootstrap.py | 15 ++++++++------- errbot/config-template.py | 6 ++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/errbot/bootstrap.py b/errbot/bootstrap.py index a0675e2770..fd19c9a1b1 100644 --- a/errbot/bootstrap.py +++ b/errbot/bootstrap.py @@ -132,19 +132,20 @@ def setup_bot( sentry_integrations.append(FlaskIntegration()) try: + sentry_options = getattr(config, "SENTRY_OPTIONS", {}) + # merge options with dedicated setting SENTRY_DSN + sentry_kwargs = { + **sentry_options, + **{"dsn": config.SENTRY_DSN, "integrations": sentry_integrations}, + } if hasattr(config, "SENTRY_TRANSPORT") and isinstance( config.SENTRY_TRANSPORT, tuple ): mod = importlib.import_module(config.SENTRY_TRANSPORT[1]) transport = getattr(mod, config.SENTRY_TRANSPORT[0]) + sentry_kwargs["transport"] = transport - sentry_sdk.init( - dsn=config.SENTRY_DSN, - integrations=sentry_integrations, - transport=transport, - ) - else: - sentry_sdk.init(dsn=config.SENTRY_DSN, integrations=sentry_integrations) + sentry_sdk.init(**sentry_kwargs) except ImportError: log.exception( f"Unable to import selected SENTRY_TRANSPORT - {config.SENTRY_TRANSPORT}" diff --git a/errbot/config-template.py b/errbot/config-template.py index 1fc07311ee..5b15c8da1e 100644 --- a/errbot/config-template.py +++ b/errbot/config-template.py @@ -138,6 +138,12 @@ # For more info, see https://docs.sentry.io/error-reporting/configuration/?platform=python#transport-options # SENTRY_TRANSPORT = ("RequestsHTTPTransport", "raven.transport.requests") +# Any other options that can be passed to sentry_sdk.init() at initialization time +# Note that dsn and transport should be specified via their dedicated setting, +# and that the 'integrations' setting cannot be set +# e.g: SENTRY_OPTIONS = {"environment": "production"} +SENTRY_OPTIONS = {} + # Execute commands in asynchronous mode. In this mode, Errbot will spawn 10 # separate threads to handle commands, instead of blocking on each # single command.