getsentry / profiling-node

The code for this repo now lives in https://github.com/getsentry/sentry-javascript/tree/develop/packages/profiling-node
MIT License
29 stars 10 forks source link

When using Node 21 and Docker I get the following error Error: Cannot find module '/node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-linux-arm64-musl-120.node' #239

Closed oxatruchdev closed 7 months ago

oxatruchdev commented 10 months ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

SDK Version

1.3.5

Link to Sentry event

No response

What environment is your node script running in?

Express app inside docker container using node:alpine image.

How is your code deployed and bundled?

It's plain javascript express server, and I'm running it inside a docker container as follows

FROM node:21-alpine

#TODO add proper user configurations in this dockerfile
COPY package*.json ./

# Use the default working directory for Node.js
WORKDIR /usr/src/app

RUN npm install

COPY . .

EXPOSE 8080

CMD [ "node", "index.js" ]

My integration for Sentry and the ProfilingIntegration looks like this

// rest of the conde
import * as Sentry from '@sentry/node';
import { ProfilingIntegration } from '@sentry/profiling-node';
import packageJson from './package.json' assert { type: 'json' };

const PORT = process.env.PORT || 8080;
const HOST = process.env.HOST || '0.0.0.0';

//TODO Go through express configuration and check the best configurations  on OWASP
const app = express();

//Sentry integration
Sentry.init({
  dsn: process.env.SENTRY_DSN,
  integrations: [
    // enable HTTP calls tracing
    new Sentry.Integrations.Http({ tracing: true }),
    // enable Express.js middleware tracing
    new Sentry.Integrations.Express({ app }),
    new ProfilingIntegration(),
  ],
  // Performance Monitoring
  tracesSampleRate: 1.0, //  Capture 100% of the transactions
  // Set sampling rate for profiling - this is relative to tracesSampleRate
  profilesSampleRate: 1.0,
  environment: process.env.ENVIRONMENT,
  release: packageJson.version,
  debug: true
});
//rest of the code

package.json looks like this

  "dependencies": {
    "@aws-sdk/client-s3": "^3.288.0",
    "@sentry/node": "^7.99.0",
    "@sentry/profiling-node": "^1.3.5",
    "axios": "^0.27.2",
    "cors": "^2.8.5",
    "dotenv": "^16.0.2",
    "express": "^4.18.1",
    "npmlog": "^6.0.2"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^6.19.1",
    "@typescript-eslint/parser": "^6.19.1",
    "eslint": "^8.56.0",
    "nodemon": "^2.0.19",
    "prettier": "3.0.3"
  }

Steps to Reproduce

  1. Installed @sentry/node and @sentry/profiling-node
  2. Configured following documentation
  3. Setup docker file
  4. Build docker container running docker build --no-cache -t efs .
  5. Run docker container using node:alpine image with the following command docker run -p 8080:8080 efs

Expected Result

Docker container runs on latest image

Actual Result

❯ docker run -p 8080:8080 efs
(node:1) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
info S3Client Initializing with us-east-2
node:internal/modules/cjs/loader:1149
  const err = new Error(message);
              ^

Error: Cannot find module '/node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-linux-arm64-musl-120.node'
Require stack:
- /node_modules/@sentry/profiling-node/lib/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1149:15)
    at Module._load (node:internal/modules/cjs/loader:990:27)
    at Module.require (node:internal/modules/cjs/loader:1237:19)
    at require (node:internal/modules/helpers:176:18)
    at importCppBindingsModule (/node_modules/@sentry/profiling-node/lib/index.js:19266:10)
    at Object.<anonymous> (/node_modules/@sentry/profiling-node/lib/index.js:19268:34)
    at Module._compile (node:internal/modules/cjs/loader:1378:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
    at Module.load (node:internal/modules/cjs/loader:1212:32)
    at Module._load (node:internal/modules/cjs/loader:1028:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/node_modules/@sentry/profiling-node/lib/index.js' ]
}

Node.js v21.6.1
Screenshot 2024-01-30 at 3 18 18 PM

And it's correct, because, in fact there's no sentry_cpu_profiler-linux-arm64-musl-120.node file in my node_modules.

Also I checked the code for this library and even though I don't understand completely what's happening inside, but there's no check for that 120 anywhere to be found in src/cpu_profiler

This also happened in my M1 Macbook pro when running node 21

(node:2350) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
info S3Client Initializing with us-east-2
node:internal/modules/cjs/loader:1149
  const err = new Error(message);
              ^

Error: Cannot find module '/Users/x/Documents/x/efs/node_modules/@sentry/profiling-node/lib/sentry_cpu_profiler-darwin-arm64-120.node'
Require stack:
- /Users/x/Documents/x/efs/node_modules/@sentry/profiling-node/lib/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1149:15)
    at Module._load (node:internal/modules/cjs/loader:990:27)
    at Module.require (node:internal/modules/cjs/loader:1237:19)
    at require (node:internal/modules/helpers:176:18)
    at importCppBindingsModule (/Users/osauceda/Documents/x/efs/node_modules/@sentry/profiling-node/lib/index.js:19266:10)
    at Object.<anonymous> (/Users/osauceda/Documents/x/efs/node_modules/@sentry/profiling-node/lib/index.js:19268:34)
    at Module._compile (node:internal/modules/cjs/loader:1378:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
    at Module.load (node:internal/modules/cjs/loader:1212:32)
    at Module._load (node:internal/modules/cjs/loader:1028:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/x/Documents/x/efs/node_modules/@sentry/profiling-node/lib/index.js'
  ]
}

Node.js v21.6.1
oxatruchdev commented 10 months ago

It's worth mentioning that this only happens when I run node 21, but whenever I change to node 18, the profiler works as expected

magnusburton commented 9 months ago

We're having the same issue and downgrading to node 18 works as you said. We do however prefer to use node 21 which is a problem.

rokas0 commented 9 months ago

This is expected.

We currently ship prebuilt binaries for a few of the most common platforms and node versions (v16-20). https://github.com/getsentry/profiling-node/tree/v1.3.5?tab=readme-ov-file#prebuilt-binaries

lukeocodes commented 7 months ago

@rokas0 it's been almost 6 months since Node 21 came out. Any info on when the Node 21 profiler will be released?

JonasBa commented 7 months ago

@lukeocodes we do not support non LTS (odd) versions of nodejs. We will release a new version when node 22 reaches LTS