-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Express middleware state leaking across requests #1773
Comments
Node domains which we use should do that on their own. Is there a chance you could provide a repro-case and node version details I could use to debug this? |
I was able to reproduce this error using this code. I may be missing something here, but I'm not sure how initializing a single global sentry hub (like the documentation does) would keep information separate when requests are being handled concurrently. 🤔 Is intended that the user initializes a hub on a per request basis? |
This is a huge problem with breadcrumbs. If you capture an event it will have all of the breadcrumbs from all of the requests that the machine has received. |
@asafigan @kamilogorek not only for breadcrumbs. plus, captureMessage and captureException signatures shows that it assumes that there is one context, this is a major issue, and Node domains is not the answer, we should be able to use Sentry sdk without domains, in my app i have a custom errorHandler cause I want to be able to keep trace of what happens (error or not) from req start, during, and sometimes after end of request, all of this being obviously asynchronous, and many requests are handled simultaneously, so i just want to send whatever i want to sentry, whenever i want. only solution I can think of is using captureEvent by itself |
That is what I feared. I think it's a problem because it looks like all the sentry libraries have the same interface but JavaScript is not like most languages. I don't think a scope system can really works in a concurrent environment like JavaScript. |
yes exactly, and when you read the doc it become even clearer, its write as if javascript was a thread by request language : |
@CharlieEarnup you have to add
There is no way to separate context between requests without the domains.
You can, you just won't have a separation of context data.
You can do that. Track your own scopes and pass them to https://docs.sentry.io/platforms/javascript/advance-settings/ import { BrowserClient } from "@sentry/browser";
const client = new BrowserClient({ dsn });
client.captureException(exception, {}, yourOwnScope);
It can with some restrictions and pre-requisites. |
@kamilogorek It is the first error middleware in my example code. It is the only error middleware in my example code. |
@CharlieEarnup it's definitely not here – #1773 (comment) |
@kamilogorek there must be some miscommunication here, do you mean it needs to go above the routes as well? |
There is no way to separate context between requests without the domains.
You can, you just won't have a separation of context data.
so i just want to send whatever i want to sentry, whenever i want.
thx for the hints, I'll use BaseClient and not BrowserClient I guess Still, I think that the usage of domains is way overkill |
@kamilogorek Oh I see the |
@adrienboulle you don't know the half of it that Api is getting deprecated for a reason. |
@CharlieEarnup it states very clearly in the docs. // The request handler must be the first middleware on the app
app.use(Sentry.Handlers.requestHandler());
...
// The error handler must be before any other error middleware
app.use(Sentry.Handlers.errorHandler());
It's soft deprecated for 5 years now with no real alternative (other than async hooks which are not there yet).
It won't catch async errors without domains. Thats the reason why we use implicit binding and call everything in |
@kamilogorek it's actually very unclear because nowhere does it communicate that you need requestHandler to support errorHandler. I personally know that I saw domains in the requestHandler code and omitted it on purpose.
It won't catch unhandled async errors without domains. Typically speaking though most people tend to implement their controllers with a wrapper that handles their errors. If you absolutely cannot take any chances with uncaught errors, sure domains work, but for most they are way overkill. |
@CharlieEarnup exactly, and Sentry is supposed to be a tool, not a framework, i handle my code errors by myself I wont rely on a third party for that |
I don't get what's the issue here tbh. If you don't want to use
https://docs.sentry.io/platforms/node/express/ I'm pretty sure "must" means "you need to use" :)
In our experience, most people want a "plug and play" solution. Using |
I get that most people want a plug and play solution, the "issue" is that this client is black or white, either plug and play or git clone the project and try to find how to do |
@adrienboulle So your point basically is we are lacking documentation on how to use the internals of the SDK if you want to manage everything yourself? |
I have a situation where I need to capture an exception with sentry that I do not need express to handle after, so I am using An example of what I need to do: app.use(Sentry.Handlers.requestHandler());
app.use('/some-work', async (req, res, next) => {
try {
await someAsyncWork.catch(error => {
Sentry.captureException(error); // capture, but ignore error
});
res.send('All good.');
} catch (error) {
next(error);
}
});
app.use(Sentry.Handlers.errorHandler()); Is this intended to work as I except it to? Edit: await someAsyncWork.catch(error => {
Sentry.withScope(scope => {
scope.addEventProcessor(async event => Sentry.Handlers.parseRequest(event, req));
Sentry.captureException(error);
});
}); |
@HazAT now that things has been explained and that I have explored the code by myself yes basically, even so I think the use of domain is not a very good idea but for my use case I do not really care. I think it would be very very helpful to explain in the doc how to use the low level API (how to send sentry events with |
Is this issue still relevant? |
@Grmiade i'd recommend to use |
Closing due to the issue getting out-dated. Feel free to ping me to reopen it if it's still relevant and/or create a more concrete ticket for a specific issue. |
@kamilogorek no one ever answered my question. |
@rhyek sorry I missed that. You're totally correct. Your second example is 100% accurate. |
Package + Version
@sentry/browser
@sentry/node
raven-js
raven-node
(raven for node)Version:
Description
When calling
Sentry.captureException
from an express middleware, theurl
field reported to Sentry is incorrect. It is almost always being reported as /health or /metrics (these are hit very frequently), even though the error happened on a totally different URL. I haveSentry.Handlers.requestHandler()
as the first middleware andSentry.Handlers.errorHandler()
as the error middlewareIs there a way to isolate the Sentry client for each request? Please let me know if you need more information
The text was updated successfully, but these errors were encountered: