1
1
from importlib import import_module
2
2
3
- from sentry_sdk . hub import Hub , _should_send_default_pii
3
+ from sentry_sdk import get_client , capture_event
4
4
from sentry_sdk .integrations import DidNotEnable , Integration
5
5
from sentry_sdk .integrations .logging import ignore_logger
6
6
from sentry_sdk .integrations ._wsgi_common import request_body_within_bounds
7
+ from sentry_sdk .scope import Scope , should_send_default_pii
7
8
from sentry_sdk .utils import (
8
9
capture_internal_exceptions ,
10
+ ensure_integration_enabled ,
9
11
event_from_exception ,
10
12
package_version ,
11
13
)
@@ -51,73 +53,60 @@ def _patch_graphql():
51
53
old_handle_errors = ariadne_graphql .handle_graphql_errors
52
54
old_handle_query_result = ariadne_graphql .handle_query_result
53
55
56
+ @ensure_integration_enabled (AriadneIntegration , old_parse_query )
54
57
def _sentry_patched_parse_query (context_value , query_parser , data ):
55
58
# type: (Optional[Any], Optional[QueryParser], Any) -> DocumentNode
56
- hub = Hub .current
57
- integration = hub .get_integration (AriadneIntegration )
58
- if integration is None :
59
- return old_parse_query (context_value , query_parser , data )
60
-
61
- with hub .configure_scope () as scope :
62
- event_processor = _make_request_event_processor (data )
63
- scope .add_event_processor (event_processor )
59
+ event_processor = _make_request_event_processor (data )
60
+ Scope .get_isolation_scope ().add_event_processor (event_processor )
64
61
65
62
result = old_parse_query (context_value , query_parser , data )
66
63
return result
67
64
65
+ @ensure_integration_enabled (AriadneIntegration , old_handle_errors )
68
66
def _sentry_patched_handle_graphql_errors (errors , * args , ** kwargs ):
69
67
# type: (List[GraphQLError], Any, Any) -> GraphQLResult
70
- hub = Hub .current
71
- integration = hub .get_integration (AriadneIntegration )
72
- if integration is None :
73
- return old_handle_errors (errors , * args , ** kwargs )
74
-
75
68
result = old_handle_errors (errors , * args , ** kwargs )
76
69
77
- with hub .configure_scope () as scope :
78
- event_processor = _make_response_event_processor (result [1 ])
79
- scope .add_event_processor (event_processor )
70
+ event_processor = _make_response_event_processor (result [1 ])
71
+ Scope .get_isolation_scope ().add_event_processor (event_processor )
80
72
81
- if hub .client :
73
+ client = get_client ()
74
+ if client .is_active ():
82
75
with capture_internal_exceptions ():
83
76
for error in errors :
84
77
event , hint = event_from_exception (
85
78
error ,
86
- client_options = hub . client .options ,
79
+ client_options = client .options ,
87
80
mechanism = {
88
- "type" : integration .identifier ,
81
+ "type" : AriadneIntegration .identifier ,
89
82
"handled" : False ,
90
83
},
91
84
)
92
- hub . capture_event (event , hint = hint )
85
+ capture_event (event , hint = hint )
93
86
94
87
return result
95
88
89
+ @ensure_integration_enabled (AriadneIntegration , old_handle_query_result )
96
90
def _sentry_patched_handle_query_result (result , * args , ** kwargs ):
97
91
# type: (Any, Any, Any) -> GraphQLResult
98
- hub = Hub .current
99
- integration = hub .get_integration (AriadneIntegration )
100
- if integration is None :
101
- return old_handle_query_result (result , * args , ** kwargs )
102
-
103
92
query_result = old_handle_query_result (result , * args , ** kwargs )
104
93
105
- with hub .configure_scope () as scope :
106
- event_processor = _make_response_event_processor (query_result [1 ])
107
- scope .add_event_processor (event_processor )
94
+ event_processor = _make_response_event_processor (query_result [1 ])
95
+ Scope .get_isolation_scope ().add_event_processor (event_processor )
108
96
109
- if hub .client :
97
+ client = get_client ()
98
+ if client .is_active ():
110
99
with capture_internal_exceptions ():
111
100
for error in result .errors or []:
112
101
event , hint = event_from_exception (
113
102
error ,
114
- client_options = hub . client .options ,
103
+ client_options = client .options ,
115
104
mechanism = {
116
- "type" : integration .identifier ,
105
+ "type" : AriadneIntegration .identifier ,
117
106
"handled" : False ,
118
107
},
119
108
)
120
- hub . capture_event (event , hint = hint )
109
+ capture_event (event , hint = hint )
121
110
122
111
return query_result
123
112
@@ -143,8 +132,8 @@ def inner(event, hint):
143
132
except (TypeError , ValueError ):
144
133
return event
145
134
146
- if _should_send_default_pii () and request_body_within_bounds (
147
- Hub . current . client , content_length
135
+ if should_send_default_pii () and request_body_within_bounds (
136
+ get_client () , content_length
148
137
):
149
138
request_info = event .setdefault ("request" , {})
150
139
request_info ["api_target" ] = "graphql"
@@ -165,7 +154,7 @@ def _make_response_event_processor(response):
165
154
def inner (event , hint ):
166
155
# type: (Event, dict[str, Any]) -> Event
167
156
with capture_internal_exceptions ():
168
- if _should_send_default_pii () and response .get ("errors" ):
157
+ if should_send_default_pii () and response .get ("errors" ):
169
158
contexts = event .setdefault ("contexts" , {})
170
159
contexts ["response" ] = {
171
160
"data" : response ,
0 commit comments