diff --git a/.gitignore b/.gitignore index d2fc83ca..1a07dec0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,9 +6,10 @@ integration_tests/recorder-extension/ext.zip integration_tests/.DS_Store integration_tests/bootstrap integration_tests/src/bin +integration_tests/src/csharp-tests/bin +integration_tests/src/csharp-tests/obj .DS_Store .layers extensions scripts/.cache scripts/.src -scripts/.layers \ No newline at end of file diff --git a/integration_tests/run.sh b/integration_tests/run.sh index d29cde28..a311dc28 100755 --- a/integration_tests/run.sh +++ b/integration_tests/run.sh @@ -47,7 +47,15 @@ cd src for go_dir in "${go_test_dirs[@]}"; do env GOOS=linux go build -ldflags="-s -w" -o bin/"$go_dir" go-tests/"$go_dir"/main.go done -cd .. + +#build .NET function +cd csharp-tests +dotnet restore +set +e #set this so we don't exit if the tools are already installed +dotnet tool install -g Amazon.Lambda.Tools --framework netcoreapp3.1 +dotnet lambda package --configuration Release --framework netcoreapp3.1 --output-package bin/Release/netcoreapp3.1/handler.zip +set -e +cd ../../ if [ -z "$NODE_LAYER_VERSION" ]; then echo "NODE_LAYER_VERSION not found, using the default" @@ -79,12 +87,13 @@ NODE_LAYER_VERSION=${NODE_LAYER_VERSION} \ serverless deploy --stage ${stage} # invoke functions -python_node_function_names=("enhanced-metric-node" "enhanced-metric-python" "no-enhanced-metric-node" "no-enhanced-metric-python" "timeout-python" "timeout-node" "error-node" "error-python") -python_node_log_function_names=("log-node" "log-python") +metric_function_names=("enhanced-metric-node" "enhanced-metric-python" "metric-csharp" "no-enhanced-metric-node" "no-enhanced-metric-python" "timeout-python" "timeout-node") +log_function_names=("log-node" "log-python" "log-csharp") + go_function_names=("with-ddlambda-go" "without-ddlambda-go" "timeout-go") trace_function_names=("simple-trace-node" "simple-trace-python" "simple-trace-go") -all_functions=("${python_node_function_names[@]}" "${python_node_log_function_names[@]}" "${go_function_names[@]}" "${trace_function_names[@]}") +all_functions=("${metric_function_names[@]}" "${log_function_names[@]}" "${go_function_names[@]}" "${trace_function_names[@]}") set +e # Don't exit this script if an invocation fails or there's a diff @@ -123,7 +132,7 @@ for function_name in "${all_functions[@]}"; do done # Replace invocation-specific data like timestamps and IDs with XXX to normalize across executions - if [[ " ${python_node_function_names[@]} " =~ " ${function_name} " ]]; then + if [[ " ${metric_function_names[*]} " =~ " ${function_name} " ]]; then # Normalize metrics logs=$( echo "$raw_logs" | @@ -142,7 +151,7 @@ for function_name in "${all_functions[@]}"; do perl -p -e "s/$stage/XXXXXX/g" | sort ) - elif [[ " ${python_node_log_function_names[@]} " =~ " ${function_name} " ]]; then + elif [[ " ${log_function_names[*]} " =~ " ${function_name} " ]]; then # Normalize logs logs=$( echo "$raw_logs" | @@ -155,7 +164,7 @@ for function_name in "${all_functions[@]}"; do perl -p -e "s/(\"message\":\").*(XXX LOG)/\1\2\3/g" | grep XXX ) - elif [[ " ${go_function_names[@]} " =~ " ${function_name} " ]]; then + elif [[ " ${go_function_names[*]} " =~ " ${function_name} " ]]; then logs=$( echo "$raw_logs" | grep -E "\[sketch\]|\[log\]" | diff --git a/integration_tests/serverless.yml b/integration_tests/serverless.yml index 98f238b7..e7397706 100644 --- a/integration_tests/serverless.yml +++ b/integration_tests/serverless.yml @@ -242,3 +242,35 @@ functions: DD_EXTRA_TAGS: tagC:valueC tagD:valueD DD_TRACE_ENABLED: true DD_APM_DD_URL: http://127.0.0.1:3333 + + metric-csharp: + runtime: dotnetcore3.1 + handler: CsharpHandlers::AwsDotnetCsharp.Handler::Hello + package: + individually: true + artifact: src/csharp-tests/bin/Release/netcoreapp3.1/handler.zip + layers: + - { Ref: RecorderExtensionLambdaLayer } + - { Ref: DatadogExtensionIntegrationTestLambdaLayer } + environment: + DD_TAGS: tagA:valueA tagB:valueB + DD_EXTRA_TAGS: tagC:valueC tagD:valueD + DD_LOGS_ENABLED: true + DD_SERVERLESS_LOGS_ENABLED: true + DD_LOGS_INJECTION: true + + log-csharp: + runtime: dotnetcore3.1 + handler: CsharpHandlers::AwsDotnetCsharp.Handler::Logs + package: + individually: true + artifact: src/csharp-tests/bin/Release/netcoreapp3.1/handler.zip + layers: + - { Ref: RecorderExtensionLambdaLayer } + - { Ref: DatadogExtensionIntegrationTestLambdaLayer } + environment: + DD_TAGS: tagA:valueA tagB:valueB + DD_EXTRA_TAGS: tagC:valueC tagD:valueD + DD_LOGS_ENABLED: true + DD_SERVERLESS_LOGS_ENABLED: true + DD_LOGS_INJECTION: true diff --git a/integration_tests/snapshots/log-csharp b/integration_tests/snapshots/log-csharp new file mode 100644 index 00000000..0fb86802 --- /dev/null +++ b/integration_tests/snapshots/log-csharp @@ -0,0 +1,4 @@ +[log] {"message":{"message":"START XXX"}} +[log] {"message":{"message":"XXX Log 0 XXX\n","lambda":{"arn":"arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp"}},"status":"info","timestamp":TIMESTAMP,"hostname":"arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp","service":"integration-tests-service","ddsource":"lambda","ddtags":"account_id:601427279990,account_id:601427279990,account_id:601427279990,architecture:x86_64,architecture:x86_64,architecture:x86_64,aws_account:601427279990,aws_account:601427279990,aws_account:601427279990,dd_extension_version:123,dd_extension_version:123,dd_extension_version:123,env:integration-tests-env,env:integration-tests-env,env:integration-tests-env,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,memorysize:1024,memorysize:1024,memorysize:1024,region:sa-east-1,region:sa-east-1,region:sa-east-1,resource:integration-tests-extension-STAGE-log-csharp,resource:integration-tests-extension-STAGE-log-csharp,resource:integration-tests-extension-STAGE-log-csharp,service:integration-tests-service,service:integration-tests-service,service:integration-tests-service,taga:valuea,taga:valuea,taga:valuea,tagb:valueb,tagb:valueb,tagb:valueb,tagc:valuec,tagc:valuec,tagc:valuec,tagd:valued,tagd:valued,tagd:valued,version:integration-tests-version,version:integration-tests-version,version:integration-tests-version"} +[log] {"message":{"message":"XXX Log 1 XXX\n","lambda":{"arn":"arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp"}},"status":"info","timestamp":TIMESTAMP,"hostname":"arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp","service":"integration-tests-service","ddsource":"lambda","ddtags":"account_id:601427279990,account_id:601427279990,account_id:601427279990,architecture:x86_64,architecture:x86_64,architecture:x86_64,aws_account:601427279990,aws_account:601427279990,aws_account:601427279990,dd_extension_version:123,dd_extension_version:123,dd_extension_version:123,env:integration-tests-env,env:integration-tests-env,env:integration-tests-env,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,memorysize:1024,memorysize:1024,memorysize:1024,region:sa-east-1,region:sa-east-1,region:sa-east-1,resource:integration-tests-extension-STAGE-log-csharp,resource:integration-tests-extension-STAGE-log-csharp,resource:integration-tests-extension-STAGE-log-csharp,service:integration-tests-service,service:integration-tests-service,service:integration-tests-service,taga:valuea,taga:valuea,taga:valuea,tagb:valueb,tagb:valueb,tagb:valueb,tagc:valuec,tagc:valuec,tagc:valuec,tagd:valued,tagd:valued,tagd:valued,version:integration-tests-version,version:integration-tests-version,version:integration-tests-version"} +[log] {"message":{"message":"XXX Log 2 XXX\n","lambda":{"arn":"arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp"}},"status":"info","timestamp":TIMESTAMP,"hostname":"arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp","service":"integration-tests-service","ddsource":"lambda","ddtags":"account_id:601427279990,account_id:601427279990,account_id:601427279990,architecture:x86_64,architecture:x86_64,architecture:x86_64,aws_account:601427279990,aws_account:601427279990,aws_account:601427279990,dd_extension_version:123,dd_extension_version:123,dd_extension_version:123,env:integration-tests-env,env:integration-tests-env,env:integration-tests-env,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,functionname:integration-tests-extension-STAGE-log-csharp,memorysize:1024,memorysize:1024,memorysize:1024,region:sa-east-1,region:sa-east-1,region:sa-east-1,resource:integration-tests-extension-STAGE-log-csharp,resource:integration-tests-extension-STAGE-log-csharp,resource:integration-tests-extension-STAGE-log-csharp,service:integration-tests-service,service:integration-tests-service,service:integration-tests-service,taga:valuea,taga:valuea,taga:valuea,tagb:valueb,tagb:valueb,tagb:valueb,tagc:valuec,tagc:valuec,tagc:valuec,tagd:valued,tagd:valued,tagd:valued,version:integration-tests-version,version:integration-tests-version,version:integration-tests-version"} diff --git a/integration_tests/snapshots/metric-csharp b/integration_tests/snapshots/metric-csharp new file mode 100644 index 00000000..4aaa7d5c --- /dev/null +++ b/integration_tests/snapshots/metric-csharp @@ -0,0 +1,2 @@ +[sketch] {"metric":"aws.lambda.enhanced.runtime_duration","distributions":null,"tags":["account_id:601427279990","architecture:x86_64","aws_account:601427279990","cold_start:true","dd_extension_version:123","env:integration-tests-env","function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-XXXXXX-metric-csharp","functionname:integration-tests-extension-XXXXXX-metric-csharp","memorysize:1024","region:sa-east-1","resource:integration-tests-extension-XXXXXX-metric-csharp","service:integration-tests-service","taga:valuea","tagb:valueb","tagc:valuec","tagd:valued","version:integration-tests-version"],"dogsketches":[{"ts":XXX,"cnt":1,"min":XXX,"max":XXX,"avg":XXX,"sum":XXX,"k":[XXX],"n":[1]}]} +[sketch] {"metric":"aws.lambda.enhanced.runtime_duration","distributions":null,"tags":["account_id:601427279990","architecture:x86_64","aws_account:601427279990","cold_start:true","dd_extension_version:123","env:integration-tests-env","function_arn:arn:aws:lambda:sa-east-1:601427279990:function:integration-tests-extension-XXXXXX-metric-csharp","functionname:integration-tests-extension-XXXXXX-metric-csharp","memorysize:1024","region:sa-east-1","resource:integration-tests-extension-XXXXXX-metric-csharp","service:integration-tests-service","taga:valuea","tagb:valueb","tagc:valuec","tagd:valued","version:integration-tests-version"],"dogsketches":[{"ts":XXX,"cnt":1,"min":XXX,"max":XXX,"avg":XXX,"sum":XXX,"k":[XXX],"n":[1]}]} diff --git a/integration_tests/src/csharp-tests/csharp.csproj b/integration_tests/src/csharp-tests/csharp.csproj new file mode 100644 index 00000000..44116bcd --- /dev/null +++ b/integration_tests/src/csharp-tests/csharp.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + true + CsharpHandlers + aws-csharp + + + + + + + + diff --git a/integration_tests/src/csharp-tests/handler.cs b/integration_tests/src/csharp-tests/handler.cs new file mode 100644 index 00000000..e6c4645a --- /dev/null +++ b/integration_tests/src/csharp-tests/handler.cs @@ -0,0 +1,34 @@ +using Amazon.Lambda.Core; +using System; + +[assembly:LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))] +namespace AwsDotnetCsharp + +{ + public class Handler + { + public Response Hello() + { + return new Response(200, "ok"); + } + + public Response Logs() + { + Console.WriteLine("XXX Log 0 XXX"); + Console.WriteLine("XXX Log 1 XXX"); + Console.WriteLine("XXX Log 2 XXX"); + return new Response(200, "ok"); + } + } + public class Response + { + public int statusCode {get; set;} + public string body {get; set;} + + public Response(int code, string message){ + statusCode = code; + body = message; + } + } + +} \ No newline at end of file