Skip to content

Commit

Permalink
Integration tests complete
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Aug 6, 2024
1 parent 2b0633c commit 77ce40f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public bool ValidateWebRequestParameters(InstrumentedMethodCall instrumentedMeth
{
dynamic requestContext = input.RequestContext;

return !string.IsNullOrEmpty(requestContext.Http.Method) && !string.IsNullOrEmpty(requestContext.Http.Path);
if (requestContext.Http != null)
return !string.IsNullOrEmpty(requestContext.Http.Method) && !string.IsNullOrEmpty(requestContext.Http.Path);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SPDX-License-Identifier: Apache-2.0
<exactMethodMatcher methodName=".ctor" />
</match>
</tracerFactory>
<!-- Instrument Amazon.Lambda.AspNetCoreServer::Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction`2::FunctionHandlerAsync -->
<!-- Instrument the function handler for AspNetCore lambdas -->
<tracerFactory name="NewRelic.Providers.Wrapper.AwsLambda.HandlerMethod">
<match assemblyName="Amazon.Lambda.AspNetCoreServer" className="Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction`2">
<exactMethodMatcher methodName="FunctionHandlerAsync" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="9.0.0" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.10.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ApplicationHelperLibraries\ApplicationLifecycle\ApplicationLifecycle.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,33 @@ private static string GetHandlerFromArgs(string[] args)

private static HandlerWrapper GetHandlerWrapper()
{
var defaultLambdaJsonSerializer = new DefaultLambdaJsonSerializer();

switch (_handlerToInvoke)
{
case "APIGatewayProxyFunctionEntryPoint":
{
var entryPoint = new APIGatewayProxyFunctionEntryPoint();
Func<APIGatewayProxyRequest, ILambdaContext, Task<APIGatewayProxyResponse>> handlerFunc = entryPoint.FunctionHandlerAsync;

return HandlerWrapper.GetHandlerWrapper(handlerFunc, new DefaultLambdaJsonSerializer());
return HandlerWrapper.GetHandlerWrapper(handlerFunc, defaultLambdaJsonSerializer);
}
case "ApplicationLoadBalancerFunctionEntryPoint":
{
var entryPoint = new ApplicationLoadBalancerFunctionEntryPoint();
Func<ApplicationLoadBalancerRequest, ILambdaContext, Task<ApplicationLoadBalancerResponse>> handlerFunc = entryPoint.FunctionHandlerAsync;

return HandlerWrapper.GetHandlerWrapper(handlerFunc, new DefaultLambdaJsonSerializer());
return HandlerWrapper.GetHandlerWrapper(handlerFunc, defaultLambdaJsonSerializer);
}
case "APIGatewayHttpApiV2ProxyFunctionEntryPoint":
{
var entryPoint = new APIGatewayHttpApiV2ProxyFunctionEntryPoint();
Func<APIGatewayHttpApiV2ProxyRequest, ILambdaContext, Task<APIGatewayHttpApiV2ProxyResponse>> handlerFunc = entryPoint.FunctionHandlerAsync;

return HandlerWrapper.GetHandlerWrapper(handlerFunc, new DefaultLambdaJsonSerializer());
return HandlerWrapper.GetHandlerWrapper(handlerFunc, defaultLambdaJsonSerializer);
}
default:
throw new ArgumentException("Handler not found.");
throw new ArgumentException($"Handler not found: {_handlerToInvoke}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ private void ValidateServerlessPayload(ServerlessPayload serverlessPayload)
{ "request.headers.header1", "value1" },
{ "request.headers.header2", "value1,value2" },
{ "request.method", "GET" },
{ "request.uri", "/api.values" },
{ "request.parameters.parameter1", "value1,value2" },
{ "request.parameters.parameter2", "value" },
{ "request.uri", "/api/values" },
{ "http.statusCode", 200 },
{ "response.status", "200" },
};
Expand All @@ -79,7 +77,7 @@ private void ValidateServerlessPayload(ServerlessPayload serverlessPayload)
}
}

public class AwsLambdaAPIGatewayHttpApiV2ProxyRequestAutoInstrumentationTestTestNet8 : AwsLambdaAPIGatewayRequestAutoInstrumentationTest<LambdaAPIGatewayHttpApiV2ProxyRequestAutoInstrumentationTriggerFixtureNet8>
public class AwsLambdaAPIGatewayHttpApiV2ProxyRequestAutoInstrumentationTestTestNet8 : AwsLambdaAPIGatewayHttpApiV2ProxyRequestAutoInstrumentationTest<LambdaAPIGatewayHttpApiV2ProxyRequestAutoInstrumentationTriggerFixtureNet8>
{
public AwsLambdaAPIGatewayHttpApiV2ProxyRequestAutoInstrumentationTestTestNet8(LambdaAPIGatewayHttpApiV2ProxyRequestAutoInstrumentationTriggerFixtureNet8 fixture, ITestOutputHelper output)
: base(fixture, output, "WebTransaction/MVC/Values/Get")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,41 @@ public void EnqueueAPIGatewayProxyRequest()

public void EnqueueAPIGatewayHttpApiV2ProxyRequest()
{
var apiGatewayProxyRequestJson = $$"""
var apiGatewayHttpApiV2ProxyRequestJson = $$$"""
{
"version": "2.0",
"routeKey": "$default",
"rawPath": "/",
"requestContext": {
"http": {
"method": "GET",
"path": "/"
"Version": "2.0",
"RouteKey": "$default",
"RawPath": "/api/values",
"Headers": {
"Header1": "value1",
"Header2": "value1,value2"
},
"RequestContext": {
"AccountId": "123456789012",
"ApiId": "api-id",
"DomainName": "id.execute-api.us-east-1.amazonaws.com",
"DomainPrefix": "id",
"Http": {
"Method": "GET",
"Path": "/api/values",
"Protocol": "HTTP/1.1",
"SourceIp": "192.168.0.1/32",
"UserAgent": "agent"
},
"RequestId": "id",
"RouteKey": "$default",
"Stage": "$default",
"Time": "12/Mar/2020:19:03:58 +0000",
"TimeEpoch": 1583348638390
},
"StageVariables": {
"stageVariable1": "value1",
"stageVariable2": "value2"
}
}
}
""";

EnqueueLambdaEvent(apiGatewayProxyRequestJson);
EnqueueLambdaEvent(apiGatewayHttpApiV2ProxyRequestJson);
}

public void EnqueueApplicationLoadBalancerRequest()
Expand Down

0 comments on commit 77ce40f

Please sign in to comment.