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 .scope import Scope , should_send_default_pii
9
10
from sentry_sdk .tracing import TRANSACTION_SOURCE_COMPONENT
10
11
from sentry_sdk .utils import (
11
12
AnnotatedValue ,
@@ -38,18 +39,13 @@ def _wrap_init_error(init_error):
38
39
# type: (F) -> F
39
40
def sentry_init_error (* args , ** kwargs ):
40
41
# type: (*Any, **Any) -> Any
41
-
42
- hub = Hub .current
43
- integration = hub .get_integration (AwsLambdaIntegration )
42
+ client = sentry_sdk .get_client ()
43
+ integration = client .get_integration (AwsLambdaIntegration )
44
44
if integration is None :
45
45
return init_error (* args , ** kwargs )
46
46
47
- # If an integration is there, a client has to be there.
48
- client = hub .client # type: Any
49
-
50
47
with capture_internal_exceptions ():
51
- with hub .configure_scope () as scope :
52
- scope .clear_breadcrumbs ()
48
+ Scope .get_isolation_scope ().clear_breadcrumbs ()
53
49
54
50
exc_info = sys .exc_info ()
55
51
if exc_info and all (exc_info ):
@@ -58,7 +54,7 @@ def sentry_init_error(*args, **kwargs):
58
54
client_options = client .options ,
59
55
mechanism = {"type" : "aws_lambda" , "handled" : False },
60
56
)
61
- hub .capture_event (sentry_event , hint = hint )
57
+ sentry_sdk .capture_event (sentry_event , hint = hint )
62
58
63
59
return init_error (* args , ** kwargs )
64
60
@@ -93,16 +89,14 @@ def sentry_handler(aws_event, aws_context, *args, **kwargs):
93
89
# this is empty
94
90
request_data = {}
95
91
96
- hub = Hub . current
97
- integration = hub .get_integration (AwsLambdaIntegration )
92
+ client = sentry_sdk . get_client ()
93
+ integration = client .get_integration (AwsLambdaIntegration )
98
94
if integration is None :
99
95
return handler (aws_event , aws_context , * args , ** kwargs )
100
96
101
- # If an integration is there, a client has to be there.
102
- client = hub .client # type: Any
103
97
configured_time = aws_context .get_remaining_time_in_millis ()
104
98
105
- with hub . push_scope () as scope :
99
+ with sentry_sdk . isolation_scope () as scope :
106
100
timeout_thread = None
107
101
with capture_internal_exceptions ():
108
102
scope .clear_breadcrumbs ()
@@ -148,7 +142,7 @@ def sentry_handler(aws_event, aws_context, *args, **kwargs):
148
142
name = aws_context .function_name ,
149
143
source = TRANSACTION_SOURCE_COMPONENT ,
150
144
)
151
- with hub .start_transaction (
145
+ with sentry_sdk .start_transaction (
152
146
transaction ,
153
147
custom_sampling_context = {
154
148
"aws_event" : aws_event ,
@@ -164,7 +158,7 @@ def sentry_handler(aws_event, aws_context, *args, **kwargs):
164
158
client_options = client .options ,
165
159
mechanism = {"type" : "aws_lambda" , "handled" : False },
166
160
)
167
- hub .capture_event (sentry_event , hint = hint )
161
+ sentry_sdk .capture_event (sentry_event , hint = hint )
168
162
reraise (* exc_info )
169
163
finally :
170
164
if timeout_thread :
@@ -176,12 +170,12 @@ def sentry_handler(aws_event, aws_context, *args, **kwargs):
176
170
def _drain_queue ():
177
171
# type: () -> None
178
172
with capture_internal_exceptions ():
179
- hub = Hub . current
180
- integration = hub .get_integration (AwsLambdaIntegration )
173
+ client = sentry_sdk . get_client ()
174
+ integration = client .get_integration (AwsLambdaIntegration )
181
175
if integration is not None :
182
176
# Flush out the event queue before AWS kills the
183
177
# process.
184
- hub .flush ()
178
+ client .flush ()
185
179
186
180
187
181
class AwsLambdaIntegration (Integration ):
@@ -358,7 +352,7 @@ def event_processor(sentry_event, hint, start_time=start_time):
358
352
if "headers" in aws_event :
359
353
request ["headers" ] = _filter_headers (aws_event ["headers" ])
360
354
361
- if _should_send_default_pii ():
355
+ if should_send_default_pii ():
362
356
user_info = sentry_event .setdefault ("user" , {})
363
357
364
358
identity = aws_event .get ("identity" )
0 commit comments