Is there a way use multiple different scopes at the same time? I’ve been looking through the docs and GitHub issues today, but haven’t found anything that fits my use case.
The short description of what I want to do is as follows:
We have an app that fires off an arbitrary number of network requests concurrently. For each request, we’d like to create and set a transaction id, both on the request, and in the scope (as per the docs on error tracing). I’d like to have the transaction ID as part of the scope so that it’s automatically logged for everything related to a given request.
What I’ve tried
From what I understand, because the default scope is on a global object, using
configureScope will cause all kinds of race conditions here. My first thought was to perform each request with
withScope, but that doesn’t work, because I need the return value from the function, and from what I understand,
withScope doesn’t support async callbacks.
Based on this GitHub issue at
hub.run, which is another function that returns
void, so that also doesn’t work in this case.
What’s the ‘right’ way of doing this? I’m very happy to accept that I’m going about this in the wrong manner here, because it doesn’t seem like a particularly uncommon use case to me. The easiest way would probably be to not use scope at all, but passing around an object that has the corresponding data on it. If that’s the case, then all I need to do is set the tag on all events, which, while tedious, should be pretty doable.
Anyway, appreciate any and all input on this. I’m still really new to Sentry (only started playing around with it yesterday), so I’m probably missing something obvious.