|
1 |
| -import sentry_sdk.hub |
2 |
| -import sentry_sdk.utils |
3 |
| -import sentry_sdk.integrations |
4 |
| -import sentry_sdk.integrations.wsgi |
5 |
| -from sentry_sdk._types import TYPE_CHECKING |
| 1 | +import sentry_sdk |
| 2 | +from sentry_sdk.integrations import Integration |
| 3 | +from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware |
| 4 | +from sentry_sdk.utils import event_from_exception |
6 | 5 |
|
7 | 6 | from trytond.exceptions import TrytonException # type: ignore
|
8 | 7 | from trytond.wsgi import app # type: ignore
|
9 | 8 |
|
10 |
| -if TYPE_CHECKING: |
11 |
| - from typing import Any |
12 |
| - |
13 | 9 |
|
14 | 10 | # TODO: trytond-worker, trytond-cron and trytond-admin intergations
|
15 | 11 |
|
16 | 12 |
|
17 |
| -class TrytondWSGIIntegration(sentry_sdk.integrations.Integration): |
| 13 | +class TrytondWSGIIntegration(Integration): |
18 | 14 | identifier = "trytond_wsgi"
|
19 | 15 |
|
20 | 16 | def __init__(self): # type: () -> None
|
21 | 17 | pass
|
22 | 18 |
|
23 | 19 | @staticmethod
|
24 | 20 | def setup_once(): # type: () -> None
|
25 |
| - app.wsgi_app = sentry_sdk.integrations.wsgi.SentryWsgiMiddleware(app.wsgi_app) |
| 21 | + app.wsgi_app = SentryWsgiMiddleware(app.wsgi_app) |
26 | 22 |
|
27 | 23 | def error_handler(e): # type: (Exception) -> None
|
28 |
| - hub = sentry_sdk.hub.Hub.current |
29 |
| - |
30 |
| - if hub.get_integration(TrytondWSGIIntegration) is None: |
| 24 | + client = sentry_sdk.get_client() |
| 25 | + if client.get_integration(TrytondWSGIIntegration) is None: |
31 | 26 | return
|
32 | 27 | elif isinstance(e, TrytonException):
|
33 | 28 | return
|
34 | 29 | else:
|
35 |
| - # If an integration is there, a client has to be there. |
36 |
| - client = hub.client # type: Any |
37 |
| - event, hint = sentry_sdk.utils.event_from_exception( |
| 30 | + event, hint = event_from_exception( |
38 | 31 | e,
|
39 | 32 | client_options=client.options,
|
40 | 33 | mechanism={"type": "trytond", "handled": False},
|
41 | 34 | )
|
42 |
| - hub.capture_event(event, hint=hint) |
| 35 | + sentry_sdk.capture_event(event, hint=hint) |
43 | 36 |
|
44 | 37 | # Expected error handlers signature was changed
|
45 | 38 | # when the error_handler decorator was introduced
|
|
0 commit comments