lumigo-io / lumigo-cdk-constructs

Home to the Lumigo constructs for the AWS Cloud Development Kit (AWS CDK)
Apache License 2.0
7 stars 1 forks source link

Cannot read properties of undefined (reading 'name') when tracing Lambdas #16

Closed nnyegaard closed 1 year ago

nnyegaard commented 1 year ago

When I use the function traceLambda() the lib throws an TypeError: Cannot read properties of undefined (reading 'name')

Error: Cannot read properties of undefined (reading 'name')

Trace: TypeError: Cannot read properties of undefined (reading 'name')
    at Lumigo.getLayerType (/home/nnyegaard/development/work/freetrailer/testing/my-sst-app/node_modules/.pnpm/@lumigo+cdk-constructs-v2@0.1.35_aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/@lumigo/cdk-constructs-v2/lib/lumigo.js:434:40)
    at Lumigo.traceLambda (/home/nnyegaard/development/work/freetrailer/testing/my-sst-app/node_modules/.pnpm/@lumigo+cdk-constructs-v2@0.1.35_aws-cdk-lib@2.84.0_constructs@10.1.156/node_modules/@lumigo/cdk-constructs-v2/lib/lumigo.js:361:32)
    at Object.stacks [as fn] (file:///home/nnyegaard/development/work/freetrailer/testing/my-sst-app/.sst.config.1687761589856.mjs:57:8)
    at Module.synth (file:///home/nnyegaard/development/work/freetrailer/testing/my-sst-app/node_modules/.pnpm/sst@2.16.3/node_modules/sst/stacks/synth.js:55:20)
    at async file:///home/nnyegaard/development/work/freetrailer/testing/my-sst-app/node_modules/.pnpm/sst@2.16.3/node_modules/sst/cli/commands/deploy.js:74:24
    at async Object.handler (file:///home/nnyegaard/development/work/freetrailer/testing/my-sst-app/node_modules/.pnpm/sst@2.16.3/node_modules/sst/cli/commands/deploy.js:65:22)
    at process.<anonymous> (file:///home/nnyegaard/development/work/freetrailer/testing/my-sst-app/node_modules/.pnpm/sst@2.16.3/node_modules/sst/cli/sst.js:58:17)
    at process.emit (node:events:525:35)
    at process.emit (node:domain:489:12)
    at process._fatalException (node:internal/process/execution:149:25)
    at processPromiseRejections (node:internal/process/promises:288:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)

Snippet:

new Lumigo({
    lumigoToken: SecretValue.unsafePlainText("xxx"),
}).traceLambda(app);

If I use traceEverything() it works.

mmanciop commented 1 year ago

Hi, sorry for missing this issue, I'll be looking into it :-)

mmanciop commented 1 year ago

Hi @nnyegaard, well, you are trying to use a method that takes in input the entire CDK app, and try to use it to trace a Function construct. For that, you need to invoke:

const function = new Function(...);
new Lumigo({
    lumigoToken: SecretValue.unsafePlainText("xxx"),
}).traceLambda(function);

This is something that the TypeScript hints should tell you, but I am guessing you are using plain JavaScript, right?

mmanciop commented 1 year ago

I went and added type validation to the public APIs. The message should be smart enough to point people with the same problem in the right direction, I hope.