I am trying to integrate @sentry/tracing into a NodeJS + Express app.
Doesn't seem to be any documentation about that I can find (and I've submitted an issue to the documentation repo here).
I have poked around @sentry/tracing code and there seems to be an Express integration available.
Based on the integration source code, it looks like it should be instantiated liked this:
const express = require('express');
const app = express();
const Sentry = require('@sentry/node');
const { Integrations } = require( "@sentry/tracing");
Sentry.init({
dsn: __MY_SENTRY_DSN__,
integrations: [
new Integrations.Express({app}),
]
});
I've tried this and i'm not getting any trace data in Sentry.
Ok, so basically, the main tracing component we need here is a separate handler for express.
That tracing handler is actually part of the @sentry/node package (because logic) and is accessible as Sentry.Handlers.tracingHandler
So the correct initialisation steps are:
Sentry.init({
tracesSampleRate: 1.0, // <- ** you need this one here (Note: the docs for the BrowserTracing version says to use less for production environment or it might suck all your quota) **
dsn: __MY_SENTRY_DSN__,
// ...
});
app.use(Sentry.Handlers.requestHandler());
app.use(Sentry.Handlers.tracingHandler()); // <- ** and add this one here **
// your route handlers
app.use(Sentry.Handlers.errorHandler());
Once that's configured, you should start seeing tracing data in Performance tab.
This leaves one un-answered question though.. what is Integrations.Express?
Basically what it seems to be doing (and it's optional) is showing sub-frames (Spans in their terminology) for each middleware calls in the trace.
Here's a trace without:

Here's a trace with:

That's what I was able to figure out. If you think there is any mistake or if there is a better way, please correct me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With