Skip to content

Commit

Permalink
feat: remove support for SENTRY_TRANSPORT in favour of SENTRY_OPTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebroke committed Sep 5, 2022
1 parent 3a8edd3 commit 65c5a40
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
4 changes: 2 additions & 2 deletions docs/user_guide/sentry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ To setup Errbot with Sentry:
* Open up your bot's config.py
* Set **BOT_LOG_SENTRY** to *True* and fill in **SENTRY_DSN** with the DSN value obtained previously
* Optionally adjust **SENTRY_LOGLEVEL** to the desired level
* Optionally adjust **SENTRY_TRANSPORT** to the desired transport
* Optionally adjust **SENTRY_OPTIONS** to customise the initialization.
* Restart Errbot

You can find a list of `Sentry transport classes <https://docs.sentry.io/clients/python/transports/>`_.
You can find a list of `Sentry options <https://docs.sentry.io/platforms/python/configuration/options/>`_.

You should now see Exceptions and log messages show up in your Sentry stream.
27 changes: 7 additions & 20 deletions errbot/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,26 +131,13 @@ 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(**sentry_kwargs)
except ImportError:
log.exception(
f"Unable to import selected SENTRY_TRANSPORT - {config.SENTRY_TRANSPORT}"
)
exit(-1)
sentry_options = getattr(config, "SENTRY_OPTIONS", {})
# merge options dict with dedicated SENTRY_DSN setting
sentry_kwargs = {
**sentry_options,
**{"dsn": config.SENTRY_DSN, "integrations": sentry_integrations},
}
sentry_sdk.init(**sentry_kwargs)

logger.setLevel(config.BOT_LOG_LEVEL)

Expand Down
8 changes: 2 additions & 6 deletions errbot/config-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,8 @@
SENTRY_LOGLEVEL = BOT_LOG_LEVEL
SENTRY_EVENTLEVEL = BOT_LOG_LEVEL

# Set an optional Sentry transport other than the default Threaded.
# 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,
# Options that can be passed to sentry_sdk.init() at initialization time
# Note that DSN should be specified via its dedicated config option
# and that the 'integrations' setting cannot be set
# e.g: SENTRY_OPTIONS = {"environment": "production"}
SENTRY_OPTIONS = {}
Expand Down

0 comments on commit 65c5a40

Please sign in to comment.