Skip to content

Commit ed89375

Browse files
authored
Add .NET handlers and tests (#37)
* add csharp handler and test * remove unused line in gitignore
1 parent 7973f5a commit ed89375

File tree

7 files changed

+105
-8
lines changed

7 files changed

+105
-8
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ integration_tests/recorder-extension/ext.zip
66
integration_tests/.DS_Store
77
integration_tests/bootstrap
88
integration_tests/src/bin
9+
integration_tests/src/csharp-tests/bin
10+
integration_tests/src/csharp-tests/obj
911
.DS_Store
1012
.layers
1113
extensions
1214
scripts/.cache
1315
scripts/.src
14-
scripts/.layers

integration_tests/run.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ cd src
4747
for go_dir in "${go_test_dirs[@]}"; do
4848
env GOOS=linux go build -ldflags="-s -w" -o bin/"$go_dir" go-tests/"$go_dir"/main.go
4949
done
50-
cd ..
50+
51+
#build .NET function
52+
cd csharp-tests
53+
dotnet restore
54+
set +e #set this so we don't exit if the tools are already installed
55+
dotnet tool install -g Amazon.Lambda.Tools --framework netcoreapp3.1
56+
dotnet lambda package --configuration Release --framework netcoreapp3.1 --output-package bin/Release/netcoreapp3.1/handler.zip
57+
set -e
58+
cd ../../
5159

5260
if [ -z "$NODE_LAYER_VERSION" ]; then
5361
echo "NODE_LAYER_VERSION not found, using the default"
@@ -79,12 +87,13 @@ NODE_LAYER_VERSION=${NODE_LAYER_VERSION} \
7987
serverless deploy --stage ${stage}
8088

8189
# invoke functions
82-
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")
83-
python_node_log_function_names=("log-node" "log-python")
90+
metric_function_names=("enhanced-metric-node" "enhanced-metric-python" "metric-csharp" "no-enhanced-metric-node" "no-enhanced-metric-python" "timeout-python" "timeout-node")
91+
log_function_names=("log-node" "log-python" "log-csharp")
92+
8493
go_function_names=("with-ddlambda-go" "without-ddlambda-go" "timeout-go")
8594
trace_function_names=("simple-trace-node" "simple-trace-python" "simple-trace-go")
8695

87-
all_functions=("${python_node_function_names[@]}" "${python_node_log_function_names[@]}" "${go_function_names[@]}" "${trace_function_names[@]}")
96+
all_functions=("${metric_function_names[@]}" "${log_function_names[@]}" "${go_function_names[@]}" "${trace_function_names[@]}")
8897

8998
set +e # Don't exit this script if an invocation fails or there's a diff
9099

@@ -123,7 +132,7 @@ for function_name in "${all_functions[@]}"; do
123132
done
124133

125134
# Replace invocation-specific data like timestamps and IDs with XXX to normalize across executions
126-
if [[ " ${python_node_function_names[@]} " =~ " ${function_name} " ]]; then
135+
if [[ " ${metric_function_names[*]} " =~ " ${function_name} " ]]; then
127136
# Normalize metrics
128137
logs=$(
129138
echo "$raw_logs" |
@@ -142,7 +151,7 @@ for function_name in "${all_functions[@]}"; do
142151
perl -p -e "s/$stage/XXXXXX/g" |
143152
sort
144153
)
145-
elif [[ " ${python_node_log_function_names[@]} " =~ " ${function_name} " ]]; then
154+
elif [[ " ${log_function_names[*]} " =~ " ${function_name} " ]]; then
146155
# Normalize logs
147156
logs=$(
148157
echo "$raw_logs" |
@@ -155,7 +164,7 @@ for function_name in "${all_functions[@]}"; do
155164
perl -p -e "s/(\"message\":\").*(XXX LOG)/\1\2\3/g" |
156165
grep XXX
157166
)
158-
elif [[ " ${go_function_names[@]} " =~ " ${function_name} " ]]; then
167+
elif [[ " ${go_function_names[*]} " =~ " ${function_name} " ]]; then
159168
logs=$(
160169
echo "$raw_logs" |
161170
grep -E "\[sketch\]|\[log\]" |

integration_tests/serverless.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,35 @@ functions:
242242
DD_EXTRA_TAGS: tagC:valueC tagD:valueD
243243
DD_TRACE_ENABLED: true
244244
DD_APM_DD_URL: http://127.0.0.1:3333
245+
246+
metric-csharp:
247+
runtime: dotnetcore3.1
248+
handler: CsharpHandlers::AwsDotnetCsharp.Handler::Hello
249+
package:
250+
individually: true
251+
artifact: src/csharp-tests/bin/Release/netcoreapp3.1/handler.zip
252+
layers:
253+
- { Ref: RecorderExtensionLambdaLayer }
254+
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
255+
environment:
256+
DD_TAGS: tagA:valueA tagB:valueB
257+
DD_EXTRA_TAGS: tagC:valueC tagD:valueD
258+
DD_LOGS_ENABLED: true
259+
DD_SERVERLESS_LOGS_ENABLED: true
260+
DD_LOGS_INJECTION: true
261+
262+
log-csharp:
263+
runtime: dotnetcore3.1
264+
handler: CsharpHandlers::AwsDotnetCsharp.Handler::Logs
265+
package:
266+
individually: true
267+
artifact: src/csharp-tests/bin/Release/netcoreapp3.1/handler.zip
268+
layers:
269+
- { Ref: RecorderExtensionLambdaLayer }
270+
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
271+
environment:
272+
DD_TAGS: tagA:valueA tagB:valueB
273+
DD_EXTRA_TAGS: tagC:valueC tagD:valueD
274+
DD_LOGS_ENABLED: true
275+
DD_SERVERLESS_LOGS_ENABLED: true
276+
DD_LOGS_INJECTION: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[log] {"message":{"message":"START XXX"}}
2+
[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"}
3+
[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"}
4+
[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"}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
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]}]}
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]}]}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
6+
<AssemblyName>CsharpHandlers</AssemblyName>
7+
<PackageId>aws-csharp</PackageId>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Amazon.Lambda.Core" Version="1.1.0" />
12+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.0.1" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Amazon.Lambda.Core;
2+
using System;
3+
4+
[assembly:LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
5+
namespace AwsDotnetCsharp
6+
7+
{
8+
public class Handler
9+
{
10+
public Response Hello()
11+
{
12+
return new Response(200, "ok");
13+
}
14+
15+
public Response Logs()
16+
{
17+
Console.WriteLine("XXX Log 0 XXX");
18+
Console.WriteLine("XXX Log 1 XXX");
19+
Console.WriteLine("XXX Log 2 XXX");
20+
return new Response(200, "ok");
21+
}
22+
}
23+
public class Response
24+
{
25+
public int statusCode {get; set;}
26+
public string body {get; set;}
27+
28+
public Response(int code, string message){
29+
statusCode = code;
30+
body = message;
31+
}
32+
}
33+
34+
}

0 commit comments

Comments
 (0)