Here's the middleware that I use in express:
const app = express();
const port = 8000;
const f = () => {
return async (req, res, next) => {
await new Promise(resolve => setTimeout(resolve, 3000));
return next();
}
}
const namedFunction = f();
app.use(namedFunction); // earlier I was using `app.use(f());`
But my function still appear as anonymous function in profiler: Something like this:
A bit of background: We want to see which middleware is causing the high latency, but because the middlewares are anonymous, we can't narrow down the cause in our APM + JS profiler. The preceding is just one example; we use approximately 40 middleware packages over which we have no control.
That's why I thought passing f()
to namedFunction
should fix the issue but it wasn't so looking for help on this.
Other tries till now: As per Jonsharpe's comment I tried:
app.use(function namedFunction() { f()(...arguments) });
But in profiler it still appear as an anonymous function