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

byceps.util.sentry   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 41
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
A configure_sentry_for_worker() 0 10 1
A configure_sentry_for_webapp() 0 13 1
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