Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundling with @sentry/profiling-node@8.49.0 no longer outputs .node files, 8.47.0 does #15026

Closed
2 of 3 tasks
rgripper opened this issue Jan 15, 2025 · 11 comments · Fixed by #15208
Closed
2 of 3 tasks
Labels
Package: node Issues related to the Sentry Node SDK

Comments

@rgripper
Copy link

rgripper commented Jan 15, 2025

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.39.0

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

@sentry/profiling-node@8.49.0
esbuild (or bun) no longer outputs *.node binaries with my instrument.js using

  loader: {
    // ensures .node binaries are copied to ./dist
    ".node": "copy",
  },

But @sentry/profiling-node@8.47.0 works fine

Expected Result

the output folder contains multiple *.node binaries and instrument.js

Actual Result

the output folder contains only instrument.js

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 15, 2025
@github-actions github-actions bot added the Package: node Issues related to the Sentry Node SDK label Jan 15, 2025
@s1gr1d
Copy link
Member

s1gr1d commented Jan 16, 2025

Hello, thanks for reaching out! This bug was most likely introduced in this PR: #14952
I was able to reproduce it and we're on it to fix this!

For now, you can downgrade to 8.48.0 or try to copy the node binaries from node_modules/@sentry/profiling-node/lib

@s1gr1d
Copy link
Member

s1gr1d commented Jan 17, 2025

For more context: esbuild does not support createRequire and there is an open issue for this: evanw/esbuild#1828

As node-based libraries were not instrumented with Sentry correctly when using them together with profiling, this PR was added to fix this: #14470 (released with 8.49.0).
This PR basically removes storing require etc. on globalThis as this was the root-cause of a set of problems. However, storing those variables on globalThis is also one of the proposed short-term solutions in esbuild to support ESM and CJS: evanw/esbuild#1921 (comment)

@timfish
Copy link
Collaborator

timfish commented Jan 22, 2025

To make native module loading compatible with more bundlers you can ensure you always do the loading in a CJS context with require:

load.cjs

function loadBindings() {
  // simplified 😂
  return require('./path/to/module.node');
}
exports.loadBindings;

Since ESM can load CJS, you can just do this in ESM:
integration.mjs

import { loadBindings } from './load.cjs';

CJS can just load the CJS:
integration.cjs

const { loadBindings } = require('./load.cjs');

@zachelrath
Copy link

@s1gr1d @timfish Will a fix for this be backported to 8.x ? Or maybe I'm not understanding how to apply the fix in my environment. I'm still seeing this issue on 8.52.1

We're using @sentry/nextjs in our Next.js project along with @sentry/profiling-node, and we are importing the Node profiling integration in sentry.server.config.ts like this:

import { init, postgresIntegration } from "@sentry/nextjs";
import { nodeProfilingIntegration } from "@sentry/profiling-node";

init({
	...
	integrations: [
		postgresIntegration(),
		nodeProfilingIntegration(),
	],
});

When I do a regular npm install, and run next dev, the expected .node binaries are all present in node_modules/@sentry/profiling-node/lib.

However, when I do a Next.js production build with next build, the lib folder doesn't contain any of the expected binaries, so the Node profiling integration fails to locate the expected binaries at runtime and crashes the app.

I've confirmed that this behavior started with 8.49.0 (binaries are present in lib on <= 8.48.0), and it is still happening on 8.51.2

Thank you!

@timfish
Copy link
Collaborator

timfish commented Jan 31, 2025

This is currently fixed only in v9. The changes are quite large so I'm not sure how easy this would be to backport to v8.

@zachelrath
Copy link

@timfish It was surprising to me that such a substantial change to the bundling process was backported onto v8 to begin with --- the commit that introduced this bug feels like a "breaking change" that probably should not have backported onto v8 --- could this commit to v8 branch be reverted (from v8 branch only)? 785aab3

@mydea
Copy link
Member

mydea commented Jan 31, 2025

We may backport this, when we verified the change actually fixes the problems.
I opened an issue to track this: #15247

We'll release another v9 alpha soon where we can hopefully verify this!

@timfish
Copy link
Collaborator

timfish commented Feb 3, 2025

9.0.0-alpha.1 has been released. Can anyone who's having bundling issues with v8 test to confirm this fixes your issues?

@evandyou
Copy link

@timfish I still run into bundling errors, as @sentry-internal/node-cpu-profiler/lib/index.js tries to resolve files that are not available.
For example, I get following error.

return require('./sentry_cpu_profiler-darwin-x64-93.node');
error: Could not resolve: "./sentry_cpu_profiler-darwin-x64-93.node"
at /node_modules/.pnpm/@sentry-internal+node-cpu-profiler@2.0.0/node_modules/@sentry-internal/node-cpu-profiler/lib/index.js:51:32

all -93.node profiles are failing

@timfish
Copy link
Collaborator

timfish commented Feb 12, 2025

Oh thanks for testing this. That issue has been fixed but it looks like we need a new release!

@timfish
Copy link
Collaborator

timfish commented Feb 12, 2025

v2.1.0 has been released so if you update your dependencies this should now be fixed:
https://github.com/getsentry/sentry-javascript-profiling-node-binaries/releases/tag/2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: node Issues related to the Sentry Node SDK
Projects
Archived in project
6 participants