Skip to content

Commit

Permalink
Allow downstream apps to pass options to sentry init
Browse files Browse the repository at this point in the history
  • Loading branch information
alastair committed Mar 31, 2021
1 parent 27a1623 commit 823d278
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion brainzutils/flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ def init_loggers(self,
{
'dsn': 'YOUR_SENTRY_DSN',
'environment': 'production', # optional
'level': 'WARNING', # optional
}
"""
if file_config:
loggers.add_file_handler(self, **file_config)
if sentry_config:
loggers.add_sentry(self, **sentry_config)
loggers.add_sentry(**sentry_config)
18 changes: 12 additions & 6 deletions brainzutils/flask/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ def add_file_handler(app, filename, max_bytes=512 * 1024, backup_count=100):
app.logger.addHandler(file_handler)


def add_sentry(app, dsn, level=logging.WARNING, **options):
"""Adds Sentry logging.
def add_sentry(dsn, level=logging.WARNING, **options):
"""Adds Sentry event logging.
Sentry is a realtime event logging and aggregation platform. Additional
information about it is available at https://sentry.readthedocs.org/.
Sentry is a realtime event logging and aggregation platform.
By default we add integration to the python logger, flask, redis, and sqlalchemy.
Arguments:
dsn: The sentry DSN to connect to
level: the logging level at which logging messages are sent as events to sentry
options: Any other arguments to be passed to sentry_sdk.init.
See https://docs.sentry.io/platforms/python/configuration/options/
"""
app.config["SENTRY_CONFIG"] = options
sentry_sdk.init(dsn, integrations=[LoggingIntegration(level=level), FlaskIntegration(), RedisIntegration(),
SqlalchemyIntegration()])
SqlalchemyIntegration()],
**options)

0 comments on commit 823d278

Please sign in to comment.