1
1
from __future__ import annotations
2
2
3
3
import logging
4
- from typing import Any
4
+ from typing import Any , Dict , Sequence , Union
5
5
6
- from asphalt .core import Context
7
- from raven import Client
8
- from raven_aiohttp import AioHttpTransport
6
+ import sentry_sdk
7
+ from asphalt .core import Context , resolve_reference
8
+ from sentry_sdk .integrations import Integration
9
+ from typeguard import check_argument_types
9
10
10
11
from asphalt .exceptions .api import ExceptionReporter
11
12
@@ -18,31 +19,37 @@ class SentryExceptionReporter(ExceptionReporter):
18
19
19
20
To use this backend, install asphalt-exceptions with the ``sentry`` extra.
20
21
21
- All keyword arguments are directly passed to :class:`raven.Client `.
22
+ All keyword arguments are directly passed to :func:`sentry_sdk.init `.
22
23
The following defaults are set for the client arguments:
23
24
24
25
* environment: "development" or "production", depending on the ``__debug__`` flag
25
- * transport: :class:`raven_aiohttp.AioHttpTransport`
26
- * enable_breadcrumbs: ``False``
27
- * install_logging_hook: ``False``
28
26
29
- The extras passed to this backend are passed to :meth:`raven.Client.capture ` as keyword
27
+ The extras passed to this backend are passed to :func:`sentry_sdk.capture_exception ` as keyword
30
28
arguments.
31
29
32
- For more information, see the `Raven client documentation`_.
30
+ For more information, see the `Sentry SDK documentation`_.
33
31
34
32
.. _Sentry: https://sentry.io/
35
- .. _Raven client documentation: https://docs.sentry.io/clients /python/#configuring-the-client
33
+ .. _Sentry SDK documentation: https://docs.sentry.io/platforms /python/
36
34
"""
37
35
38
- def __init__ (self , ** client_args ) -> None :
39
- client_args .setdefault (
40
- "environment" , "development" if __debug__ else "production"
41
- )
42
- client_args .setdefault ("transport" , AioHttpTransport )
43
- client_args .setdefault ("enable_breadcrumbs" , False )
44
- client_args .setdefault ("install_logging_hook" , False )
45
- self .client = Client (** client_args )
36
+ def __init__ (
37
+ self , integrations : Sequence [Union [Integration , Dict [str , Any ]]] = (), ** options
38
+ ) -> None :
39
+ check_argument_types ()
40
+ options .setdefault ("environment" , "development" if __debug__ else "production" )
41
+
42
+ integrations_ : list [Integration ] = []
43
+ for integration in integrations :
44
+ if isinstance (integration , dict ):
45
+ integration_class = resolve_reference (integration ["type" ])
46
+ integration = integration_class (
47
+ * integration .get ("args" , ()), ** integration .get ("kwargs" , {})
48
+ )
49
+
50
+ integrations_ .append (integration )
51
+
52
+ sentry_sdk .init (integrations = integrations_ , ** options )
46
53
47
54
def report_exception (
48
55
self ,
@@ -51,5 +58,4 @@ def report_exception(
51
58
message : str ,
52
59
extra : dict [str , Any ],
53
60
) -> None :
54
- exc_info = type (exception ), exception , exception .__traceback__
55
- self .client .captureException (exc_info , message = message , ** extra )
61
+ sentry_sdk .capture_exception (exception , ** extra )
0 commit comments