|
25 | 25 | SAM_TEMPLATE_FILE = "sam.template.yaml" |
26 | 26 | SAM_SHUTDOWN_TIMEOUT = 10 |
27 | 27 |
|
| 28 | +SQS_RECORD = { |
| 29 | + "messageId": "059f36b4-87a3-44ab-83d2-661975830a7d", |
| 30 | + "body": "{}", |
| 31 | + "eventSource": "aws:sqs", |
| 32 | + "eventSourceARN": "arn:aws:sqs:us-east-1:012345678912:orders", |
| 33 | +} |
| 34 | +SNS_RECORD = { |
| 35 | + "EventSource": "aws:sns", |
| 36 | + "Sns": {"TopicArn": "arn:aws:sns:us-east-1:012345678912:alerts"}, |
| 37 | +} |
| 38 | +APPSYNC_EVENT = { |
| 39 | + "arguments": {"id": "1"}, |
| 40 | + "info": {"fieldName": "getOrder", "parentTypeName": "Query"}, |
| 41 | +} |
| 42 | +EVENTBRIDGE_EVENT = { |
| 43 | + "version": "0", |
| 44 | + "id": "53dc4d37-cffa-4f76-80c9-8b7d4a4d2eaa", |
| 45 | + "detail-type": "Object Created", |
| 46 | + "source": "aws.s3", |
| 47 | + "account": "012345678912", |
| 48 | + "time": "2026-10-26T12:00:00Z", |
| 49 | + "region": "us-east-1", |
| 50 | + "resources": [], |
| 51 | + "detail": {}, |
| 52 | +} |
| 53 | + |
28 | 54 |
|
29 | 55 | @pytest.fixture(scope="session", autouse=True) |
30 | 56 | def test_environment(): |
@@ -767,6 +793,7 @@ def test_no_error(lambda_client, test_environment): |
767 | 793 | assert _get_span_attr(attrs, SPANDATA.AWS_LOG_STREAM_NAMES) == [ |
768 | 794 | LATEST_FUNCTION_VERSION |
769 | 795 | ] |
| 796 | + assert _get_span_attr(attrs, SPANDATA.FAAS_TRIGGER) == "other" |
770 | 797 |
|
771 | 798 |
|
772 | 799 | def test_error(lambda_client, test_environment): |
@@ -820,6 +847,73 @@ def test_error(lambda_client, test_environment): |
820 | 847 | assert _get_span_attr(attrs, SPANDATA.AWS_LOG_STREAM_NAMES) == [ |
821 | 848 | LATEST_FUNCTION_VERSION |
822 | 849 | ] |
| 850 | + assert _get_span_attr(attrs, SPANDATA.FAAS_TRIGGER) == "other" |
| 851 | + |
| 852 | + |
| 853 | +@pytest.mark.parametrize( |
| 854 | + "aws_event,trigger", |
| 855 | + [ |
| 856 | + pytest.param( |
| 857 | + {"httpMethod": "GET", "path": "/", "requestContext": {"stage": "prod"}}, |
| 858 | + "http", |
| 859 | + id="api-gateway-rest", |
| 860 | + ), |
| 861 | + pytest.param( |
| 862 | + { |
| 863 | + "version": "2.0", |
| 864 | + "routeKey": "GET /", |
| 865 | + "requestContext": {"http": {"method": "GET"}}, |
| 866 | + }, |
| 867 | + "http", |
| 868 | + id="api-gateway-http", |
| 869 | + ), |
| 870 | + pytest.param( |
| 871 | + {"Records": [{"cf": {"request": {"uri": "/"}}}]}, |
| 872 | + "http", |
| 873 | + id="cloudfront", |
| 874 | + ), |
| 875 | + pytest.param(APPSYNC_EVENT, "http", id="appsync"), |
| 876 | + pytest.param([APPSYNC_EVENT, APPSYNC_EVENT], "http", id="appsync-batch"), |
| 877 | + pytest.param({"Records": [SQS_RECORD, SQS_RECORD]}, "pubsub", id="sqs"), |
| 878 | + pytest.param({"Records": [SNS_RECORD]}, "pubsub", id="sns"), |
| 879 | + pytest.param( |
| 880 | + {"eventSource": "aws:kafka", "records": {"orders-0": [{}]}}, |
| 881 | + "pubsub", |
| 882 | + id="msk", |
| 883 | + ), |
| 884 | + pytest.param( |
| 885 | + EVENTBRIDGE_EVENT, |
| 886 | + "pubsub", |
| 887 | + id="eventbridge", |
| 888 | + ), |
| 889 | + pytest.param( |
| 890 | + { |
| 891 | + **EVENTBRIDGE_EVENT, |
| 892 | + "source": "aws.events", |
| 893 | + "detail-type": "Scheduled Event", |
| 894 | + }, |
| 895 | + "timer", |
| 896 | + id="eventbridge-schedule", |
| 897 | + ), |
| 898 | + pytest.param({"Records": [{"eventSource": "aws:s3"}]}, "datasource", id="s3"), |
| 899 | + pytest.param( |
| 900 | + [{"good dog": "Maisey"}, {"good dog": "Charlie"}], |
| 901 | + "other", |
| 902 | + id="list", |
| 903 | + ), |
| 904 | + ], |
| 905 | +) |
| 906 | +def test_trigger(lambda_client, test_environment, aws_event, trigger): |
| 907 | + lambda_client.invoke( |
| 908 | + FunctionName="BasicOkSpanStreaming", |
| 909 | + Payload=json.dumps(aws_event), |
| 910 | + ) |
| 911 | + |
| 912 | + (segment_span,) = [ |
| 913 | + s for s in test_environment["server"].span_items if s["is_segment"] |
| 914 | + ] |
| 915 | + attrs = segment_span["attributes"] |
| 916 | + assert _get_span_attr(attrs, SPANDATA.FAAS_TRIGGER) == trigger |
823 | 917 |
|
824 | 918 |
|
825 | 919 | def test_trace_continuation(lambda_client, test_environment): |
|
0 commit comments