1
1
import sys
2
2
from datetime import datetime
3
3
4
+ import sentry_sdk
4
5
from sentry_sdk ._types import TYPE_CHECKING
5
- from sentry_sdk import Hub
6
6
from sentry_sdk .api import continue_trace , get_baggage , get_traceparent
7
7
from sentry_sdk .consts import OP
8
- from sentry_sdk .hub import _should_send_default_pii
9
8
from sentry_sdk .integrations import DidNotEnable , Integration
9
+ from sentry_sdk .scope import Scope , should_send_default_pii
10
10
from sentry_sdk .tracing import (
11
11
BAGGAGE_HEADER_NAME ,
12
12
SENTRY_TRACE_HEADER_NAME ,
13
13
TRANSACTION_SOURCE_TASK ,
14
14
)
15
- from sentry_sdk .scope import Scope
16
15
from sentry_sdk .utils import (
17
16
capture_internal_exceptions ,
17
+ ensure_integration_enabled ,
18
18
event_from_exception ,
19
19
SENSITIVE_DATA_SUBSTITUTE ,
20
20
reraise ,
@@ -52,14 +52,10 @@ def patch_enqueue():
52
52
# type: () -> None
53
53
old_enqueue = Huey .enqueue
54
54
55
+ @ensure_integration_enabled (HueyIntegration , old_enqueue )
55
56
def _sentry_enqueue (self , task ):
56
57
# type: (Huey, Task) -> Optional[Union[Result, ResultGroup]]
57
- hub = Hub .current
58
-
59
- if hub .get_integration (HueyIntegration ) is None :
60
- return old_enqueue (self , task )
61
-
62
- with hub .start_span (op = OP .QUEUE_SUBMIT_HUEY , description = task .name ):
58
+ with sentry_sdk .start_span (op = OP .QUEUE_SUBMIT_HUEY , description = task .name ):
63
59
if not isinstance (task , PeriodicTask ):
64
60
# Attach trace propagation data to task kwargs. We do
65
61
# not do this for periodic tasks, as these don't
@@ -87,12 +83,12 @@ def event_processor(event, hint):
87
83
"task" : task .name ,
88
84
"args" : (
89
85
task .args
90
- if _should_send_default_pii ()
86
+ if should_send_default_pii ()
91
87
else SENSITIVE_DATA_SUBSTITUTE
92
88
),
93
89
"kwargs" : (
94
90
task .kwargs
95
- if _should_send_default_pii ()
91
+ if should_send_default_pii ()
96
92
else SENSITIVE_DATA_SUBSTITUTE
97
93
),
98
94
"retry" : (task .default_retries or 0 ) - task .retries ,
@@ -122,12 +118,10 @@ def _capture_exception(exc_info):
122
118
123
119
def _wrap_task_execute (func ):
124
120
# type: (F) -> F
121
+
122
+ @ensure_integration_enabled (HueyIntegration , func )
125
123
def _sentry_execute (* args , ** kwargs ):
126
124
# type: (*Any, **Any) -> Any
127
- hub = Hub .current
128
- if hub .get_integration (HueyIntegration ) is None :
129
- return func (* args , ** kwargs )
130
-
131
125
try :
132
126
result = func (* args , ** kwargs )
133
127
except Exception :
@@ -144,14 +138,10 @@ def patch_execute():
144
138
# type: () -> None
145
139
old_execute = Huey ._execute
146
140
141
+ @ensure_integration_enabled (HueyIntegration , old_execute )
147
142
def _sentry_execute (self , task , timestamp = None ):
148
143
# type: (Huey, Task, Optional[datetime]) -> Any
149
- hub = Hub .current
150
-
151
- if hub .get_integration (HueyIntegration ) is None :
152
- return old_execute (self , task , timestamp )
153
-
154
- with hub .push_scope () as scope :
144
+ with sentry_sdk .isolation_scope () as scope :
155
145
with capture_internal_exceptions ():
156
146
scope ._name = "huey"
157
147
scope .clear_breadcrumbs ()
@@ -171,7 +161,7 @@ def _sentry_execute(self, task, timestamp=None):
171
161
task .execute = _wrap_task_execute (task .execute )
172
162
task ._sentry_is_patched = True
173
163
174
- with hub .start_transaction (transaction ):
164
+ with sentry_sdk .start_transaction (transaction ):
175
165
return old_execute (self , task , timestamp )
176
166
177
167
Huey ._execute = _sentry_execute
0 commit comments