@@ -135,7 +135,7 @@ def test_basic_no_exception(lambda_client, test_environment):
135135 }
136136
137137
138- def test_BasicException (lambda_client , test_environment ):
138+ def test_basic_exception (lambda_client , test_environment ):
139139 lambda_client .invoke (
140140 FunctionName = "BasicException" ,
141141 Payload = json .dumps ({}),
@@ -185,7 +185,9 @@ def test_init_error(lambda_client, test_environment):
185185
186186 (error_event , transaction_event ) = envelopes
187187
188- assert error_event ["exception" ]["values" ][0 ]["value" ] == "name 'func' is not defined"
188+ assert (
189+ error_event ["exception" ]["values" ][0 ]["value" ] == "name 'func' is not defined"
190+ )
189191 assert transaction_event ["transaction" ] == "InitError"
190192
191193
@@ -196,13 +198,123 @@ def test_timeout_error(lambda_client, test_environment):
196198 )
197199 envelopes = test_environment ["server" ].envelopes
198200
199- (error_event , ) = envelopes
201+ (error_event ,) = envelopes
200202
201203 assert error_event ["level" ] == "error"
202204 assert error_event ["extra" ]["lambda" ]["function_name" ] == "TimeoutError"
203205
204206 (exception ,) = error_event ["exception" ]["values" ]
205207 assert not exception ["mechanism" ]["handled" ]
206208 assert exception ["type" ] == "ServerlessTimeoutWarning"
207- assert exception ["value" ].startswith ("WARNING : Function is expected to get timed out. Configured timeout duration =" )
209+ assert exception ["value" ].startswith (
210+ "WARNING : Function is expected to get timed out. Configured timeout duration ="
211+ )
208212 assert exception ["mechanism" ]["type" ] == "threading"
213+
214+
215+ @pytest .mark .parametrize (
216+ "aws_event, has_request_data, batch_size" ,
217+ [
218+ (b"1231" , False , 1 ),
219+ (b"11.21" , False , 1 ),
220+ (b'"Good dog!"' , False , 1 ),
221+ (b"true" , False , 1 ),
222+ (
223+ b"""
224+ [
225+ {"good dog": "Maisey"},
226+ {"good dog": "Charlie"},
227+ {"good dog": "Cory"},
228+ {"good dog": "Bodhi"}
229+ ]
230+ """ ,
231+ False ,
232+ 4 ,
233+ ),
234+ (
235+ b"""
236+ [
237+ {
238+ "headers": {
239+ "Host": "x1.io",
240+ "X-Forwarded-Proto": "https"
241+ },
242+ "httpMethod": "GET",
243+ "path": "/1",
244+ "queryStringParameters": {
245+ "done": "f"
246+ },
247+ "d": "D1"
248+ },
249+ {
250+ "headers": {
251+ "Host": "x2.io",
252+ "X-Forwarded-Proto": "http"
253+ },
254+ "httpMethod": "POST",
255+ "path": "/2",
256+ "queryStringParameters": {
257+ "done": "t"
258+ },
259+ "d": "D2"
260+ }
261+ ]
262+ """ ,
263+ True ,
264+ 2 ,
265+ ),
266+ (b"[]" , False , 1 ),
267+ ],
268+ ids = [
269+ "event as integer" ,
270+ "event as float" ,
271+ "event as string" ,
272+ "event as bool" ,
273+ "event as list of dicts" ,
274+ "event as dict" ,
275+ "event as empty list" ,
276+ ],
277+ )
278+ def test_non_dict_event (
279+ lambda_client , test_environment , aws_event , has_request_data , batch_size
280+ ):
281+ lambda_client .invoke (
282+ FunctionName = "BasicException" ,
283+ Payload = aws_event ,
284+ )
285+ envelopes = test_environment ["server" ].envelopes
286+
287+ (error_event , transaction_event ) = envelopes
288+
289+ assert transaction_event ["type" ] == "transaction"
290+ assert transaction_event ["transaction" ] == "BasicException"
291+ assert transaction_event ["sdk" ]["name" ] == "sentry.python.aws_lambda"
292+ assert transaction_event ["contexts" ]["trace" ]["status" ] == "internal_error"
293+
294+ assert error_event ["level" ] == "error"
295+ assert error_event ["transaction" ] == "BasicException"
296+ assert error_event ["sdk" ]["name" ] == "sentry.python.aws_lambda"
297+ assert error_event ["exception" ]["values" ][0 ]["type" ] == "RuntimeError"
298+ assert error_event ["exception" ]["values" ][0 ]["value" ] == "Oh!"
299+ assert error_event ["exception" ]["values" ][0 ]["mechanism" ]["type" ] == "aws_lambda"
300+
301+ if has_request_data :
302+ request_data = {
303+ "headers" : {"Host" : "x1.io" , "X-Forwarded-Proto" : "https" },
304+ "method" : "GET" ,
305+ "url" : "https://x1.io/1" ,
306+ "query_string" : {
307+ "done" : "f" ,
308+ },
309+ }
310+ else :
311+ request_data = {"url" : "awslambda:///BasicException" }
312+
313+ assert error_event ["request" ] == request_data
314+ assert transaction_event ["request" ] == request_data
315+
316+ if batch_size > 1 :
317+ assert error_event ["tags" ]["batch_size" ] == batch_size
318+ assert error_event ["tags" ]["batch_request" ] is True
319+ assert transaction_event ["tags" ]["batch_size" ] == batch_size
320+ assert transaction_event ["tags" ]["batch_request" ] is True
0 commit comments