getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
8.02k stars 1.59k forks source link

PrivateCpuProfilerBindings.startProfiling is not a function #14561

Open jbreckel opened 16 hours ago

jbreckel commented 16 hours ago

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/node

SDK Version

8.41.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

AWS Lambda Node 20

Sentry.init({
    dsn: SENTRY_DSN,
    environment: stage,
    integrations: [nodeProfilingIntegration()],
    release: 'not-defined',
    tracesSampleRate: 0.5,
    profilesSampleRate: 1.0,
    shutdownTimeout: 0.1,
});

Steps to Reproduce

  1. execute lambda
  2. wait for execution
  3. get error or expected result

Expected Result

get a reproducible result. ~ 4 out of 10 times the below described error gets thrown

Actual Result

sometimes a TypeError is thrown, most times not

{
    "errorType": "TypeError",
    "errorMessage": "PrivateCpuProfilerBindings.startProfiling is not a function",
    "stack": [
        "TypeError: PrivateCpuProfilerBindings.startProfiling is not a function",
        "    at Bindings.startProfiling (/var/task/index.js:67619:43)",
        "    at maybeProfileSpan (/var/task/index.js:67944:27)",
        "    at /var/task/index.js:67988:28",
        "    at /var/task/index.js:5588:43",
        "    at Array.forEach (<anonymous>)",
        "    at NodeClient.emit (/var/task/index.js:5588:21)",
        "    at /var/task/index.js:37635:41",
        "    at /var/task/index.js:37661:82",
        "    at _optionalChain$1 (/var/task/index.js:37635:19)",
        "    at onSpanStart (/var/task/index.js:37661:7)"
    ]
}
Lms24 commented 13 hours ago

Hey @jbreckel thanks for writing in! Are you running your lambda function in ESM or CJS? Can you confirm that all your @sentry/* packages are aligned to exactly the same version?

jbreckel commented 11 hours ago

lambdas are running CJS, NodejsFunction definition:

new lambdaNodeJs.NodejsFunction(
    this,
    `SomeLambda`,
    {
        functionName: `${this.prefix}-some-lambda`,
        entry: `src/aws/lambda/some-lambda.ts`,
        runtime: lambda.Runtime.NODEJS_20_X,
        logRetention: logs.RetentionDays.ONE_WEEK,
        architecture: lambda.Architecture.ARM_64,
        bundling: {
            loader: {
                '.node': 'file',
            },
            commandHooks: {
                beforeBundling: () => [],
                beforeInstall: () => [],
                afterBundling: (_, outputDir) => [
                    `sentry-prune-profiler-binaries --target_platform=linux --target_arch=arm64 --target_node=20 --target_stdlib=glibc --target_dir_path=${outputDir}`,
                ],
            },
        },
        environment: {
            SENTRY_ENV: this.awsStage,
            SENTRY_RELEASE: `${this.prefix}-${this.awsStage}`,
            SENTRY_DSN: Context.tryGetContext<string>(
                this.node,
                'sentryDSN'
            ),
        },
    }
);

Yes, they are all pinned @8.41.0 in package-lock.json.