2424DOCKER_NETWORK_NAME = "lambda-test-network"
2525SAM_TEMPLATE_FILE = "sam.template.yaml"
2626SAM_SHUTDOWN_TIMEOUT = 10
27- MESSAGE_ORIGIN_LINK = {
28- SPANDATA .SENTRY_LINK_TYPE : {"value" : "message_origin" , "type" : "string" }
29- }
3027
3128SQS_RECORD = {
3229 "messageId" : "059f36b4-87a3-44ab-83d2-661975830a7d" ,
@@ -853,43 +850,6 @@ def test_error(lambda_client, test_environment):
853850 assert _get_span_attr (attrs , SPANDATA .FAAS_TRIGGER ) == "other"
854851
855852
856- def _sqs_record (sentry_trace = None ):
857- record = {
858- "messageId" : "059f36b4-87a3-44ab-83d2-661975830a7d" ,
859- "body" : "{}" ,
860- "messageAttributes" : {},
861- "eventSource" : "aws:sqs" ,
862- "eventSourceARN" : "arn:aws:sqs:us-east-1:012345678912:orders" ,
863- }
864- if sentry_trace is not None :
865- record ["messageAttributes" ]["sentry-trace" ] = {
866- "stringValue" : sentry_trace ,
867- "stringListValues" : [],
868- "binaryListValues" : [],
869- "dataType" : "String" ,
870- }
871- return record
872-
873-
874- def _sns_record (sentry_trace = None ):
875- record = {
876- "EventSource" : "aws:sns" ,
877- "Sns" : {
878- "Type" : "Notification" ,
879- "MessageId" : "95df01b4-ee98-5cb9-9903-4c221d41eb5e" ,
880- "TopicArn" : "arn:aws:sns:us-east-1:012345678912:alerts" ,
881- "Message" : "{}" ,
882- "MessageAttributes" : {},
883- },
884- }
885- if sentry_trace is not None :
886- record ["Sns" ]["MessageAttributes" ]["sentry-trace" ] = {
887- "Type" : "String" ,
888- "Value" : sentry_trace ,
889- }
890- return record
891-
892-
893853@pytest .mark .parametrize (
894854 "aws_event,trigger" ,
895855 [
@@ -957,85 +917,16 @@ def test_trigger(lambda_client, test_environment, aws_event, trigger):
957917
958918
959919@pytest .mark .parametrize (
960- "aws_event,system,destination,links " ,
920+ "aws_event,system,destination" ,
961921 [
962922 pytest .param (
963- {
964- "Records" : [
965- _sqs_record ("471a43a4192642f0b136d5159a501701-6e8f22c393e68f19-1" ),
966- # the same send context: linked once.
967- _sqs_record ("471a43a4192642f0b136d5159a501701-6e8f22c393e68f19-1" ),
968- _sqs_record ("0f4c2a5b8d9e4f1a2b3c4d5e6f7a8b9c-1a2b3c4d5e6f7a8b-0" ),
969- _sqs_record (),
970- # incomplete context: not linked.
971- _sqs_record ("-1" ),
972- ]
973- },
974- "aws_sqs" ,
975- "orders" ,
976- [
977- {
978- "trace_id" : "471a43a4192642f0b136d5159a501701" ,
979- "span_id" : "6e8f22c393e68f19" ,
980- "attributes" : MESSAGE_ORIGIN_LINK ,
981- "sampled" : True ,
982- },
983- {
984- "trace_id" : "0f4c2a5b8d9e4f1a2b3c4d5e6f7a8b9c" ,
985- "span_id" : "1a2b3c4d5e6f7a8b" ,
986- "attributes" : MESSAGE_ORIGIN_LINK ,
987- "sampled" : False ,
988- },
989- ],
990- id = "sqs" ,
991- ),
992- pytest .param (
993- {
994- "Records" : [
995- _sns_record ("471a43a4192642f0b136d5159a501701-6e8f22c393e68f19-1" )
996- ]
997- },
998- "aws.sns" ,
999- "alerts" ,
1000- [
1001- {
1002- "trace_id" : "471a43a4192642f0b136d5159a501701" ,
1003- "span_id" : "6e8f22c393e68f19" ,
1004- "attributes" : MESSAGE_ORIGIN_LINK ,
1005- "sampled" : True ,
1006- }
1007- ],
1008- id = "sns" ,
1009- ),
1010- pytest .param (
1011- {
1012- "Records" : [
1013- {
1014- ** _sqs_record (),
1015- "body" : json .dumps (
1016- _sns_record (
1017- "471a43a4192642f0b136d5159a501701-6e8f22c393e68f19-1"
1018- )["Sns" ]
1019- ),
1020- }
1021- ]
1022- },
1023- "aws_sqs" ,
1024- "orders" ,
1025- [
1026- {
1027- "trace_id" : "471a43a4192642f0b136d5159a501701" ,
1028- "span_id" : "6e8f22c393e68f19" ,
1029- "attributes" : MESSAGE_ORIGIN_LINK ,
1030- "sampled" : True ,
1031- }
1032- ],
1033- id = "sns-to-sqs" ,
923+ {"Records" : [SQS_RECORD , SQS_RECORD ]}, "aws_sqs" , "orders" , id = "sqs"
1034924 ),
925+ pytest .param ({"Records" : [SNS_RECORD ]}, "aws.sns" , "alerts" , id = "sns" ),
1035926 ],
1036927)
1037928def test_messaging_process_span (
1038- lambda_client , test_environment , aws_event , system , destination , links
929+ lambda_client , test_environment , aws_event , system , destination
1039930):
1040931 lambda_client .invoke (
1041932 FunctionName = "BasicOkSpanStreaming" ,
@@ -1049,12 +940,11 @@ def test_messaging_process_span(
1049940 for s in span_items
1050941 if _get_span_attr (s ["attributes" ], SPANDATA .SENTRY_OP ) == OP .QUEUE_PROCESS
1051942 ]
1052- # messages are linked, never the parent of the invocation.
1053- assert "parent_span_id" not in segment_span
1054943 assert process_span ["parent_span_id" ] == segment_span ["span_id" ]
1055944 assert process_span ["trace_id" ] == segment_span ["trace_id" ]
1056945 assert process_span ["name" ] == f"process { destination } "
1057- assert process_span ["links" ] == links
946+ # producer links stay on the invocation span, see `test_producer_links`.
947+ assert "links" not in process_span
1058948
1059949 attrs = process_span ["attributes" ]
1060950 assert _get_span_attr (attrs , SPANDATA .SENTRY_KIND ) == "consumer"
@@ -1080,7 +970,7 @@ def test_no_process_span_without_messages(lambda_client, test_environment):
1080970def test_process_span_error (lambda_client , test_environment ):
1081971 response = lambda_client .invoke (
1082972 FunctionName = "RaiseErrorSpanStreaming" ,
1083- Payload = json .dumps ({"Records" : [_sqs_record () ]}),
973+ Payload = json .dumps ({"Records" : [SQS_RECORD ]}),
1084974 )
1085975
1086976 # the handler's exception still reaches the Lambda runtime.
0 commit comments