Completed
Push — main ( 249b02...ae0ee6 )
by Jochen
04:53
created

byceps.util.sentry.configure_sentry_for_webapp()   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 3
dl 0
loc 13
ccs 0
cts 6
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
"""
2
byceps.util.sentry
3
~~~~~~~~~~~~~~~~~~
4
5
Sentry_ integration
6
7
.. _Sentry: https://sentry.io/
8
9
:Copyright: 2006-2020 Jochen Kupperschmidt
10
:License: Modified BSD, see LICENSE for details.
11
"""
12
13
from flask import Flask
14
15
16
def configure_sentry_for_webapp(dsn: str, environment: str, app: Flask) -> None:
17
    """Initialize and configure the Sentry SDK for the Flask-based web
18
    application (both in 'admin' and 'site' modes).
19
    """
20
    import sentry_sdk
21
    from sentry_sdk.integrations.flask import FlaskIntegration
22
23
    sentry_sdk.init(
24
        dsn=dsn, environment=environment, integrations=[FlaskIntegration()],
25
    )
26
27
    sentry_sdk.set_tag('app_mode', app.config.get('APP_MODE'))
28
    sentry_sdk.set_tag('site_id', app.config.get('SITE_ID'))
29
30
31
def configure_sentry_for_worker(dsn: str, environment: str) -> None:
32
    """Initialize and configure the Sentry SDK for the RQ worker."""
33
    import sentry_sdk
34
    from sentry_sdk.integrations.rq import RqIntegration
35
36
    sentry_sdk.init(
37
        dsn=dsn, environment=environment, integrations=[RqIntegration()],
38
    )
39
40
    sentry_sdk.set_tag('app_mode', 'worker')
41