@@ -134,7 +134,10 @@ def sentry_handler(aws_event, aws_context, *args, **kwargs):
134
134
# Starting the thread to raise timeout warning exception
135
135
timeout_thread .start ()
136
136
137
- headers = request_data .get ("headers" , {})
137
+ headers = request_data .get ("headers" )
138
+ # AWS Service may set an explicit `{headers: None}`, we can't rely on `.get()`'s default.
139
+ if headers is None :
140
+ headers = {}
138
141
transaction = Transaction .continue_from_headers (
139
142
headers , op = "serverless.function" , name = aws_context .function_name
140
143
)
@@ -337,11 +340,15 @@ def event_processor(sentry_event, hint, start_time=start_time):
337
340
if _should_send_default_pii ():
338
341
user_info = sentry_event .setdefault ("user" , {})
339
342
340
- id = aws_event .get ("identity" , {}).get ("userArn" )
343
+ identity = aws_event .get ("identity" )
344
+ if identity is None :
345
+ identity = {}
346
+
347
+ id = identity .get ("userArn" )
341
348
if id is not None :
342
349
user_info .setdefault ("id" , id )
343
350
344
- ip = aws_event . get ( " identity" , {}) .get ("sourceIp" )
351
+ ip = identity .get ("sourceIp" )
345
352
if ip is not None :
346
353
user_info .setdefault ("ip_address" , ip )
347
354
@@ -363,7 +370,11 @@ def event_processor(sentry_event, hint, start_time=start_time):
363
370
def _get_url (aws_event , aws_context ):
364
371
# type: (Any, Any) -> str
365
372
path = aws_event .get ("path" , None )
366
- headers = aws_event .get ("headers" , {})
373
+
374
+ headers = aws_event .get ("headers" )
375
+ if headers is None :
376
+ headers = {}
377
+
367
378
host = headers .get ("Host" , None )
368
379
proto = headers .get ("X-Forwarded-Proto" , None )
369
380
if proto and host and path :
0 commit comments