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

PM2 does not work with Raven #3063

Closed
niftylettuce opened this issue Aug 3, 2017 · 8 comments
Closed

PM2 does not work with Raven #3063

niftylettuce opened this issue Aug 3, 2017 · 8 comments
Labels

Comments

@niftylettuce
Copy link
Contributor

niftylettuce commented Aug 3, 2017

Not sure how to resolve this - I think it is the usage of domain in the context of Raven.

See getsentry/raven-node#355.

Basically raven (a package that supports logging for Sentry.io) provides a middleware for Express apps (as documented here). There is a middleware for handling requests and errors (so metadata like logged in user ID's, browser user-agent, IP address of user, and email address of user get sent along with logs).

The script below works properly (it sends along the user's ID to Sentry for logging). However as soon as I run the script with pm2, e.g. pm2 start app.js -i 0 (with clustering enabled), the script stops working. I think this is due to domain and clustering somehow, but I've not gone too deep here just yet. I was hoping someone here could take a look at the raven-node lib/client.js file available at https://github.com/getsentry/raven-node/blob/master/lib/client.js#L449-L459 and help debug this issue:.

var app = require('express')();
var Raven = require('raven');

// TODO: REPLACE WITH A DSN TOKEN FROM <https://sentry.io>
var DSN = '******';

// Must configure Raven before doing anything else with it
Raven.config(DSN).install();

// The request handler must be the first middleware on the app
app.use(Raven.requestHandler());

// fake a user logged in
app.use(function(req, res, next) {
  req.user = { id: '123456' };
  next();
});

app.get('/', function mainHandler(req, res) {
    throw new Error('Broke!');
});

// The error handler must be before any other error middleware
app.use(Raven.errorHandler());

// Optional fallthrough error handler
app.use(function onError(err, req, res, next) {
    // The error id is attached to `res.sentry` to be returned
    // and optionally displayed to the user for support.
    res.statusCode = 500;
    res.end(res.sentry + '\n');
});

app.listen(3000);
@niftylettuce
Copy link
Contributor Author

Also note that "working" (as mentioned above) means that Sentry receives the user's ID parameter. If you run node app.js and then go to http://localhost:3000 - it works. However pm2 start app.js -i 0 does not send this user ID to Sentry.

@niftylettuce
Copy link
Contributor Author

Furthermore, DSN is a token available through a free account at https://sentry.io.

@vmarchaud
Copy link
Contributor

Does it works with pm2 start app.js (fork mode) ?

@niftylettuce
Copy link
Contributor Author

Yes it does work @vmarchaud

@vmarchaud
Copy link
Contributor

vmarchaud commented Aug 3, 2017

Maybe try with the vanilla nodejs implementation ?

EDIT : Since we are just using the nodejs cluster, i want to know if the problem is inside our code or just with nodejs directly

@mbrochh
Copy link

mbrochh commented Apr 23, 2020

I have the same problem. However, even fork-mode does not work for me.

I have tried pretty much everything (see https://forum.sentry.io/t/sourcemaps-for-node-app-behind-pm2-not-working/9536 and https://twitter.com/mbrochh/status/1252778718478491649?s=20)

Really no idea what else to try, and I can't figure out if this is a PM2 issue or a Sentry issue.

@stale
Copy link

stale bot commented May 23, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 23, 2020
@niftylettuce
Copy link
Contributor Author

Hey everyone, you should NOT be using Raven. You should be using https://cabinjs.com instead. Sentry and Raven have some very core security related issues, and I built Cabin out of frustration with it and services like Timber, Airbrake, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants