Repository navigation
Two Express monitoring gotchas: load order and where the error handler goes #7570
virajrakholiya
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Two mistakes that silently break error and request monitoring in Express apps.
1. Instrumentation loaded too late. Most Node tracing (OpenTelemetry and tools built on it) works by patching modules when they are first required. If
express,pgorhttpis required before the tracing setup runs, those calls are never recorded, with no error. Load it first:or start with
node --require ./tracing.js server.js.2. Error handler in the wrong place. Express error middleware (four arguments) only sees errors from routes registered before it. Put the error handler that records errors after all your routes:
Also worth doing: record the route pattern (
req.baseUrl + req.route.path, e.g./orders/:id) rather than the raw URL, so requests group properly.Question: any other ordering traps you have hit with Express 5?
(Disclosure: I'm building Relia, a monitoring tool (https://tryrelia.com/?utm_source=express-show-and-tell&utm_medium=community&utm_campaign=places); its Express setup has exactly these two steps.)
All reactions