@@ -2873,6 +2873,97 @@ def test_sqs_sns_event_with_exception_accessing_first_record(
28732873 mock_extract_from_lambda_context .assert_called_once_with (self .lambda_context )
28742874 self .assertEqual (result , mock_context )
28752875
2876+ @patch ("datadog_lambda.tracing.extract_context_from_lambda_context" )
2877+ @patch ("datadog_lambda.tracing._dsm_set_checkpoint" )
2878+ def test_sqs_event_with_empty_arn (
2879+ self , mock_dsm_set_checkpoint , mock_extract_from_lambda_context
2880+ ):
2881+ """Test SQS event with empty eventSourceARN"""
2882+ event = {
2883+ "Records" : [
2884+ {
2885+ "eventSourceARN" : "" ,
2886+ "messageAttributes" : {},
2887+ "eventSource" : "aws:sqs" ,
2888+ }
2889+ ]
2890+ }
2891+
2892+ mock_context = Context (trace_id = 123 , span_id = 456 )
2893+ mock_extract_from_lambda_context .return_value = mock_context
2894+
2895+ result = extract_context_from_sqs_or_sns_event_or_context (
2896+ event , self .lambda_context , parse_event_source (event )
2897+ )
2898+
2899+ mock_dsm_set_checkpoint .assert_not_called ()
2900+ mock_extract_from_lambda_context .assert_called_once_with (self .lambda_context )
2901+ self .assertEqual (result , mock_context )
2902+
2903+ @patch ("datadog_lambda.tracing.extract_context_from_lambda_context" )
2904+ @patch ("datadog_lambda.tracing._dsm_set_checkpoint" )
2905+ def test_sns_event_with_empty_arn (
2906+ self , mock_dsm_set_checkpoint , mock_extract_from_lambda_context
2907+ ):
2908+ """Test SNS event with empty TopicArn"""
2909+ event = {
2910+ "Records" : [
2911+ {
2912+ "Sns" : {
2913+ "TopicArn" : "" ,
2914+ "MessageAttributes" : {},
2915+ },
2916+ "eventSource" : "aws:sns" ,
2917+ }
2918+ ]
2919+ }
2920+
2921+ mock_context = Context (trace_id = 123 , span_id = 456 )
2922+ mock_extract_from_lambda_context .return_value = mock_context
2923+
2924+ result = extract_context_from_sqs_or_sns_event_or_context (
2925+ event , self .lambda_context , parse_event_source (event )
2926+ )
2927+
2928+ mock_dsm_set_checkpoint .assert_not_called ()
2929+ mock_extract_from_lambda_context .assert_called_once_with (self .lambda_context )
2930+ self .assertEqual (result , mock_context )
2931+
2932+ @patch ("datadog_lambda.tracing.extract_context_from_lambda_context" )
2933+ @patch ("datadog_lambda.tracing._dsm_set_checkpoint" )
2934+ def test_sns_to_sqs_event_with_empty_arn (
2935+ self , mock_dsm_set_checkpoint , mock_extract_from_lambda_context
2936+ ):
2937+ """Test SNS->SQS event with empty eventSourceARN"""
2938+ sns_notification = {
2939+ "Type" : "Notification" ,
2940+ "TopicArn" : "arn:aws:sns:us-east-1:123456789012:test-topic" ,
2941+ "MessageAttributes" : {},
2942+ "Message" : "test message" ,
2943+ }
2944+
2945+ event = {
2946+ "Records" : [
2947+ {
2948+ "eventSourceARN" : "" ,
2949+ "body" : json .dumps (sns_notification ),
2950+ "messageAttributes" : {},
2951+ "eventSource" : "aws:sqs" ,
2952+ }
2953+ ]
2954+ }
2955+
2956+ mock_context = Context (trace_id = 123 , span_id = 456 )
2957+ mock_extract_from_lambda_context .return_value = mock_context
2958+
2959+ result = extract_context_from_sqs_or_sns_event_or_context (
2960+ event , self .lambda_context , parse_event_source (event )
2961+ )
2962+
2963+ mock_dsm_set_checkpoint .assert_not_called ()
2964+ mock_extract_from_lambda_context .assert_called_once_with (self .lambda_context )
2965+ self .assertEqual (result , mock_context )
2966+
28762967
28772968class TestExtractContextFromKinesisEventWithDSMLogic (unittest .TestCase ):
28782969 def setUp (self ):
@@ -2970,6 +3061,34 @@ def test_kinesis_event_with_malformed_data(
29703061 mock_extract_from_lambda_context .assert_called_once_with (self .lambda_context )
29713062 self .assertEqual (result , mock_context )
29723063
3064+ @patch ("datadog_lambda.tracing.extract_context_from_lambda_context" )
3065+ @patch ("datadog_lambda.tracing._dsm_set_checkpoint" )
3066+ def test_kinesis_event_with_empty_arn (
3067+ self , mock_dsm_set_checkpoint , mock_extract_from_lambda_context
3068+ ):
3069+ """Test Kinesis event with empty eventSourceARN"""
3070+ kinesis_data = {"message" : "test" }
3071+ kinesis_data_str = json .dumps (kinesis_data )
3072+ encoded_data = base64 .b64encode (kinesis_data_str .encode ()).decode ()
3073+
3074+ event = {
3075+ "Records" : [
3076+ {
3077+ "eventSourceARN" : "" ,
3078+ "kinesis" : {"data" : encoded_data },
3079+ }
3080+ ]
3081+ }
3082+
3083+ mock_context = Context (trace_id = 123 , span_id = 456 )
3084+ mock_extract_from_lambda_context .return_value = mock_context
3085+
3086+ result = extract_context_from_kinesis_event (event , self .lambda_context )
3087+
3088+ mock_dsm_set_checkpoint .assert_not_called ()
3089+ mock_extract_from_lambda_context .assert_called_once_with (self .lambda_context )
3090+ self .assertEqual (result , mock_context )
3091+
29733092 @patch ("datadog_lambda.tracing.extract_context_from_lambda_context" )
29743093 @patch ("datadog_lambda.tracing._dsm_set_checkpoint" )
29753094 def test_kinesis_event_with_exception_accessing_first_record (
0 commit comments