aws-otel-lambda icon indicating copy to clipboard operation
aws-otel-lambda copied to clipboard

Cannot redefine property: handler

Open revmischa opened this issue 3 years ago • 2 comments

Describe the bug

      scope.addDefaultFunctionEnv({
        [EnvVars.openTelemetryEnabled]: "true",
        AWS_LAMBDA_EXEC_WRAPPER: "/opt/otel-handler",
      })
      const otelLayer = LayerVersion.fromLayerVersionArn(
        this,
        "OpenTelemetryLayer",
        `arn:aws:lambda:${scope.region}:901920570463:layer:aws-otel-nodejs-amd64-ver-1-5-0:2`
      )
      scope.addDefaultFunctionLayers([otelLayer])

handler:

export const handler = async (): Promise<string> => {
...
}
 ❌  mish-platform-DbMigrations failed: Received response status [FAILED] from custom resource. Message returned: Cannot redefine property: handler

Logs: /aws/lambda/mish-platform-DbMigration-MigrationScriptMigration-hWdyvtv7f92D

    at Function.defineProperty (<anonymous>)
    at defineProperty (/opt/nodejs/node_modules/shimmer/index.js:14:10)
    at AwsLambdaInstrumentation.wrap [as _wrap] (/opt/nodejs/node_modules/shimmer/index.js:56:3)
    at InstrumentationNodeModuleFile.patch (/opt/nodejs/node_modules/@opentelemetry/instrumentation-aws-lambda/src/instrumentation.ts:124:20)
    at AwsLambdaInstrumentation._onRequire (/opt/nodejs/node_modules/@opentelemetry/instrumentation-aws-lambda/node_modules/@opentelemetry/instrumentation/src/platform/node/instrumentation.ts:126:23)
    at null.<anonymous> (/opt/nodejs/node_modules/@opentelemetry/instrumentation-aws-lambda/node_modules/@opentelemetry/instrumentation/src/platform/node/instrumentation.ts:161:25)
    at Module.Hook._require.Module.require (/opt/nodejs/node_modules/require-in-the-middle/index.js:175:32)
    at Module.Hook._require.Module.require (/opt/nodejs/node_modules/require-in-the-middle/index.js:101:39)
    at Module.Hook._require.Module.require (/opt/nodejs/node_modules/require-in-the-middle/index.js:101:39)
    at Module.Hook._require.Module.require (/opt/nodejs/node_modules/require-in-the-middle/index.js:101:39) (RequestId: 582b69af-9ad1-4ffd-b0de-d8f9c32b24db)

Additional context Node 16, Serverless Stack

revmischa avatar Aug 26 '22 20:08 revmischa

Can you please add more detail in the issue? Such as what is expected and what did you see instead.

vasireddy99 avatar Sep 16 '22 07:09 vasireddy99

I was hoping to instrument my application. I want to use https://www.prisma.io/docs/concepts/components/prisma-client/opentelemetry-tracing to gather data about what queries my serverless application is performing and have the results appear in xray.

revmischa avatar Sep 19 '22 00:09 revmischa

This issue is stale because it has been open 90 days with no activity. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled

github-actions[bot] avatar Dec 18 '22 20:12 github-actions[bot]

Still an issue for me

revmischa avatar Dec 19 '22 16:12 revmischa

Tried it today, the issue is still there...

Dutzu avatar Jan 10 '23 16:01 Dutzu

I think the root cause might be this CJS vs. ESM issue noted here

  • https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1287

thiskevinwang avatar Jan 24 '23 13:01 thiskevinwang

Using CJS vs ESM style exports fixed this issue for me.

E.g

export const handler = function() {}

refactored to

const handler = function() {}
module.exports = { handler }

pyrae-alex avatar Mar 13 '23 03:03 pyrae-alex

This issue is stale because it has been open 90 days with no activity. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled

github-actions[bot] avatar Jun 11 '23 20:06 github-actions[bot]

This issue was closed because it has been marked as stale for 30 days with no activity.

github-actions[bot] avatar Jul 16 '23 20:07 github-actions[bot]