Skip to main content

Elysia

Beta

This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas.

@bugsee/elysia adds a request context, error reporting and, where the performance extension is present (Node.js, not @bugsee/bun), an http.server transaction to an Elysia app. It runs on Bun, and on Node.js through the app's fetch handler. Read the backend overview first for how context and trace correlation work.

You need an app token. Create a JavaScript application in Bugsee and choose Elysia as its target; see Create your app.

Install​

npm install @bugsee/elysia

On Bun, also install @bugsee/bun and import launch from it, as described in Running on Bun. In that setup the request context and error reporting work, but there is no http.server transaction.

The adapter declares no peer dependency. It only relies on the shape of your Elysia app. On Node.js it needs Node.js 18 or newer.

Set up​

Call launch() at the top of your server entry, then pass the app to setupElysia:

server.ts
import { launch, setupElysia } from '@bugsee/elysia';
import { Elysia } from 'elysia';

launch('<your_app_token>');

const app = new Elysia();
setupElysia(app);

// ... your routes ...

Hooks are scoped to the Elysia instance they are added to, so register setupElysia on the instance that owns your routes.

If your Elysia app type does not unify with the adapter's structural type, cast it:

import { type ElysiaAppLike, setupElysia } from '@bugsee/elysia';

setupElysia(app as unknown as ElysiaAppLike);

Node.js and Bun​

On Bun, the full Elysia server works.

On Node.js, Elysia's .listen is not supported: the adapter is tested only through the app's fetch handler, app.fetch, so use that. (Elysia's separate Node adapter is not covered by this SDK's tests.)

What it does​

Elysia hooks are additive, so setupElysia adds three without replacing yours:

HookWhat it does
onRequestOpens a request context, continues an inbound traceparent and starts an http.server transaction.
onErrorReports server errors, meaning a plain throw or a 5xx status. Framework control flow such as NOT_FOUND and VALIDATION is skipped.
mapResponseFinishes the transaction without altering the response.

Options​

Pass options as the second argument of setupElysia.

OptionTypeDefaultDescription
user(c) => string | undefinedoffThe end-user identity for reports raised during the request.
shouldReport(error) => booleanserver errors onlyDecides whether a thrown error is reported.
onError(error) => voidnoneReceives a failure of the adapter itself. It never reaches the request.

c is a structural view of the Elysia context: request, set and route.

Launch options​

The adapter does not change the launch options. These are the ones that matter most on a server:

OptionDefaultDescription
instrumentIncomingRequeststrueAutomatic per-request context and http.server transaction. See the backend overview.
captureLocalVariablesfalseAttach local variables to the stack frames of a reported error. Always off on Bun. See Diagnostics.
captureSourceContextfalseAttach the source lines around each stack frame. See Diagnostics.
detectHangstrueReport event-loop hangs. See Hangs.
profilingfalseAttach a rolling CPU profile to reports. See Diagnostics.

@bugsee/elysia installs @bugsee/bugsee for you and re-exports everything from its Node entry, so launch and the SDK types come from this one package. You do not install or import @bugsee/bugsee separately. On Bun, use @bugsee/bun for launch() and note that it has no http.server transaction; see Running on Bun.

Found an issue, typo, or wrong statement on this page? Report it now →