Skip to content

Commit 5a64d9e

Browse files
GenPagegbin
authored andcommitted
Add config option to set a custom Sentry Transport (errbotio#1136)
* Add config option to set a custom Sentry Transport * Document new config option for custom Sentry Transport
1 parent ae8ab3a commit 5a64d9e

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

docs/user_guide/sentry.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ To setup Errbot with Sentry:
4949
* Open up your bot's config.py
5050
* Set **BOT_LOG_SENTRY** to *True* and fill in **SENTRY_DSN** with the DNS value obtained previously
5151
* Optionally adjust **SENTRY_LOGLEVEL** to the desired level
52+
* Optionally adjust **SENTRY_TRANSPORT** to the desired transport
5253
* Restart Errbot
5354

55+
You can find a list of Sentry transport classes `here <https://docs.sentry.io/clients/python/transports/>`_.
56+
5457
You should now see Exceptions and log messages show up in your Sentry stream.

errbot/bootstrap.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from os import path, makedirs
2+
import importlib
23
import logging
34
import sys
45
import ast
@@ -101,7 +102,21 @@ def setup_bot(backend_name, logger, config, restore=None):
101102
)
102103
exit(-1)
103104

104-
sentryhandler = SentryHandler(config.SENTRY_DSN, level=config.SENTRY_LOGLEVEL)
105+
if hasattr(config, 'SENTRY_TRANSPORT') and isinstance(config.SENTRY_TRANSPORT, tuple):
106+
try:
107+
mod = importlib.import_module(config.SENTRY_TRANSPORT[1])
108+
transport = getattr(mod, config.SENTRY_TRANSPORT[0])
109+
except ImportError:
110+
log.exception(
111+
"Unable to import selected SENTRY_TRANSPORT - {transport}".format(transport=config.SENTRY_TRANSPORT)
112+
)
113+
exit(-1)
114+
115+
sentryhandler = SentryHandler(config.SENTRY_DSN,
116+
level=config.SENTRY_LOGLEVEL,
117+
transport=transport)
118+
else:
119+
sentryhandler = SentryHandler(config.SENTRY_DSN, level=config.SENTRY_LOGLEVEL)
105120
logger.addHandler(sentryhandler)
106121

107122
logger.setLevel(config.BOT_LOG_LEVEL)

errbot/config-template.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@
134134
SENTRY_DSN = ''
135135
SENTRY_LOGLEVEL = BOT_LOG_LEVEL
136136

137+
# Set an optional Sentry transport other than the default Threaded.
138+
# For more info, see https://docs.sentry.io/clients/python/transports/
139+
# SENTRY_TRANSPORT = ('RequestsHTTPTransport', 'raven.transport.requests')
140+
137141
# Execute commands in asynchronous mode. In this mode, Errbot will spawn 10
138142
# separate threads to handle commands, instead of blocking on each
139143
# single command.

0 commit comments

Comments
 (0)