3
3
from datetime import datetime , timedelta , timezone
4
4
from os import environ
5
5
6
+ import sentry_sdk
6
7
from sentry_sdk .api import continue_trace
7
8
from sentry_sdk .consts import OP
8
- from sentry_sdk .hub import Hub , _should_send_default_pii
9
+ from sentry_sdk .integrations import Integration
10
+ from sentry_sdk .integrations ._wsgi_common import _filter_headers
11
+ from sentry_sdk .scope import should_send_default_pii
9
12
from sentry_sdk .tracing import TRANSACTION_SOURCE_COMPONENT
10
13
from sentry_sdk .utils import (
11
14
AnnotatedValue ,
15
18
TimeoutThread ,
16
19
reraise ,
17
20
)
18
- from sentry_sdk .integrations import Integration
19
- from sentry_sdk .integrations ._wsgi_common import _filter_headers
20
21
21
22
from sentry_sdk ._types import TYPE_CHECKING
22
23
@@ -39,15 +40,12 @@ def _wrap_func(func):
39
40
# type: (F) -> F
40
41
def sentry_func (functionhandler , gcp_event , * args , ** kwargs ):
41
42
# type: (Any, Any, *Any, **Any) -> Any
43
+ client = sentry_sdk .get_client ()
42
44
43
- hub = Hub .current
44
- integration = hub .get_integration (GcpIntegration )
45
+ integration = client .get_integration (GcpIntegration )
45
46
if integration is None :
46
47
return func (functionhandler , gcp_event , * args , ** kwargs )
47
48
48
- # If an integration is there, a client has to be there.
49
- client = hub .client # type: Any
50
-
51
49
configured_time = environ .get ("FUNCTION_TIMEOUT_SEC" )
52
50
if not configured_time :
53
51
logger .debug (
@@ -59,7 +57,7 @@ def sentry_func(functionhandler, gcp_event, *args, **kwargs):
59
57
60
58
initial_time = datetime .now (timezone .utc )
61
59
62
- with hub . push_scope () as scope :
60
+ with sentry_sdk . isolation_scope () as scope :
63
61
with capture_internal_exceptions ():
64
62
scope .clear_breadcrumbs ()
65
63
scope .add_event_processor (
@@ -100,7 +98,7 @@ def sentry_func(functionhandler, gcp_event, *args, **kwargs):
100
98
},
101
99
"gcp_event" : gcp_event ,
102
100
}
103
- with hub .start_transaction (
101
+ with sentry_sdk .start_transaction (
104
102
transaction , custom_sampling_context = sampling_context
105
103
):
106
104
try :
@@ -112,13 +110,13 @@ def sentry_func(functionhandler, gcp_event, *args, **kwargs):
112
110
client_options = client .options ,
113
111
mechanism = {"type" : "gcp" , "handled" : False },
114
112
)
115
- hub .capture_event (sentry_event , hint = hint )
113
+ sentry_sdk .capture_event (sentry_event , hint = hint )
116
114
reraise (* exc_info )
117
115
finally :
118
116
if timeout_thread :
119
117
timeout_thread .stop ()
120
118
# Flush out the event queue
121
- hub .flush ()
119
+ client .flush ()
122
120
123
121
return sentry_func # type: ignore
124
122
@@ -187,7 +185,7 @@ def event_processor(event, hint):
187
185
if hasattr (gcp_event , "headers" ):
188
186
request ["headers" ] = _filter_headers (gcp_event .headers )
189
187
190
- if _should_send_default_pii ():
188
+ if should_send_default_pii ():
191
189
if hasattr (gcp_event , "data" ):
192
190
request ["data" ] = gcp_event .data
193
191
else :
0 commit comments