โ† All posts
RELEASE September 29, 2026 ยท 3 min read

Express, on plain Node, with the stack trace

SR
Sentrinel Team
Product & engineering

Express is still where a lot of production Node lives: the API that has been paying the bills for six years, the service nobody wants to port. Sentrinel's plugin now supports it properly. That sentence needs some honesty behind it, because for a while it did not.

It installs into plain Node now

The plugin used to ship TypeScript sources and nothing else. Bun runs those directly, and so did the Elysia apps we built it for โ€” which is how it went unnoticed that plain Node cannot import TypeScript from node_modules. An Express app that followed the install instructions failed at the import.

The public repo now carries built JavaScript โ€” ESM, CommonJS and type declarations โ€” next to the sources. import works, require() works, no build step runs on install, and Elysia is an optional peer an Express app never has to install.

npm install "github:Zaga-ltd/sentinel_packages"

Two lines, in two places

import { sentrinelExpressMiddleware, sentrinelErrorHandler } from "@sentrinel/plugin/express";

app.use(sentrinelExpressMiddleware({
  serverUrl: process.env.SENTRINEL_URL!,
  appName: "legacy-api",
  env: "prod",
  apiKey: process.env.SENTRINEL_API_KEY,
  consumerIdentifier: "x-consumer-id",   // a header name, or a function
}));

app.use("/api", routes);

app.use(sentrinelErrorHandler());         // after your routes, before your own error handlers

The middleware goes before your routes, so it sees every request. The error handler goes after them, and it exists for a reason that is easy to miss.

Where Express keeps its errors

Express hands a thrown error only to error middleware โ€” a function with four arguments โ€” and only to the ones after the route that threw. A middleware at the top of the stack never sees the Error object at all; it sees a 500 response go past.

The old integration tried to intercept next(err) from the top, which does not work: Express passes errors through its router's own closure, not the function the middleware wrapped. The result was errors recorded with a message scraped from an HTML error page and no stack. sentrinelErrorHandler() is a real four-argument error middleware: it records the error with its stack and calls next(err). It never responds, so your own error handling still decides what the client sees. Leave it out and errors are still recorded, from their status โ€” just without a stack.

The route, not the URL

/api/orders/1042 and /api/orders/1043 should be one endpoint. Express knows they are both /api/orders/:id, but only after routing has happened โ€” reading req.route at the top of the stack gets nothing, which is what the old integration did, so every id became its own endpoint. The route is now read when the response finishes, mount path included.

Secrets stay in your process

Request logging can capture headers and bodies, and the dangerous ones are masked before they leave your process with no configuration: Authorization, Cookie, X-API-Key and friends; token, code, signature query values; password, secret, card numbers in JSON, form-encoded and multipart bodies. Your own patterns add to that list. An earlier version masked only when you had configured patterns yourself and stored headers as they came otherwise โ€” safe for the people who read the docs closely, and nobody else.

It does not lose the last thirty seconds

Data is batched and sent every flush interval. A deploy sends SIGTERM, and an app that exits immediately used to take its last batch with it. The plugin now flushes on SIGTERM, SIGINT and beforeExit โ€” waiting at most three seconds โ€” and reports an uncaught exception or unhandled rejection before letting the process end as Node would have.

Batches are also cut to the server's limits (a busy app used to send one oversized batch and have it refused whole), buffers are bounded, and a Sentrinel outage is retried with backoff per data type, so a pile of request logs cannot push your metrics out of the queue.

The plugin reference has every option. Traces, structured logging and custom metrics work in Express exactly as they do in Elysia.