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());
But that is giving me errors: “cannot use import statement outside a module node”
I looked into the error and I’m trying to use ES6 (import) while I can only use commonJS.
So then I simply tried to load the script that I need, by using: <script src="/node_modules/@sentry/browser/build/bundle.min.js"></script>
But this won’t load as /node_modules/ is not accessible if I understand correctly - the root folder is /public.
@George This file might get overwritten on Wappler update, correct?
I don’t use sentry or any such tool yet, but out of curiosity, is Wappler planning to add such an extensibility support?
We moved the sentry code into an external file to prevent Wappler to overwrite our custom code in server.js during an update of Wappler.
extensions/server_connect/routes/sentry.js:
// JavaScript Document
const Sentry = require('@sentry/node');
const Tracing = require("@sentry/tracing");
exports.handler = function (app) {
Sentry.init({
dsn: "CHANGE_ME",
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());
}
If it doesn’t work then we need to revert and hook directly into server.js. Maybe the Wappler team will do the Sentry integration and it will fix this.
By loading a server connect that tries a DB update query that doesn’t work. It’s trying to update a record that doesn’t exist.
I’m quite sure it has to do by the fact that the code in /extensions is loaded too early for that error. Probably the same reason why the wappler devs load the error codes at the bottom of server.js
I think the way @Eldynn has it with the external file is the best way. The custom routes are loaded before the api routes, it is important that Sentry comes before other routes. Also the external file will never be updated by an Wappler update, so it is more future proof.
I see, checked the documentation and the error handler should indeed be applied after all the routes, but before our error handler. Will see if we can maybe provide more hooks for you, so that you not need to edit our code.