Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Isolated scopes for each http request #5576

Answered by AbhiPrasad
Loskir asked this question in Q&A
Discussion options

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?

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
0 replies
Answer selected by Loskir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /