Skip to content

Cannot redefine property: <lambda_name> #16973

Closed
@drqCode

Description

@drqCode

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/aws-serverless

SDK Version

9.38.0

Framework Version

@sentry/aws-serverless

Link to Sentry event

No response

Reproduction Example/SDK Setup

Followed docs here:
https://docs.sentry.io/platforms/javascript/guides/aws-lambda/install/cjs-npm/#alternative-initialize-the-sdk-in-code.

Lambda function:

// src/handlers/testSentry.js

const Instrumentation = require('../instrumentation');

module.exports.testSentry = Instrumentation.instrument(
    async (event) => {
        return {
            statusCode: 200,
            body: JSON.stringify(event.body)
        };
    },
);

Instrumentation module:

// src/instrumentation.js

const Sentry = require('@sentry/aws-serverless');

module.exports.instrument = Sentry.wrapHandler;

Bootstrap file:

// bootstrap/sentry.js

const Sentry = require('@sentry/aws-serverless');

Sentry.init({
  dsn: process.env.SENTRY_DSN_URL,
  tracesSampleRate: 1.0,
  environment: process.env.APP_ENVIRONMENT === 'prod' ? 'production' : process.env.APP_ENVIRONMENT
});

Steps to Reproduce

Deploying with serverless V3:

// serverless.yml

service: test-sentry

useDotenv: true

plugins:
  - serverless-offline

package:
  patterns:
    - bootstrap/sentry.js

provider:
  name: aws
  runtime: nodejs20.x
  apiName: ${env:STACK}
  stackName: ${env:STACK}
  timeout: 20
  environment:
    NODE_OPTIONS: "--require ./bootstrap/sentry.js"
    SENTRY_DSN_URL: ${env:SENTRY_DSN}
    APP_ENVIRONMENT: ${env:APP_ENVIRONMENT}
  role: ${env:IAM_ROLE}

functions:
  testSentry:
    name: ${env:STACK}-testSentry
    handler: src/handlers/testSentry.testSentry
    events:
      - http:
          path: /test_sentry
          method: post
          cors:
            origin: '*'
            headers: ${self:custom.allowed-headers}
            allowCredentials: false

Receiving error when invoking the requesting the lambda function:

{
  "errorType": "TypeError",
  "errorMessage": "Cannot redefine property: authorize",
  "stack": [
    "TypeError: Cannot redefine property: authorize",
    "    at Function.defineProperty (<anonymous>)",
    "    at defineProperty (/var/task/node_modules/shimmer/index.js:14:10)",
    "    at wrap (/var/task/node_modules/shimmer/index.js:56:3)",
    "    at InstrumentationBase._wrap (/var/task/node_modules/@opentelemetry/instrumentation/build/src/platform/node/instrumentation.js:44:43)",
    "    at InstrumentationNodeModuleFile.patch (/var/task/node_modules/@opentelemetry/instrumentation-aws-lambda/build/src/instrumentation.js:99:26)",
    "    at /var/task/node_modules/@opentelemetry/instrumentation/build/src/platform/node/instrumentation.js:186:29",
    "    at Array.reduce (<anonymous>)",
    "    at AwsLambdaInstrumentation._onRequire (/var/task/node_modules/@opentelemetry/instrumentation/build/src/platform/node/instrumentation.js:176:46)",
    "    at onRequire (/var/task/node_modules/@opentelemetry/instrumentation/build/src/platform/node/instrumentation.js:230:29)",
    "    at Module.patchedRequire (/var/task/node_modules/require-in-the-middle/index.js:349:28)"
  ]
}

Expected Result

Successfully run the lambda function.

Actual Result

{
  "errorType": "TypeError",
  "errorMessage": "Cannot redefine property: authorize",
  "stack": [
    "TypeError: Cannot redefine property: authorize",
    "    at Function.defineProperty (<anonymous>)",
    "    at defineProperty (/var/task/node_modules/shimmer/index.js:14:10)",
    "    at wrap (/var/task/node_modules/shimmer/index.js:56:3)",
    "    at InstrumentationBase._wrap (/var/task/node_modules/@opentelemetry/instrumentation/build/src/platform/node/instrumentation.js:44:43)",
    "    at InstrumentationNodeModuleFile.patch (/var/task/node_modules/@opentelemetry/instrumentation-aws-lambda/build/src/instrumentation.js:99:26)",
    "    at /var/task/node_modules/@opentelemetry/instrumentation/build/src/platform/node/instrumentation.js:186:29",
    "    at Array.reduce (<anonymous>)",
    "    at AwsLambdaInstrumentation._onRequire (/var/task/node_modules/@opentelemetry/instrumentation/build/src/platform/node/instrumentation.js:176:46)",
    "    at onRequire (/var/task/node_modules/@opentelemetry/instrumentation/build/src/platform/node/instrumentation.js:230:29)",
    "    at Module.patchedRequire (/var/task/node_modules/require-in-the-middle/index.js:349:28)"
  ]
}

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions