@@ -208,77 +208,44 @@ def setup_once():
208208 )
209209 return
210210
211- pre_37 = hasattr (lambda_bootstrap , "handle_http_request" ) # Python 3.6
211+ lambda_bootstrap .LambdaRuntimeClient .post_init_error = _wrap_init_error (
212+ lambda_bootstrap .LambdaRuntimeClient .post_init_error
213+ )
212214
213- if pre_37 :
214- old_handle_event_request = lambda_bootstrap .handle_event_request
215+ old_handle_event_request = lambda_bootstrap .handle_event_request
215216
216- def sentry_handle_event_request (request_handler , * args , ** kwargs ):
217- # type: (Any, *Any, **Any) -> Any
218- request_handler = _wrap_handler (request_handler )
219- return old_handle_event_request (request_handler , * args , ** kwargs )
220-
221- lambda_bootstrap .handle_event_request = sentry_handle_event_request
222-
223- old_handle_http_request = lambda_bootstrap .handle_http_request
224-
225- def sentry_handle_http_request (request_handler , * args , ** kwargs ):
226- # type: (Any, *Any, **Any) -> Any
227- request_handler = _wrap_handler (request_handler )
228- return old_handle_http_request (request_handler , * args , ** kwargs )
229-
230- lambda_bootstrap .handle_http_request = sentry_handle_http_request
217+ def sentry_handle_event_request ( # type: ignore
218+ lambda_runtime_client , request_handler , * args , ** kwargs
219+ ):
220+ request_handler = _wrap_handler (request_handler )
221+ return old_handle_event_request (
222+ lambda_runtime_client , request_handler , * args , ** kwargs
223+ )
231224
232- # Patch to_json to drain the queue. This should work even when the
233- # SDK is initialized inside of the handler
225+ lambda_bootstrap .handle_event_request = sentry_handle_event_request
234226
235- old_to_json = lambda_bootstrap .to_json
227+ # Patch the runtime client to drain the queue. This should work
228+ # even when the SDK is initialized inside of the handler
236229
237- def sentry_to_json (* args , ** kwargs ):
230+ def _wrap_post_function (f ):
231+ # type: (F) -> F
232+ def inner (* args , ** kwargs ):
238233 # type: (*Any, **Any) -> Any
239234 _drain_queue ()
240- return old_to_json (* args , ** kwargs )
241-
242- lambda_bootstrap .to_json = sentry_to_json
243- else :
244- lambda_bootstrap .LambdaRuntimeClient .post_init_error = _wrap_init_error (
245- lambda_bootstrap .LambdaRuntimeClient .post_init_error
246- )
235+ return f (* args , ** kwargs )
247236
248- old_handle_event_request = lambda_bootstrap . handle_event_request
237+ return inner # type: ignore
249238
250- def sentry_handle_event_request ( # type: ignore
251- lambda_runtime_client , request_handler , * args , ** kwargs
252- ):
253- request_handler = _wrap_handler (request_handler )
254- return old_handle_event_request (
255- lambda_runtime_client , request_handler , * args , ** kwargs
256- )
257-
258- lambda_bootstrap .handle_event_request = sentry_handle_event_request
259-
260- # Patch the runtime client to drain the queue. This should work
261- # even when the SDK is initialized inside of the handler
262-
263- def _wrap_post_function (f ):
264- # type: (F) -> F
265- def inner (* args , ** kwargs ):
266- # type: (*Any, **Any) -> Any
267- _drain_queue ()
268- return f (* args , ** kwargs )
269-
270- return inner # type: ignore
271-
272- lambda_bootstrap .LambdaRuntimeClient .post_invocation_result = (
273- _wrap_post_function (
274- lambda_bootstrap .LambdaRuntimeClient .post_invocation_result
275- )
239+ lambda_bootstrap .LambdaRuntimeClient .post_invocation_result = (
240+ _wrap_post_function (
241+ lambda_bootstrap .LambdaRuntimeClient .post_invocation_result
276242 )
277- lambda_bootstrap . LambdaRuntimeClient . post_invocation_error = (
278- _wrap_post_function (
279- lambda_bootstrap . LambdaRuntimeClient . post_invocation_error
280- )
243+ )
244+ lambda_bootstrap . LambdaRuntimeClient . post_invocation_error = (
245+ _wrap_post_function (
246+ lambda_bootstrap . LambdaRuntimeClient . post_invocation_error
281247 )
248+ )
282249
283250
284251def get_lambda_bootstrap ():
0 commit comments