In my express
app I initialise Sentry
as follows.
const Sentry = require('@sentry/node');
const Tracing = require('@sentry/tracing');
const app = express();
const server = require('http').createServer(app);
Sentry.init({
dsn:
'...',
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.8,
});
app.use(Sentry.Handlers.requestHandler());
// TracingHandler creates a trace for every incoming request
app.use(Sentry.Handlers.tracingHandler());
server.listen(PORT);
Next, I export Sentry
as follows from this file:
module.exports = {
app,
Sentry,
};
In other files, I would like to use the captureException
method to manually report errors to Sentry
. In these files I have:
const { Sentry } = require('./path/to/above/file');
Sentry.captureException(ex);
This throws the error to Sentry: cannot read property captureException of undefined
which to me sounds like there's an issue with my export / import logic leading to Sentry being undefined, but I don't understand what the issue could be.
console.log(require('./path/to/above/file'))
?captureException
or can I just doconst Sentry = require('@sentry/node');
in those places instead?import * as Sentry from '@sentry/node';