DataDog / datadog-lambda-js

The Datadog AWS Lambda Library for Node
Apache License 2.0
105 stars 35 forks source link

Lambda init failure with Nodejs 20.x version upgrade #546

Open ananthbh-te opened 1 month ago

ananthbh-te commented 1 month ago

Hi Team,

I started working on upgrading my Nodejs lambda from 16.x to 20.x and facing an issue during the lambda init.

Expected Behavior

Lambda function creation should be successful

Actual Behavior

Lambda function is failed to create with below message

Error: waiting for Lambda Provisioned Concurrency Config (aws-lambd-axx-xxx-xxx,2) create: unexpected state 'FAILED', wanted target 'READY'. last error: FUNCTION_ERROR_INIT_FAILURE

Steps to Reproduce the Problem

Update the lambda from 16.x to 20.x and using the Datadog Lambda Layer version: Datadog-Node20-x:109

Datadog Lambda Extension layer Datadog-Extension - arn:aws:lambda:eu-central-1:464622532012:layer:Datadog-Extension:57

Datadog Lambda library for JavaScript layer Datadog-lambda-js arn:aws:lambda:eu-central-1:464622532012:layer:Datadog-Node20-x:109

Specifications

Stacktrace

error log message

2024-05-16T09:11:12.321Z    undefined   ERROR   Uncaught Exception  {
    "errorType": "TypeError",
    "errorMessage": "The \"this\" argument must be an instance of Performance. Received undefined",
    "code": "ERR_INVALID_ARG_TYPE",
    "stack": [
        "TypeError [ERR_INVALID_ARG_TYPE]: The \"this\" argument must be an instance of Performance. Received undefined",
        "    at now (node:internal/perf/performance:135:5)",
        "    at DatadogSpan._createContext (/var/task/node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:164:60)",
        "    at new DatadogSpan (/var/task/node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:36:30)",
        "    at DatadogTracer.startSpan (/var/task/node_modules/dd-trace/packages/dd-trace/src/opentracing/tracer.js:56:18)",
        "    at /var/task/node_modules/dd-trace/packages/datadog-plugin-http/src/client.js:37:32",
        "    at Subscription._handler (/var/task/node_modules/dd-trace/packages/dd-trace/src/plugins/plugin.js:12:9)",
        "    at Channel.publish (node:diagnostics_channel:142:9)",
        "    at /var/task/node_modules/dd-trace/packages/datadog-instrumentations/src/http/client.js:52:23",
        "    at AsyncResource.runInAsyncScope (node:async_hooks:206:9)",
        "    at Object.request (/var/task/node_modules/dd-trace/packages/datadog-instrumentations/src/http/client.js:51:28)"
    ]
}
purple4reina commented 1 month ago

@ananthbh-te thanks for reporting this, I'm looking into it.

ananthbh-te commented 1 month ago

Thanks for taking a look @purple4reina

I'm able to start the lambda function, however the function is failing with same error as mentioned above for each invocation.

FYI - Same lambda function is working without any issue for nodejs18.x as i tested it by upgrading it from 16.x to 18.x, Seems to be problem with Node20.x, Please let me know on your findings.

2024-05-18T12:41:02.827Z
{
    "e": 1716036062.787,
    "m": "aws.lambda.enhanced.errors",
    "t": [
        "region:xxxxx",
        "account_id:xxxxx",
        "functionname:axxx",
        "resource:xxxxx",
        "cold_start:true",
        "memorysize:128",
        "datadog_lambda:v8.108.0",
        "runtime:nodejs20.x"
    ],
    "v": 1
}

2024-05-18T12:41:02.828Z    832285a4-7359-475b-a376-06aad2d1d0d4    ERROR   [dd.trace_id=2894475163638417218 dd.span_id=4322268747100736326] Invoke Error   
{
    "errorType": "TypeError",
    "errorMessage": "The \"this\" argument must be an instance of Performance. Received undefined",
    "code": "ERR_INVALID_ARG_TYPE",
    "stack": [
        "TypeError [ERR_INVALID_ARG_TYPE]: The \"this\" argument must be an instance of Performance. Received undefined",
        "    at now (node:internal/perf/performance:135:5)",
        "    at DatadogSpan._createContext (/var/task/node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:164:60)",
        "    at new DatadogSpan (/var/task/node_modules/dd-trace/packages/dd-trace/src/opentracing/span.js:36:30)",
        "    at DatadogTracer.startSpan (/var/task/node_modules/dd-trace/packages/dd-trace/src/opentracing/tracer.js:56:18)",
        "    at DatadogTracer.trace (/var/task/node_modules/dd-trace/packages/dd-trace/src/tracer.js:32:23)",
        "    at /var/task/node_modules/dd-trace/packages/dd-trace/src/tracer.js:97:23",
        "    at /opt/nodejs/node_modules/datadog-lambda-js/index.js:250:91",
        "    at step (/opt/nodejs/node_modules/datadog-lambda-js/index.js:44:23)",
        "    at Object.throw (/opt/nodejs/node_modules/datadog-lambda-js/index.js:25:53)",
        "    at rejected (/opt/nodejs/node_modules/datadog-lambda-js/index.js:17:65)"
    ]
}
ananthbh-te commented 1 month ago

Any updates here would be helpful..

ananthbh-te commented 1 month ago

Any progress here, this is blocking me to upgrade it to the nodejs 20.x..