forked from getsentry/sentry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrytond.py
More file actions
55 lines (41 loc) · 1.69 KB
/
Copy pathtrytond.py
File metadata and controls
55 lines (41 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sentry_sdk.hub
import sentry_sdk.utils
import sentry_sdk.integrations
import sentry_sdk.integrations.wsgi
from sentry_sdk._types import MYPY
from trytond.exceptions import TrytonException # type: ignore
from trytond.wsgi import app # type: ignore
if MYPY:
from typing import Any
# TODO: trytond-worker, trytond-cron and trytond-admin intergations
class TrytondWSGIIntegration(sentry_sdk.integrations.Integration):
identifier = "trytond_wsgi"
def __init__(self): # type: () -> None
pass
@staticmethod
def setup_once(): # type: () -> None
app.wsgi_app = sentry_sdk.integrations.wsgi.SentryWsgiMiddleware(app.wsgi_app)
def error_handler(e): # type: (Exception) -> None
hub = sentry_sdk.hub.Hub.current
if hub.get_integration(TrytondWSGIIntegration) is None:
return
elif isinstance(e, TrytonException):
return
else:
# If an integration is there, a client has to be there.
client = hub.client # type: Any
event, hint = sentry_sdk.utils.event_from_exception(
e,
client_options=client.options,
mechanism={"type": "trytond", "handled": False},
)
hub.capture_event(event, hint=hint)
# Expected error handlers signature was changed
# when the error_handler decorator was introduced
# in Tryton-5.4
if hasattr(app, "error_handler"):
@app.error_handler
def _(app, request, e): # type: ignore
error_handler(e)
else:
app.error_handlers.append(error_handler)