sentry-docs
sentry-docs copied to clipboard
Clarify Global scope for Node SDK
Core or SDK?
Platform/SDK
Which part? Which one?
NodeJS SDK
Description
The current text here is: https://docs.sentry.io/platforms/node/enriching-events/context/#clearing-context
This will be changed for all future events:
Sentry.setUser(someUser); //SetContext as well
However, the scope in Node is per router and if the context or user is added inside a router, it will not be available to other routers. This is expected and can be reproduced with:
Sentry.init({....});
app.use(Sentry.Handlers.requestHandler());
Sentry.setContext("TrueGlobalContext",{foo:'This context will be present in all future events'});
// All controllers should live here
app.get("/", function rootHandler(req, res) {
Sentry.setContext("FakeGlobalContext",{foo:'This context will be present only in events from this request'});
res.end("End request")
});
// The error handler must be before any other error middleware and after all controllers
app.use(Sentry.Handlers.errorHandler());
Suggested Solution
The doc currently has a single text for all platforms/frameworks. The suggestion is to add notes or comments for frameworks where the behaviour is different.
Looks like a platformsection just needs to be set up for that section of the page to address this.
Routing to @getsentry/team-web-sdk-frontend for triage. ⏲️