Skip to content

Commit

Permalink
Add utilities to integrate with Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
homeworkprod committed Jun 28, 2020
1 parent 5c3fd67 commit ae0ee68
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions byceps/util/sentry.py
@@ -0,0 +1,40 @@
"""
byceps.util.sentry
~~~~~~~~~~~~~~~~~~
Sentry_ integration
.. _Sentry: https://sentry.io/
:Copyright: 2006-2020 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from flask import Flask


def configure_sentry_for_webapp(dsn: str, environment: str, app: Flask) -> None:
"""Initialize and configure the Sentry SDK for the Flask-based web
application (both in 'admin' and 'site' modes).
"""
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration

sentry_sdk.init(
dsn=dsn, environment=environment, integrations=[FlaskIntegration()],
)

sentry_sdk.set_tag('app_mode', app.config.get('APP_MODE'))
sentry_sdk.set_tag('site_id', app.config.get('SITE_ID'))


def configure_sentry_for_worker(dsn: str, environment: str) -> None:
"""Initialize and configure the Sentry SDK for the RQ worker."""
import sentry_sdk
from sentry_sdk.integrations.rq import RqIntegration

sentry_sdk.init(
dsn=dsn, environment=environment, integrations=[RqIntegration()],
)

sentry_sdk.set_tag('app_mode', 'worker')

0 comments on commit ae0ee68

Please sign in to comment.