|
2 | 2 | import requests |
3 | 3 |
|
4 | 4 | from cloudharness.utils.env import get_common_service_cluster_address |
| 5 | +from cloudharness.applications import get_current_configuration |
5 | 6 |
|
6 | 7 | sentry_environment = os.environ.get("DOMAIN", "Production") |
7 | 8 |
|
@@ -29,32 +30,39 @@ def get_dsn(appname): |
29 | 30 | else: |
30 | 31 | return None |
31 | 32 |
|
32 | | -def init(appname, traces_sample_rate=0): |
| 33 | +def init(appname=None, traces_sample_rate=0, integrations=None, **kwargs): |
33 | 34 | """ |
34 | 35 | Init cloudharness Sentry functionality for the current app |
35 | 36 |
|
36 | 37 | Args: |
37 | 38 | appname: the slug of the application |
38 | | - traces_sample_rate: performance trace sample rate |
| 39 | + others/kwargs: additional parameters for sentry_sdk.init |
| 40 | +
|
39 | 41 |
|
40 | 42 | Usage examples: |
41 | 43 | import cloudharness.sentry as sentry |
42 | 44 | sentry.init('notifications') |
43 | 45 | """ |
| 46 | + if appname is None: |
| 47 | + appname = get_current_configuration().harness.name |
| 48 | + |
44 | 49 | dsn = get_dsn(appname) |
| 50 | + |
45 | 51 | if dsn: |
46 | 52 | import sentry_sdk |
47 | | - try: |
48 | | - from flask import current_app as app |
49 | | - from sentry_sdk.integrations.flask import FlaskIntegration |
50 | | - integrations = [FlaskIntegration()] |
51 | | - except: |
52 | | - integrations = [] |
| 53 | + if not integrations: |
| 54 | + try: |
| 55 | + from flask import current_app as app |
| 56 | + from sentry_sdk.integrations.flask import FlaskIntegration |
| 57 | + integrations = [FlaskIntegration()] |
| 58 | + except: |
| 59 | + integrations = [] |
53 | 60 | sentry_sdk.init( |
54 | 61 | dsn=dsn, |
55 | | - traces_sample_rate=traces_sample_rate, |
56 | 62 | environment=sentry_environment, |
57 | | - integrations=integrations |
| 63 | + integrations=integrations, |
| 64 | + traces_sample_rate=traces_sample_rate, |
| 65 | + **kwargs |
58 | 66 | ) |
59 | 67 |
|
60 | 68 | __all__ = ['get_dsn', 'init'] |
0 commit comments