Add Sentry to backend

I’ve added Sentry to the frontend quite easily but for the backend I have an issue trying to catch something.

I’m using the express “version” of Sentry. Do I need to configure something else in another file than lib/server.js?

...
    const cors = require('cors');
    const Sentry = require('@sentry/node');
    const Tracing = require("@sentry/tracing");
    const app = express();

    Sentry.init({
        dsn: "...",
        integrations: [
            // enable HTTP calls tracing
            new Sentry.Integrations.Http({ tracing: true }),
            // enable Express.js middleware tracing
            new Tracing.Integrations.Express({ app }),
        ],
        environment: process.env.MODE,
    });

    // RequestHandler creates a separate execution context using domains, so that every
    // transaction/span/breadcrumb is attached to its own Hub instance
    app.use(Sentry.Handlers.requestHandler());
    // TracingHandler creates a trace for every incoming request
    app.use(Sentry.Handlers.tracingHandler());

    app.use(
        Sentry.Handlers.errorHandler({
            shouldHandleError(error) {
                console.error('shouldHandleError', error);
                if (error.status === 404 || error.status === 500) {
                    return true;
                }
                return false;
            },
        })
    );

    app.set('trust proxy', true);
...
Community Page
Last updated: