You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
@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 requestsapp.use((req,res,next)=>{Sentry.getHubFromCarrier(req).configureScope(scope=>{scope.setTag('process_name','webserver')scope.setExtra('whatever','you-need');});next();});// set data per endpointapp.get("/foo",req=>{Sentry.getHubFromCarrier(req).configureScope(scope=>{scope.setTag("foo","my-value");});thrownewError("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
@samholmes ignore my previous comments. We fixed everything internally and starting 4.1.0 (to be released today or tomorrow), everything will "just work" :)
Activity
kamilogorek commentedon Oct 9, 2018
I can confirm that it's an issue when working with express. I'll take care of it this week.
kamilogorek commentedon Oct 9, 2018
@samholmes because of pipeline-like nature of Express (its middlewares), a user has to pass the
scopethrough 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:
Also, one thing you have to remember is that if you want to use
captureMessage/captureExceptionand 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.0this week, and then globalWill work as well :)
kamilogorek commentedon Oct 9, 2018
getsentry/sentry-docs#447
kamilogorek commentedon Oct 9, 2018
and #1637
kamilogorek commentedon Oct 10, 2018
@samholmes ignore my previous comments. We fixed everything internally and starting
4.1.0(to be released today or tomorrow), everything will "just work" :)saoudrizwan commentedon Jun 18, 2019
Hey @kamilogorek just to clarify, we can now use middleware and set scope without first setting the hub?
I.e.
will just work?
kamilogorek commentedon Jun 18, 2019
@saoudrizwan yes, as long as you attach
app.use(Sentry.Handlers.requestHandler())first, it'll work just fine :)saoudrizwan commentedon Jun 18, 2019
That's magical, great work!