Sentry.init({
dsn: process.env.SENTRY_DSN,
tags: {
process_name: 'webserver',
},
})
Above is the code I have in my project. When errors are logged from the express middleware, the process_name tag is not included. This is obviously a bug.
Note: I've also tried:
Sentry.configureScope(scope => {
scope.setTag('process_name', 'webserver')
})
with no avail.
I can confirm that it's an issue when working with express. I'll take care of it this week.
@samholmes because of pipeline-like nature of Express (its middlewares), a user has to pass the scope
through all the pipes and carry it over with the request. Otherwise, there's no way to isolate them from each other.
Here's how to work with custom data in Express.js:
app.use(Sentry.Handlers.requestHandler());
// Set any data for all the requests
app.use((req, res, next) => {
Sentry.getHubFromCarrier(req).configureScope(scope => {
scope.setTag('process_name', 'webserver')
scope.setExtra('whatever', 'you-need');
});
next();
});
// set data per endpoint
app.get("/foo", req => {
Sentry.getHubFromCarrier(req).configureScope(scope => {
scope.setTag("foo", "my-value");
});
throw new Error("foo!");
});
app.use(Sentry.Handlers.errorHandler());
Also, one thing you have to remember is that if you want to use captureMessage/captureException
and preserve your data, you also need to call them on the requests hub, Sentry.getHubFromCarrier(req).captureMessage("foo")
;
We'll make sure to document it better. Also we'll release 4.1.0
this week, and then global
Sentry.configureScope(scope => {
scope.setTag('process_name', 'webserver')
})
Will work as well :)
@samholmes ignore my previous comments. We fixed everything internally and starting 4.1.0
(to be released today or tomorrow), everything will "just work" :)
Hey @kamilogorek just to clarify, we can now use middleware and set scope without first setting the hub?
I.e.
app.use((req, res, next) => {
Sentry.configureScope(scope => {
// ...
});
next();
});
will just work?
@saoudrizwan yes, as long as you attach app.use(Sentry.Handlers.requestHandler())
first, it'll work just fine :)
That's magical, great work!
Most helpful comment
That's magical, great work!