How to install Sentry on the Back-end (NodeJS)

Here’s quick guide on how to install Sentry on the back end.

Note: this can get overwritten by a wappler update.

  1. Make sentry account

  2. Create a project and select that you want to install for Express

  3. Do the following npm install:
    npm install --save @sentry/node @sentry/tracing

  4. Open server.js in /lib

  5. Under const cors = require('cors'); add code:

    const Sentry = require('@sentry/node');
    const Tracing = require("@sentry/tracing");
  1. Under const app=express(); add code (don’t forget to enter your DSN:
    Sentry.init({

    dsn: "YOUR_DSN_LINK_HERE",

    integrations: [

    // enable HTTP calls tracing

    new Sentry.Integrations.Http({ tracing: true }),

    // enable Express.js middleware tracing

    new Tracing.Integrations.Express({ app }),

    ],

    // Set tracesSampleRate to 1.0 to capture 100%

    // of transactions for performance monitoring.

    // We recommend adjusting this value in production

    tracesSampleRate: 0.1,

    });

    // 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());

At this point it should look like:

  1. Add app.use(Sentry.Handlers.errorHandler()); in the module.exports like so: |0x43

  2. Trigger an error (for example a database query that doesn’t work and check in your sentry.io dashboard under Issues if you can see the error.

Sentry back-end is now installed.

(Thanks @Eldynn - it’s based on your thread!)

Community Page
Last updated: