Skip to main content

hapi

Beta

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

@bugsee/hapi adds a request context, an http.server transaction and error reporting to a hapi server on Node.js. 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 hapi as its target; see Create your app.

Install​

npm install @bugsee/hapi

The adapter declares no peer dependency. It only relies on the shape of your @hapi/hapi server.

Set up​

Call launch() at the top of your server entry, then pass the server to setupHapi before server.start():

server.ts
import { launch, setupHapi } from '@bugsee/hapi';
import Hapi from '@hapi/hapi';

launch('<your_app_token>');

const server = Hapi.server({ port: 3000 });
setupHapi(server);

// ... your routes ...

server.start().catch((error) => {
console.error(error);
process.exit(1);
});

What it does​

setupHapi registers two request extensions. They are added next to yours and never replace them.

ExtensionWhat it does
onRequestOpens a request context, continues an inbound traceparent and starts an http.server transaction.
onPreResponseReports a Boom error and finishes the transaction. The response is not altered.

By default server errors (5xx) are reported and client errors (4xx) are skipped. A client disconnect finishes the transaction as cancelled.

Options​

Pass options as the second argument of setupHapi.

OptionTypeDefaultDescription
user(req) => string | undefinedoffThe end-user identity for reports raised during the request.
shouldReport(error) => boolean5xx or no statusDecides whether a thrown error is reported.
onError(error) => voidnoneReceives a failure of the adapter itself. It never reaches the request.

req is a structural view of the hapi request: method, path, route, headers and response.

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. 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/hapi 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, see Running on Bun.

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