null `headers` from API Gateway causes handler to return null
jstephenson opened this issue · 2 comments
Expected Behavior
When a Lambda is invoked with an API Gateway REST proxy input payload with null
headers it should return the Lambda's response. null
headers is the basic behaviour when using the API Gateway test client where no headers are specified. Without the DD wrapper the response is passed through as expected.
{
"event": {
...
"headers": null,
...
}
}
Actual Behavior
https://github.com/DataDog/datadog-lambda-js/blob/main/src/trace/context.ts#L260 is not guarded properly (see the caller) because typeof null === 'object'
in JS which causes an exception during
datadog-lambda-js/src/index.ts
Lines 116 to 124 in 94c9361
For a reason I can't immediately identify this scenario leads to null
returning from the Lambda (which the runtime will return if the handler returned undefined
which I suspect is happening).
Steps to Reproduce the Problem
- Lambda wrapped in DD (can statically return 200 or whatever)
- Invoke with API Gateway payload including
"headers": null
- Observe
null
response - Change to
"headers": {}
- Observe proper response
Specifications
- Datadog Lambda Layer version: 50
- Node version: 12.x
Hi @jstephenson, thanks for the bug report. I've pushed a release with a fix for this issue, (Layer Version 51, npm release 3.51.0).
Thanks :). Do you have any sense of why this condition would have yielded a null
response from the handler? A read of the code would suggest it should have continued on normally.