-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Isolated scopes for each http request #5576
-
I'm using Sentry with koa framework.
What do I do to make each request have its own isolated scope? So I can set some request-specific tags that shouldn't be visible in other requests.
I can't use pushScope because there can be a race condition that results in data from one request being leaked to other requests.
I tried creating separate Hubs for each request, but that's not an elegant solution, and besides, the console breadcrumbs broke.
I tried creating a cloned Scope for each request using Scope.clone(Sentry.getCurrentHub().getScope()) and then passing it in captureException like Sentry.captureException(error, scope). It works fine, but I discovered that Event Processors are not executed for some reason and metadata from the koa request is not added.
On this page I saw an example that used the domain module of node. I haven't tried it, but I suppose that it does something similar to what I'm trying to achieve. The problem is that this module is deprecated and I don't quite fancy these magic "domains". I'd rather have a plain variable with current scope and pass it back and forth.
Any other solutions? Best practices?
Beta Was this translation helpful? Give feedback.
All reactions
Hey! We recommend using domains. Although it's deprecated, it works quite well and is the foundation of our various server side integrations - it should work ootb with the SDK as well. See our usage in express:
Eventually we'll make the switch to async hooks: https://nodejs.org/api/async_hooks.html - but since we have to support Node 8, we're stuck with domains for now.
Replies: 1 comment
-
Hey! We recommend using domains. Although it's deprecated, it works quite well and is the foundation of our various server side integrations - it should work ootb with the SDK as well. See our usage in express:
Eventually we'll make the switch to async hooks: https://nodejs.org/api/async_hooks.html - but since we have to support Node 8, we're stuck with domains for now.
Beta Was this translation helpful? Give feedback.