Sentry-javascript: Make client injectable in requestHandler and errorHandler to make it possible to use multiple clients

Created on 12 Nov 2018  路  6Comments  路  Source: getsentry/sentry-javascript

I'm currently upgrading from the "raven" module to the "@sentry/node" module in several express based Node applications. Since we report errors to multiple Sentry projects in a single application (some modules used in an application have their own projects), we instantiated clients and used the request and error middleware exposed by the client.

Is there a way to use client/hub bound middleware with the "@sentry/node" module? They seem to only be exposed by the Sentry object.

Improvement

All 6 comments

Yes, you still can create multiple clients - https://docs.sentry.io/platforms/javascript/advance-settings/

However, linking them to specific routes is more complex. We use domains internally and read current hub based on the current execution context - https://docs.sentry.io/platforms/node/express/

You'd need to utilize our parseRequest handler which is available on Sentry.Handlers.parseRequest and make use of https://github.com/getsentry/sentry-javascript/blob/master/packages/node/src/handlers.ts#L227-L237 and https://github.com/getsentry/sentry-javascript/blob/master/packages/node/src/handlers.ts#L269-L276 code to get it stitched together.

Thanks for the response. Are there any plans to provide the express handlers at the client/hub level?

It'd require a lot of rewrite, but I'll leave this issue opened just in case we find some time to do this one day.

@shils just curious, what did you end up doing to solve this? We are late to upgrade our clients but running into the same issue.

@QuotableWater7 We didn't go through with the upgrade server-side. I had something that seemed to work, but couldn't explain why; I still have the branch so I'll post a snippet here when I get the chance.

We're still stuck on Raven 2.0.2 as a result of this :\

Was this page helpful?
0 / 5 - 0 ratings