Skip to content

Commit e3c7873

Browse files
authored
ref(trytond): Use new scopes API (#2885)
1 parent 4731ce3 commit e3c7873

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

sentry_sdk/integrations/trytond.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,38 @@
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
65

76
from trytond.exceptions import TrytonException # type: ignore
87
from trytond.wsgi import app # type: ignore
98

10-
if TYPE_CHECKING:
11-
from typing import Any
12-
139

1410
# TODO: trytond-worker, trytond-cron and trytond-admin intergations
1511

1612

17-
class TrytondWSGIIntegration(sentry_sdk.integrations.Integration):
13+
class TrytondWSGIIntegration(Integration):
1814
identifier = "trytond_wsgi"
1915

2016
def __init__(self): # type: () -> None
2117
pass
2218

2319
@staticmethod
2420
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)
2622

2723
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:
3126
return
3227
elif isinstance(e, TrytonException):
3328
return
3429
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(
3831
e,
3932
client_options=client.options,
4033
mechanism={"type": "trytond", "handled": False},
4134
)
42-
hub.capture_event(event, hint=hint)
35+
sentry_sdk.capture_event(event, hint=hint)
4336

4437
# Expected error handlers signature was changed
4538
# when the error_handler decorator was introduced

0 commit comments

Comments
 (0)