You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Node.js agent incorrectly assumes that all fields are present in an API Gateway v2 proxy event object. While this appears to be true for API Gateway v1 proxy event, it is not true for API Gateway v2. For example, in v1, if there are no stage variables configured on the API Gateway stage, the stageVariables field in the proxy event is null. However, in v2, the field is absent. This applies to other fields - for example, if there are not path parameters or query string parameters in the request, the pathParameters and queryStringParameters fields are absent from the event object.
The following logic assumes that all fields are present in API Gateway v2 proxy event.
The implication is that isGatewayV2Event is returning false for valid API Gateway v2 proxy events. In turn, this means that isApiGatewayLambdaProxy is false. For my use case, this meant that tracing headers were not being respected in the proxy event and a new trace was created, rather than adding segments to the existing trace.
The workaround is to set the payload version to 1.0 for API Gateway routes.
Expected Behavior
API Gateway v2 proxy events with absent fields are recognised as being valid. In turn, trace headers are pulled out of the event and used for distributed tracing.
Steps to Reproduce
Deploy attached CloudFormation template (drop .txt extension, if required). This template creates an Lambda function, API Gateway HTTP API, and sets up an associated integration and route.
Perform a HTTP GET to the / route of the API. Observe in the Lambda function's logs that the stageVariables key among others (for example, queryStringParameters and pathParameters) is absent in the event object.
joshuapmorgan
changed the title
AWS API Gateway HTTP API (payload v2) event not detected correctly
Amazon API Gateway HTTP API (payload v2) event not detected correctly
Nov 19, 2024
Description
The Node.js agent incorrectly assumes that all fields are present in an API Gateway v2 proxy event object. While this appears to be true for API Gateway v1 proxy event, it is not true for API Gateway v2. For example, in v1, if there are no stage variables configured on the API Gateway stage, the
stageVariables
field in the proxy event is null. However, in v2, the field is absent. This applies to other fields - for example, if there are not path parameters or query string parameters in the request, thepathParameters
andqueryStringParameters
fields are absent from the event object.The following logic assumes that all fields are present in API Gateway v2 proxy event.
node-newrelic/lib/serverless/api-gateway.js
Lines 142 to 160 in 9640030
The implication is that
isGatewayV2Event
is returning false for valid API Gateway v2 proxy events. In turn, this means thatisApiGatewayLambdaProxy
is false. For my use case, this meant that tracing headers were not being respected in the proxy event and a new trace was created, rather than adding segments to the existing trace.The workaround is to set the payload version to 1.0 for API Gateway routes.
Expected Behavior
API Gateway v2 proxy events with absent fields are recognised as being valid. In turn, trace headers are pulled out of the event and used for distributed tracing.
Steps to Reproduce
stageVariables
key among others (for example,queryStringParameters
andpathParameters
) is absent in the event object.Your Environment
AWS Lambda, nodejs18.x
newrelic 12.7.0
template.yaml.txt
The text was updated successfully, but these errors were encountered: