Sentrinel itself runs on Bun, and the plugin was born there โ which is why it has two Bun integrations. If your app uses Elysia, use the Elysia plugin: it knows your routes, your lifecycle hooks and your context, and the Elysia guide covers it end to end. If you are writing Bun.serve by hand, this one is for you.
import { sentrinelBunMiddleware } from "@sentrinel/plugin/bun";
Bun.serve({
fetch: sentrinelBunMiddleware(
{ serverUrl, appName: "edge-api", env: "prod", apiKey },
(req) => new Response("ok"),
),
});
It wraps your fetch handler, so it sees exactly what the caller saw: the status, the duration to the response, the error if your handler threw. Bun runs the plugin's TypeScript sources directly, so there is nothing to build.
What you get
The same signals as every other backend integration, correlated the same way:
- Requests, with status, duration, sizes, the consumer and the trace โ and errors for every 4xx and 5xx.
- Traces: an incoming
traceparentis continued, so a tap in the phone app and the request it caused are one waterfall; spans you add withtraceSpan()nest inside it. - Structured logs through
getLogger(), carrying the request and trace they were written in. - Custom metrics โ
count,gauge,histogramโ folded in memory and sent once per flush.
Routes without a router
This is the one real difference from a framework integration. Bun.serve has no router, so the wrapper cannot know that /orders/1042 is the route /orders/:id. The path is normalised the way the server normalises every path โ numbers, UUIDs and long hashes collapse to placeholders โ so an endpoint list does not grow one row per order. If your paths carry identifiers that do not look like ids, a router (or Elysia) that knows your routes is the better fit.
Bodies without the cost
With response-body logging on, the wrapper used to read the whole body of every 4xx and 5xx before returning it, just to keep the first few kilobytes. It now reads at most the configured cap and leaves streaming and binary responses alone. On the request path, the plugin's own work is an in-memory counter update โ no I/O, nothing awaited on Sentrinel.
Credentials in headers, query strings and bodies are masked before anything leaves the process, with no configuration. When Sentrinel is unreachable, batches are retried with backoff in bounded queues; on SIGTERM the buffer is flushed before the process exits.
The plugin reference has every option.