Skip to content

Commit

Permalink
feat: allow specifying any Sentry option
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebroke committed Sep 2, 2022
1 parent b1a6408 commit 3a8edd3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 8 additions & 7 deletions errbot/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
6 changes: 6 additions & 0 deletions errbot/config-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3a8edd3

Please sign in to comment.