How to send a scope (user id) to sentry (nodejs)?

It's about this:

Then your code should be:

const Sentry = require('@sentry/node');

exports.before = function (app) {
    Sentry.init({
        dsn: "mydns",
        beforeSend(event) {
            console.log(event);
            return event;
        }
    });
    app.use((req, res, next) => {
        const user_id = req.session.secId ?? '';
        Sentry.configureScope(scope => {
            scope.setUser({ id: user_id });
        });
        next();
    });
    app.use(Sentry.Handlers.requestHandler());
};

exports.after = function (app) {
    app.use(Sentry.Handlers.errorHandler());
};

PS: Sorry @mgaussie should explained better, on the code you can see the line 12, there is a req.session.
There is where you need to write the security provider name + Id

1 Like