Sentry is awesome, but their NodeJS Platform is slightly less great. It's basically entirely synchronous, so if you have a lot of async operations going on things like breadcrumbs and other context information will all get mixed up together.
I put this gist together to share with other people how I worked around this problem in our code base. It's not a perfect solution, but it works pretty well.
The way this works is that Sentry has a global store (global.__SENTRY__
) that includes a hub
property that stores the current hub. The hub has a stack of scopes that are the things you interact with when using things like Sentry.withScope
and Sentry.configureScope
. What I'm doing here is replacing that hub
property with a getter that return an async context local hub
instead of a global one. It does this by using the Node native AsyncLocalStorage mo