TypeError: Cannot read properties of undefined (reading 'then')
chelseaharalson opened this issue · 8 comments
Expected Behavior
No issues
Actual Behavior
When invoking my lambda function, I get this error coming from the datadog library:
TypeError: Cannot read properties of undefined (reading 'then')
,
at /opt/nodejs/node_modules/dd-trace/packages/dd-trace/src/lambda/handler.js:89:43
,
at /opt/nodejs/node_modules/datadog-lambda-js/utils/handler.js:166:25
,
at /opt/nodejs/node_modules/datadog-lambda-js/index.js:223:70
,
at step (/opt/nodejs/node_modules/datadog-lambda-js/index.js:44:23)
,
at Object.next (/opt/nodejs/node_modules/datadog-lambda-js/index.js:25:53)
,
at /opt/nodejs/node_modules/datadog-lambda-js/index.js:19:71
,
at new Promise (<anonymous>)
,
at __awaiter (/opt/nodejs/node_modules/datadog-lambda-js/index.js:15:12)
,
at traceListenerOnWrap (/opt/nodejs/node_modules/datadog-lambda-js/index.js:200:36)
,
at /opt/nodejs/node_modules/dd-trace/packages/dd-trace/src/tracer.js:103:56
This just started happening yesterday. Previously it worked with no code changes.
Specifications
- Datadog Lambda Layer version: I am using the latest version of "serverless-plugin-datadog": "5.36.0"
- Node version: I tried both 16 and 18 - happens in both
- I believe this pull request could have caused the issue: DataDog/dd-trace-js@1538225
Hi @chelseaharalson - thanks for reaching out!
DataDog/dd-trace-js#3278 definitely seems suspect here - would you happen to have a simple lambda handler which reproduces this? Could you share more about the installation and instrumentation process you're using?
Thanks!
Hi @astuyve - thanks for taking a look!
I'm going to paste some code, but take out some of the body. It looks like this:
/******************************************************/
// Okta lambda authorizer for Amazon API Gateway
require('dotenv').config();
const OktaJwtVerifier = require('@okta/jwt-verifier');
/******************************************************/
const oktaJwtVerifier = new OktaJwtVerifier({
issuer: process.env.ISSUER, // required
clientId: process.env.CLIENT_ID, // required
assertClaims: {
aud: process.env.AUDIENCE
}
});
const AuthPolicy = require('./auth-policy');
/******************************************************/
exports.handler = function (event, context) {
if (arr[0] !== "Bearer") {
var policy = new AuthPolicy(...);
policy.allowAllMethods();
return context.succeed(policy.build())
}
oktaJwtVerifier.verifyAccessToken(access_token)
.then(jwt => {
var claims = jwt.claims;
var policyContext = {
sub: claims.sub
}
var policy = new AuthPolicy(...);
policy.allowAllMethods()
return context.succeed(policy.build());
})
.catch(err => {
console.log(err)
return context.fail('Unauthorized');
});
}
That's perfect, thank you so much!
I'll work on reproducing and fixing this issue and update this when it's ready!
Thanks!
Hey! I just merged a fix for this in dd-trace: DataDog/dd-trace-js#3404
I'll update this ticket when we publish a new version, thanks!
Hi, we're drafting the dd-trace release now and then I will release this library.
Thank you for your patience!
This should be fixed in 7.95 and layer 95!
Thank you so much! @astuyve