diff --git a/cspell.json b/cspell.json index 1565e7f6..8b1f0385 100644 --- a/cspell.json +++ b/cspell.json @@ -2,6 +2,29 @@ "version": "0.2", "language": "en", "words": [ + "Rspack", + "rspack", + "Elysia", + "elysia", + "verylow", + "solidjs", + "navigations", + "workerd", + "traceresponse", + "rrweb", + "webtransport", + "unhandledrejection", + "speedscope", + "iban", + "ttfb", + "nitropack", + "melden", + "jsessionid", + "fastfail", + "bunx", + "Zusammenfassung", + "Senden", + "Kurze", "SIGSYS", "apptoken", "libbugsee", diff --git a/docs/index.md b/docs/index.md index 5c559391..67c450ac 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,6 +1,6 @@ --- title: "Overview" -description: "Overview of Bugsee SDK installation links and a feature comparison table across iOS, Android, React Native, Flutter, Unity, .NET, and Cordova." +description: "Overview of Bugsee SDK installation links and a feature comparison table across iOS, Android, React Native, Flutter, Unity, .NET, and Cordova (plus installation links for the JavaScript SDK)." sidebar_position: 0 slug: "/" --- @@ -14,6 +14,7 @@ Using Bugsee on mobile devices requires installation of Bugsee lightweight SDK: * [Installing Cordova SDK](/sdk/cordova/installation/) * [Installing React Native SDK](/sdk/react_native/v6/installation/) * [Installing Flutter SDK](/sdk/flutter/installation/) +* [Installing JavaScript SDK (Beta)](/sdk/javascript/installation/) — browsers, Node.js, Bun, Electron, edge runtimes and web frameworks * [Installing Unity SDK](/sdk/unity/installation/) * [Installing KMP SDK (Beta)](/sdk/kmp/installation/) * [Installing Xamarin SDK](/sdk/xamarin/installation/) — **deprecated**, use the [.NET SDK](/sdk/dotnet/installation/) for new projects diff --git a/docs/sdk/javascript/backend/elysia.mdx b/docs/sdk/javascript/backend/elysia.mdx new file mode 100644 index 00000000..2838c346 --- /dev/null +++ b/docs/sdk/javascript/backend/elysia.mdx @@ -0,0 +1,128 @@ +--- +title: "Elysia" +description: "Report errors and trace requests in an Elysia app on Bun or Node.js with the Bugsee JavaScript SDK: per-request context, http.server transactions and error capture." +sidebar_position: 8 +slug: "/sdk/javascript/backend/elysia" +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +:::warning[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](/sdk/javascript/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](/sdk/javascript/installation#create-your-app). + +## Install + + + + +```bash +npm install @bugsee/elysia +``` + + + + +```bash +pnpm add @bugsee/elysia +``` + + + + +```bash +yarn add @bugsee/elysia +``` + + + + +```bash +bun add @bugsee/elysia +``` + + + + +On Bun, also install `@bugsee/bun` and import `launch` from it, as described in [Running on Bun](/sdk/javascript/backend/overview#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`: + +```ts title="server.ts" +import { launch, setupElysia } from '@bugsee/elysia'; +import { Elysia } from 'elysia'; + +launch(''); + +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: + +```ts +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: + +| Hook | What it does | +| --- | --- | +| `onRequest` | Opens a request context, continues an inbound `traceparent` and starts an `http.server` transaction. | +| `onError` | Reports server errors, meaning a plain throw or a 5xx status. Framework control flow such as `NOT_FOUND` and `VALIDATION` is skipped. | +| `mapResponse` | Finishes the transaction without altering the response. | + +## Options + +Pass options as the second argument of `setupElysia`. + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `user` | `(c) => string \| undefined` | off | The end-user identity for reports raised during the request. | +| `shouldReport` | `(error) => boolean` | server errors only | Decides whether a thrown error is reported. | +| `onError` | `(error) => void` | none | Receives 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: + +| Option | Default | Description | +| --- | --- | --- | +| `instrumentIncomingRequests` | `true` | Automatic per-request context and `http.server` transaction. See the [backend overview](/sdk/javascript/backend/overview#incoming-request-instrumentation). | +| `captureLocalVariables` | `false` | Attach local variables to the stack frames of a reported error. Always off on Bun. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `captureSourceContext` | `false` | Attach the source lines around each stack frame. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `detectHangs` | `true` | Report event-loop hangs. See [Hangs](/sdk/javascript/issue-detection/hangs). | +| `profiling` | `false` | Attach a rolling CPU profile to reports. See [Diagnostics](/sdk/javascript/issue-detection/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](/sdk/javascript/backend/overview#running-on-bun). + +## Related pages + +- [Backend overview](/sdk/javascript/backend/overview) — request context, trace correlation and incoming-request instrumentation +- [Issue detection](/sdk/javascript/issue-detection/overview) — what else is detected on a server +- [Performance](/sdk/javascript/performance) — transactions and spans diff --git a/docs/sdk/javascript/backend/express.mdx b/docs/sdk/javascript/backend/express.mdx new file mode 100644 index 00000000..a9226e17 --- /dev/null +++ b/docs/sdk/javascript/backend/express.mdx @@ -0,0 +1,144 @@ +--- +title: "Express" +description: "Report errors and trace requests in an Express app with the Bugsee JavaScript SDK: per-request context, http.server transactions and error capture." +sidebar_position: 2 +slug: "/sdk/javascript/backend/express" +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +`@bugsee/express` adds a request context, an `http.server` transaction and error reporting to an Express app on Node.js. Read the [backend overview](/sdk/javascript/backend/overview) first for how context and trace correlation work. + +You need an app token. Create a JavaScript application in Bugsee and choose **Express** as its target; see [Create your app](/sdk/javascript/installation#create-your-app). + +## Install + + + + +```bash +npm install @bugsee/express +``` + + + + +```bash +pnpm add @bugsee/express +``` + + + + +```bash +yarn add @bugsee/express +``` + + + + +```bash +bun add @bugsee/express +``` + + + + +The adapter declares no peer dependency. It only relies on the shape of your Express app (Express 4 or 5). + +## Set up + +Call `launch()` at the top of your server entry, then pass the app to `setupExpress`: + +```ts title="server.ts" +import { launch, setupExpress } from '@bugsee/express'; +import express from 'express'; + +launch(''); + +const app = express(); +setupExpress(app); + +// ... your routes ... + +app.listen(3000); +``` + +`setupExpress` installs the request middleware immediately, so call it before you register routes. It installs the error handler for you: + +- It wraps `app.listen`, so the handler is added when the server starts listening, after your routes exist. +- An app that never calls `app.listen` (for example one passed to `http.createServer`) gets the handler on its first request. +- The handler is placed in front of any error middleware you already registered, so an error-response middleware that ends the response without calling `next(err)` does not hide the error from Bugsee. + +## Place the error handler yourself + +To control the position, turn off the automatic handler and add it with `setupExpressErrorHandler`: + +```ts title="server.ts" +import { setupExpress, setupExpressErrorHandler } from '@bugsee/express'; + +setupExpress(app, { autoErrorHandler: false }); + +// ... your routes ... + +setupExpressErrorHandler(app); // reports, then calls next(err) + +app.use((err, req, res, next) => { + // your error response +}); +``` + +For full control, the two middlewares are also exported on their own: `requestHandler()` (mount it first) and `errorHandler()` (mount it after your routes). + +## What it does + +- Opens a request context for each request, so everything reported inside a route is tagged with that request. +- Continues an inbound `traceparent` header and records an `http.server` transaction named after the route pattern, such as `/users/:id`. +- Reports an error that reaches the error handler, with the request context merged in, and then passes it on with `next(err)`. Your own error handling still runs. +- Does nothing, and passes every request through, when no client is launched. + +By default an error with no status, or with a status of 500 or higher, is reported, and a 4xx is skipped. + +## Options + +Pass options as the second argument of `setupExpress`. `setupExpressErrorHandler`, `requestHandler` and `errorHandler` take the same options, without `autoErrorHandler`. + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `user` | `(req) => string \| undefined` | off | The end-user identity for reports raised during the request. | +| `shouldReport` | `(error) => boolean` | 5xx or no status | Decides whether a thrown error is reported. | +| `onError` | `(error) => void` | none | Receives a failure of the adapter itself. It never reaches the request. | +| `autoErrorHandler` | `boolean` | `true` | Set `false` to place the error handler yourself. `setupExpress` only. | + +`req` is a structural view of the Express request: `method`, `url`, `originalUrl`, `route`, `baseUrl` and `headers`. Cast it to read fields added by your own middleware: + +```ts +setupExpress(app, { + user: (req) => (req as { user?: { id: string } }).user?.id, +}); +``` + +## Launch options + +The adapter does not change the launch options. These are the ones that matter most on a server: + +| Option | Default | Description | +| --- | --- | --- | +| `instrumentIncomingRequests` | `true` | Automatic per-request context and `http.server` transaction. See the [backend overview](/sdk/javascript/backend/overview#incoming-request-instrumentation). | +| `captureLocalVariables` | `false` | Attach local variables to the stack frames of a reported error. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `captureSourceContext` | `false` | Attach the source lines around each stack frame. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `detectHangs` | `true` | Report event-loop hangs. See [Hangs](/sdk/javascript/issue-detection/hangs). | +| `profiling` | `false` | Attach a rolling CPU profile to reports. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | + +`@bugsee/express` 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](/sdk/javascript/backend/overview#running-on-bun). + +## Related pages + +- [Backend overview](/sdk/javascript/backend/overview) — request context, trace correlation and incoming-request instrumentation +- [Issue detection](/sdk/javascript/issue-detection/overview) — what else is detected on a server +- [Performance](/sdk/javascript/performance) — transactions and spans diff --git a/docs/sdk/javascript/backend/fastify.mdx b/docs/sdk/javascript/backend/fastify.mdx new file mode 100644 index 00000000..a8d00b55 --- /dev/null +++ b/docs/sdk/javascript/backend/fastify.mdx @@ -0,0 +1,120 @@ +--- +title: "Fastify" +description: "Report errors and trace requests in a Fastify app with the Bugsee JavaScript SDK: per-request context, http.server transactions and error capture." +sidebar_position: 3 +slug: "/sdk/javascript/backend/fastify" +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +`@bugsee/fastify` adds a request context, an `http.server` transaction and error reporting to a Fastify app on Node.js. Read the [backend overview](/sdk/javascript/backend/overview) first for how context and trace correlation work. + +You need an app token. Create a JavaScript application in Bugsee and choose **Fastify** as its target; see [Create your app](/sdk/javascript/installation#create-your-app). + +## Install + + + + +```bash +npm install @bugsee/fastify +``` + + + + +```bash +pnpm add @bugsee/fastify +``` + + + + +```bash +yarn add @bugsee/fastify +``` + + + + +```bash +bun add @bugsee/fastify +``` + + + + +The adapter declares no peer dependency. It only relies on the shape of your Fastify instance. + +## Set up + +Call `launch()` at the top of your server entry, then pass the root Fastify instance to `setupFastify`: + +```ts title="server.ts" +import { launch, setupFastify } from '@bugsee/fastify'; +import Fastify from 'fastify'; + +launch(''); + +const app = Fastify(); +setupFastify(app); + +// ... your routes ... + +app.listen({ port: 3000 }).catch((error) => { + app.log.error(error); + process.exit(1); +}); +``` + +## What it does + +`setupFastify` installs lifecycle hooks: + +| Hook | What it does | +| --- | --- | +| `onRequest` | Opens a request context, continues an inbound `traceparent` and starts an `http.server` transaction. | +| `onError` | Reports an unhandled route error, with the request context merged in. | +| `onResponse` | Finishes the transaction with the route pattern, such as `/users/:id`, and the status. | +| `onRequestAbort` | Finishes the transaction as cancelled when the client aborts. | + +Fastify hooks are encapsulated per scope. Call `setupFastify` on the root instance and the hooks cover it and its child plugins. The order relative to your routes does not matter. + +By default an error with no status, or with a status of 500 or higher, is reported, and a 4xx is skipped. + +## Options + +Pass options as the second argument of `setupFastify`. + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `user` | `(req) => string \| undefined` | off | The end-user identity for reports raised during the request. | +| `shouldReport` | `(error) => boolean` | 5xx or no status | Decides whether a thrown error is reported. | +| `onError` | `(error) => void` | none | Receives a failure of the adapter itself. It never reaches the request. | + +`req` is a structural view of the Fastify request: `method`, `url`, `headers` and `routeOptions`. + +## Launch options + +The adapter does not change the launch options. These are the ones that matter most on a server: + +| Option | Default | Description | +| --- | --- | --- | +| `instrumentIncomingRequests` | `true` | Automatic per-request context and `http.server` transaction. See the [backend overview](/sdk/javascript/backend/overview#incoming-request-instrumentation). | +| `captureLocalVariables` | `false` | Attach local variables to the stack frames of a reported error. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `captureSourceContext` | `false` | Attach the source lines around each stack frame. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `detectHangs` | `true` | Report event-loop hangs. See [Hangs](/sdk/javascript/issue-detection/hangs). | +| `profiling` | `false` | Attach a rolling CPU profile to reports. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | + +`@bugsee/fastify` 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](/sdk/javascript/backend/overview#running-on-bun). + +## Related pages + +- [Backend overview](/sdk/javascript/backend/overview) — request context, trace correlation and incoming-request instrumentation +- [Issue detection](/sdk/javascript/issue-detection/overview) — what else is detected on a server +- [Performance](/sdk/javascript/performance) — transactions and spans diff --git a/docs/sdk/javascript/backend/hapi.mdx b/docs/sdk/javascript/backend/hapi.mdx new file mode 100644 index 00000000..98ba521d --- /dev/null +++ b/docs/sdk/javascript/backend/hapi.mdx @@ -0,0 +1,116 @@ +--- +title: "hapi" +description: "Report errors and trace requests in a hapi server with the Bugsee JavaScript SDK: per-request context, http.server transactions and error capture." +sidebar_position: 7 +slug: "/sdk/javascript/backend/hapi" +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +:::warning[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](/sdk/javascript/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](/sdk/javascript/installation#create-your-app). + +## Install + + + + +```bash +npm install @bugsee/hapi +``` + + + + +```bash +pnpm add @bugsee/hapi +``` + + + + +```bash +yarn add @bugsee/hapi +``` + + + + +```bash +bun add @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()`: + +```ts title="server.ts" +import { launch, setupHapi } from '@bugsee/hapi'; +import Hapi from '@hapi/hapi'; + +launch(''); + +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. + +| Extension | What it does | +| --- | --- | +| `onRequest` | Opens a request context, continues an inbound `traceparent` and starts an `http.server` transaction. | +| `onPreResponse` | Reports 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`. + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `user` | `(req) => string \| undefined` | off | The end-user identity for reports raised during the request. | +| `shouldReport` | `(error) => boolean` | 5xx or no status | Decides whether a thrown error is reported. | +| `onError` | `(error) => void` | none | Receives 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: + +| Option | Default | Description | +| --- | --- | --- | +| `instrumentIncomingRequests` | `true` | Automatic per-request context and `http.server` transaction. See the [backend overview](/sdk/javascript/backend/overview#incoming-request-instrumentation). | +| `captureLocalVariables` | `false` | Attach local variables to the stack frames of a reported error. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `captureSourceContext` | `false` | Attach the source lines around each stack frame. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `detectHangs` | `true` | Report event-loop hangs. See [Hangs](/sdk/javascript/issue-detection/hangs). | +| `profiling` | `false` | Attach a rolling CPU profile to reports. See [Diagnostics](/sdk/javascript/issue-detection/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](/sdk/javascript/backend/overview#running-on-bun). + +## Related pages + +- [Backend overview](/sdk/javascript/backend/overview) — request context, trace correlation and incoming-request instrumentation +- [Issue detection](/sdk/javascript/issue-detection/overview) — what else is detected on a server +- [Performance](/sdk/javascript/performance) — transactions and spans diff --git a/docs/sdk/javascript/backend/hono.mdx b/docs/sdk/javascript/backend/hono.mdx new file mode 100644 index 00000000..7a5db668 --- /dev/null +++ b/docs/sdk/javascript/backend/hono.mdx @@ -0,0 +1,108 @@ +--- +title: "Hono" +description: "Report errors and trace requests in a Hono app on Node.js or Bun with the Bugsee JavaScript SDK: per-request context, http.server transactions and error capture." +sidebar_position: 5 +slug: "/sdk/javascript/backend/hono" +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +`@bugsee/hono` adds a request context, an `http.server` transaction and error reporting to a Hono app hosted on Node.js or Bun. On Bun, see [Running on Bun](/sdk/javascript/backend/overview#running-on-bun) for the `launch` import and the missing `http.server` transaction. Read the [backend overview](/sdk/javascript/backend/overview) first for how context and trace correlation work. + +For Hono on an edge runtime, use the edge platform packages instead: [Cloudflare](/sdk/javascript/platforms/cloudflare) or [Vercel Edge](/sdk/javascript/platforms/vercel-edge). + +You need an app token. Create a JavaScript application in Bugsee and choose **Hono** as its target; see [Create your app](/sdk/javascript/installation#create-your-app). + +## Install + + + + +```bash +npm install @bugsee/hono +``` + + + + +```bash +pnpm add @bugsee/hono +``` + + + + +```bash +yarn add @bugsee/hono +``` + + + + +```bash +bun add @bugsee/hono +``` + + + + +The adapter declares no peer dependency. It only relies on the shape of your Hono app. + +## Set up + +Call `launch()` at the top of your server entry, then pass the app to `setupHono` before you register routes: + +```ts title="server.ts" +import { launch, setupHono } from '@bugsee/hono'; +import { Hono } from 'hono'; + +launch(''); + +const app = new Hono(); +setupHono(app); + +// ... your routes ... +``` + +## What it does + +`setupHono` registers one middleware. It opens a request context, continues an inbound `traceparent`, starts an `http.server` transaction named after the route, and, after `next()`, reports a handled error that Hono stored in `c.error`. Your `app.onError` handler is not touched. + +A Hono `HTTPException` is deliberate control flow and is not reported. Any other error is reported. + +## Options + +Pass options as the second argument of `setupHono`. + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `user` | `(c) => string \| undefined` | off | The end-user identity for reports raised during the request. | +| `shouldReport` | `(error) => boolean` | skips `HTTPException` | Decides whether a thrown error is reported. | +| `onError` | `(error) => void` | none | Receives a failure of the adapter itself. It never reaches the request. | + +`c` is a structural view of the Hono context: `c.req`, `c.res` and `c.error`. + +## Launch options + +The adapter does not change the launch options. These are the ones that matter most on a server: + +| Option | Default | Description | +| --- | --- | --- | +| `instrumentIncomingRequests` | `true` | Automatic per-request context and `http.server` transaction. See the [backend overview](/sdk/javascript/backend/overview#incoming-request-instrumentation). | +| `captureLocalVariables` | `false` | Attach local variables to the stack frames of a reported error. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `captureSourceContext` | `false` | Attach the source lines around each stack frame. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `detectHangs` | `true` | Report event-loop hangs. See [Hangs](/sdk/javascript/issue-detection/hangs). | +| `profiling` | `false` | Attach a rolling CPU profile to reports. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | + +`@bugsee/hono` 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](/sdk/javascript/backend/overview#running-on-bun). + +## Related pages + +- [Backend overview](/sdk/javascript/backend/overview) — request context, trace correlation and incoming-request instrumentation +- [Issue detection](/sdk/javascript/issue-detection/overview) — what else is detected on a server +- [Performance](/sdk/javascript/performance) — transactions and spans diff --git a/docs/sdk/javascript/backend/koa.mdx b/docs/sdk/javascript/backend/koa.mdx new file mode 100644 index 00000000..1ef27dc5 --- /dev/null +++ b/docs/sdk/javascript/backend/koa.mdx @@ -0,0 +1,108 @@ +--- +title: "Koa" +description: "Report errors and trace requests in a Koa app with the Bugsee JavaScript SDK: per-request context, http.server transactions and error capture." +sidebar_position: 6 +slug: "/sdk/javascript/backend/koa" +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +`@bugsee/koa` adds a request context, an `http.server` transaction and error reporting to a Koa app on Node.js. Read the [backend overview](/sdk/javascript/backend/overview) first for how context and trace correlation work. + +You need an app token. Create a JavaScript application in Bugsee and choose **Koa** as its target; see [Create your app](/sdk/javascript/installation#create-your-app). + +## Install + + + + +```bash +npm install @bugsee/koa +``` + + + + +```bash +pnpm add @bugsee/koa +``` + + + + +```bash +yarn add @bugsee/koa +``` + + + + +```bash +bun add @bugsee/koa +``` + + + + +The adapter declares no peer dependency. It only relies on the shape of your Koa app. + +## Set up + +Call `launch()` at the top of your server entry, then pass the app to `setupKoa`. Register it before your other middleware so that it wraps the whole chain: + +```ts title="server.ts" +import { launch, setupKoa } from '@bugsee/koa'; +import Koa from 'koa'; + +launch(''); + +const app = new Koa(); +setupKoa(app); + +// ... your middleware and routes ... + +app.listen(3000); +``` + +## What it does + +`setupKoa` installs one middleware. It opens a request context, continues an inbound `traceparent`, starts an `http.server` transaction, and reports an error thrown downstream before re-throwing it untouched, so Koa's own `onerror` still formats the response. + +By default a plain throw or a 5xx is reported, and a 4xx such as `ctx.throw(404)` is skipped. With `@koa/router`, the transaction is named after the matched route. + +## Options + +Pass options as the second argument of `setupKoa`. + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `user` | `(ctx) => string \| undefined` | off | The end-user identity for reports raised during the request. | +| `shouldReport` | `(error) => boolean` | 5xx or no status | Decides whether a thrown error is reported. | +| `onError` | `(error) => void` | none | Receives a failure of the adapter itself. It never reaches the request. | + +`ctx` is a structural view of the Koa context: `method`, `path`, `url`, `status` and `headers`. + +## Launch options + +The adapter does not change the launch options. These are the ones that matter most on a server: + +| Option | Default | Description | +| --- | --- | --- | +| `instrumentIncomingRequests` | `true` | Automatic per-request context and `http.server` transaction. See the [backend overview](/sdk/javascript/backend/overview#incoming-request-instrumentation). | +| `captureLocalVariables` | `false` | Attach local variables to the stack frames of a reported error. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `captureSourceContext` | `false` | Attach the source lines around each stack frame. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `detectHangs` | `true` | Report event-loop hangs. See [Hangs](/sdk/javascript/issue-detection/hangs). | +| `profiling` | `false` | Attach a rolling CPU profile to reports. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | + +`@bugsee/koa` 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](/sdk/javascript/backend/overview#running-on-bun). + +## Related pages + +- [Backend overview](/sdk/javascript/backend/overview) — request context, trace correlation and incoming-request instrumentation +- [Issue detection](/sdk/javascript/issue-detection/overview) — what else is detected on a server +- [Performance](/sdk/javascript/performance) — transactions and spans diff --git a/docs/sdk/javascript/backend/nestjs.mdx b/docs/sdk/javascript/backend/nestjs.mdx new file mode 100644 index 00000000..83280120 --- /dev/null +++ b/docs/sdk/javascript/backend/nestjs.mdx @@ -0,0 +1,144 @@ +--- +title: "NestJS" +description: "Report errors and trace requests in a NestJS app with the Bugsee JavaScript SDK, and choose where errors are caught: interceptor, exception filter or both." +sidebar_position: 4 +slug: "/sdk/javascript/backend/nestjs" +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +`@bugsee/nestjs` adds a request context, an `http.server` transaction and error reporting to a NestJS app on the Express or Fastify platform. Read the [backend overview](/sdk/javascript/backend/overview) first for how context and trace correlation work. + +You need an app token. Create a JavaScript application in Bugsee and choose **NestJS** as its target; see [Create your app](/sdk/javascript/installation#create-your-app). + +## Install + + + + +```bash +npm install @bugsee/nestjs +``` + + + + +```bash +pnpm add @bugsee/nestjs +``` + + + + +```bash +yarn add @bugsee/nestjs +``` + + + + +```bash +bun add @bugsee/nestjs +``` + + + + +Peer dependencies: `@nestjs/common` and `@nestjs/core` (version 9, 10, 11 or 12) and `rxjs` 7. Node.js 18 or newer, and Node.js 20 or newer for Nest 12 itself. + +## Set up + +Call `launch()` at the top of your server entry, then pass the Nest application to `setupNest`: + +```ts title="main.ts" +import { launch, setupNest } from '@bugsee/nestjs'; +import { NestFactory } from '@nestjs/core'; +import { AppModule } from './app.module'; + +launch(''); + +async function bootstrap() { + const app = await NestFactory.create(AppModule); + setupNest(app); + await app.listen(3000); +} + +void bootstrap(); +``` + +`launch()` returns the client directly on Node.js, so it needs no `await`. The `bootstrap` function keeps the example valid in a CommonJS project, where top-level `await` is not available. + +## What it does + +`setupNest` installs two things: + +- A **context middleware** that opens a request context for each request. +- By default, a **global interceptor** that starts an `http.server` transaction, continues an inbound `traceparent`, and reports a thrown error before re-throwing it untouched. Nest's own exception filters still format the response. + +A Nest `HttpException` is deliberate control flow and is not reported, whatever its status. Any other thrown error is reported. + +## Choose where errors are caught + +The `errorCapture` option picks the seam that catches errors. + +| `errorCapture` | Catches | Notes | +| --- | --- | --- | +| `'interceptor'` (default) | Route handlers, services and pipes | Reports and re-throws. Never conflicts with your own filter. Does not see errors thrown in guards. | +| `'filter'` | Also guards | Installs a global `ExceptionFilter`. Being a catch-all, it can collide with your own global filter. | +| `'both'` | Everything above | Interceptor and filter together. An error is reported once. | + +```ts +setupNest(app, { errorCapture: 'both' }); +``` + +If you already have a global exception filter, keep the default or decorate your filter's `catch` method with `BugseeExceptionCaptured` instead of using `'filter'` or `'both'`: + +```ts +import { BugseeExceptionCaptured } from '@bugsee/nestjs'; + +@Catch() +export class MyFilter extends BaseExceptionFilter { + @BugseeExceptionCaptured() + catch(exception: unknown, host: ArgumentsHost) { + // your handling + } +} +``` + +## Options + +Pass options as the second argument of `setupNest`. + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `errorCapture` | `'interceptor' \| 'filter' \| 'both'` | `'interceptor'` | Where errors are caught. See above. | +| `user` | `(req) => string \| undefined` | off | The end-user identity for reports raised during the request. | +| `shouldReport` | `(error) => boolean` | skips `HttpException` | Decides whether a thrown error is reported. | +| `onError` | `(error) => void` | none | Receives a failure of the adapter itself. It never reaches the request. | + +`req` is a structural view of the request of your Nest platform (Express or Fastify): `method`, `url`, `originalUrl`, `route`, `routeOptions` and `headers`. + +## Launch options + +The adapter does not change the launch options. These are the ones that matter most on a server: + +| Option | Default | Description | +| --- | --- | --- | +| `instrumentIncomingRequests` | `true` | Automatic per-request context and `http.server` transaction. See the [backend overview](/sdk/javascript/backend/overview#incoming-request-instrumentation). | +| `captureLocalVariables` | `false` | Attach local variables to the stack frames of a reported error. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `captureSourceContext` | `false` | Attach the source lines around each stack frame. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | +| `detectHangs` | `true` | Report event-loop hangs. See [Hangs](/sdk/javascript/issue-detection/hangs). | +| `profiling` | `false` | Attach a rolling CPU profile to reports. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). | + +`@bugsee/nestjs` 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](/sdk/javascript/backend/overview#running-on-bun). + +## Related pages + +- [Backend overview](/sdk/javascript/backend/overview) — request context, trace correlation and incoming-request instrumentation +- [Issue detection](/sdk/javascript/issue-detection/overview) — what else is detected on a server +- [Performance](/sdk/javascript/performance) — transactions and spans diff --git a/docs/sdk/javascript/backend/overview.mdx b/docs/sdk/javascript/backend/overview.mdx new file mode 100644 index 00000000..3dc6a7d4 --- /dev/null +++ b/docs/sdk/javascript/backend/overview.mdx @@ -0,0 +1,185 @@ +--- +title: "Backend overview" +description: "How the Bugsee JavaScript SDK instruments Node.js and Bun servers: per-request context, trace correlation, automatic incoming-request instrumentation and the framework adapters." +sidebar_position: 1 +slug: "/sdk/javascript/backend/overview" +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +On a server, Bugsee records what your process was doing around a failure and ties it to the request that was running. Each request gets a context and an `http.server` transaction, and an error reported while the request runs carries both. + +## What Bugsee records + +- **Per-request context.** A request context holds an id, the trace of the request and, if you provide it, the end-user identity. Everything Bugsee captures while the request runs (logs, network calls, breadcrumbs) is tagged with it. +- **An `http.server` transaction per request** (Node.js; not on Bun with `@bugsee/bun`, see [Running on Bun](#running-on-bun)). It is named after the route, carries the method and the response status, and continues the trace of the caller when the request has a `traceparent` header. See [Performance](/sdk/javascript/performance). +- **Errors.** A framework adapter reports an error your route throws, with the request context merged into the report. +- **Process-level signals.** Uncaught exceptions, unhandled rejections and event-loop hangs are detected for the whole process. See [Issue detection](/sdk/javascript/issue-detection/overview). + +## How it works + +Two layers cooperate: + +1. **Incoming-request instrumentation** is part of the SDK and needs no adapter. It is on by default and covers any server built on `node:http` or `Bun.serve`. +2. **A framework adapter** adds what the SDK cannot see from outside: reporting of errors that the framework catches, the route pattern as the transaction name, and your `user` getter. + +When both run, the first one to see a request owns its context and transaction. The other one refines them (route name, user, error report), so a request gets exactly one context and one transaction. + +## Request context + +A request context lives in Node's `AsyncLocalStorage`, so it follows the request through every `await`, timer and callback it starts. Concurrent requests each see their own context. + +Bugsee tags; it does not isolate. There is one capture buffer for the process. Every entry recorded while a context is active is stamped with the context id, and with the trace id and span id when the request has a trace. The entries of concurrent requests are interleaved in the same recording, and the stamp is what tells them apart. An entry recorded outside any request, such as a timer or a startup log, carries no stamp. + +When a report is created inside a context, it records the context id. The context's `user` and attributes are merged over the global ones for that report only, so a user set for one request never leaks into another. + +You do not create or enter a context yourself. The incoming-request instrumentation or the adapter does it. + +## Incoming-request instrumentation + +`instrumentIncomingRequests` is `true` by default. Set it to `false` to turn it off. + +```ts +import { launch } from '@bugsee/express'; // or the adapter for your framework + +launch('', { + instrumentIncomingRequests: false, +}); +``` + +When it is on: + +- On Node.js and Bun, Bugsee patches `emit` on the `node:http` and `node:https` server prototypes. Every `request` event runs inside a context and, when the performance extension is present, a transaction. `@bugsee/bun` has no performance extension, so there is a context but no transaction on Bun. +- On Bun with `@bugsee/bun`, it also wraps `Bun.serve` when you pass it a `fetch` handler. The Node.js build that an adapter re-exports does not wrap `Bun.serve`. +- Where there is a transaction, it is named ` `, with the query string removed, until an adapter refines it to the route pattern, for example `/users/:id`. +- No headers and no bodies of the incoming request are captured by this layer. + +:::note +A framework that catches a thrown error and turns it into a 500 response hides it from `node:http`, so automatic instrumentation cannot report it. That is what the adapters are for. An error nobody catches is still detected as a crash. +::: + +## Trace correlation + +**Inbound.** When a request carries a valid W3C `traceparent` header, the `http.server` transaction continues that trace: it adopts the trace id, becomes a child of the caller's span and follows the caller's sampling decision. Entries recorded during the request are stamped with that trace id. + +**Outbound.** Bugsee adds `traceparent` to the outgoing requests your server makes, so the downstream service continues the same trace. `propagateTrace` is `true` by default, but a server has no same-origin concept, so nothing is sent until you list your own services in `tracePropagationTargets`. This keeps the trace from leaking to third-party APIs. + +```ts +launch('', { + tracePropagationTargets: [ + // One host, any port, path or query + /^https?:\/\/billing\.internal\.example\.com(?::\d+)?(?:[/?#]|$)/, + // Any subdomain of your internal domain + /^https?:\/\/[^/?#:@]+\.internal\.example\.com(?::\d+)?(?:[/?#]|$)/, + ], +}); +``` + +A target is a string or a regular expression; functions are not accepted. Each is tested against the full request URL, including scheme, port, path and query. A string matches anywhere in the URL, so `'https://billing.internal.example.com'` also matches `https://billing.internal.example.com.attacker.test/` and `https://attacker.test/?u=https://billing.internal.example.com`. Use a string only for a complete URL prefix you control. For hosts, use regular expressions anchored with `^` that end at the host boundary, as above: the scheme is `http` or `https`, an optional port follows the host, and the next character must be `/`, `?`, `#` or the end of the URL. + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `instrumentIncomingRequests` | `boolean` | `true` | Open a context and an `http.server` transaction for each incoming request. | +| `propagateTrace` | `boolean` | `true` | Add `traceparent` to outgoing requests. Needs `tracePropagationTargets`. `false` turns it off. | +| `tracePropagationTargets` | `(string \| RegExp)[]` | none | Outgoing URLs allowed to receive the trace headers. A string matches as a substring. | +| `traceResponse` | `{ traceresponse?: boolean, serverTiming?: boolean }` | both off | Return the trace to the caller in a `traceresponse` header, a `Server-Timing` entry, or both. | + +`traceResponse` also accepts `timingAllowOrigin` and `exposeTraceresponse` for cross-origin browsers. + +## Framework adapters + +Install only the adapter for your framework. It installs `@bugsee/bugsee` for you and re-exports the Node entry of it, so you import `launch` and the adapter's setup function from the same package. + +| Framework | Package | Setup call | Page | +| --- | --- | --- | --- | +| Express | `@bugsee/express` | `setupExpress(app)` | [Express](/sdk/javascript/backend/express) | +| Fastify | `@bugsee/fastify` | `setupFastify(app)` | [Fastify](/sdk/javascript/backend/fastify) | +| NestJS | `@bugsee/nestjs` | `setupNest(app)` | [NestJS](/sdk/javascript/backend/nestjs) | +| Hono | `@bugsee/hono` | `setupHono(app)` | [Hono](/sdk/javascript/backend/hono) | +| Koa | `@bugsee/koa` | `setupKoa(app)` | [Koa](/sdk/javascript/backend/koa) | +| hapi | `@bugsee/hapi` | `setupHapi(server)` | [hapi](/sdk/javascript/backend/hapi) | +| Elysia | `@bugsee/elysia` | `setupElysia(app)` | [Elysia](/sdk/javascript/backend/elysia) | + +Call `launch()` first, at the top of your server entry. If no client is launched, an adapter does nothing and passes every request through. + +### Adapter options + +Every adapter takes an options object as its second argument. + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `user` | `(request) => string \| undefined` | off | The end-user identity for reports raised during the request. Nothing identifying is read unless you provide it. The argument is the framework's request or context object. | +| `shouldReport` | `(error) => boolean` | status-based | Decides whether a thrown error is reported. | +| `onError` | `(error) => void` | none | Receives a failure of the adapter itself. It never reaches the request. | + +The default `shouldReport` reports an error that has no HTTP status or a status of 500 or higher, and skips a 4xx. It reads the status from `getStatus()`, `status`, `statusCode` or `output.statusCode`. Some adapters add framework rules on top, described on their pages. + +An adapter never throws into your request pipeline. + +## Running on Bun + +The `launch` that an adapter re-exports is the Node.js build. On Bun it works, but reports name the runtime `node`, and `Bun.serve` requests are not instrumented. On Bun, install `@bugsee/bun` next to the adapter and import `launch` from it: + +```bash +bun add @bugsee/elysia @bugsee/bun +``` + +```ts +import { launch } from '@bugsee/bun'; +import { setupElysia } from '@bugsee/elysia'; +``` + +The adapter's setup function and the rest of its API are the same, with two differences. `@bugsee/bun` does not include the performance extension, so there is no `http.server` transaction on Bun; the request context, error reporting and trace tagging still work. And `captureLocalVariables` is always off on Bun. See [Bun](/sdk/javascript/platforms/bun). + +## Requirements + +- Node.js 18 or newer, or Bun 1.1.13 or newer. +- The adapter package for your framework. It brings `@bugsee/bugsee` with it. On a server, `launch()` returns the client directly and does not return a promise. + +## Install + + + + +```bash +npm install @bugsee/express +``` + + + + +```bash +pnpm add @bugsee/express +``` + + + + +```bash +yarn add @bugsee/express +``` + + + + +```bash +bun add @bugsee/express +``` + + + + +Replace `@bugsee/express` with the adapter for your framework. + +## Related pages + +- [Express](/sdk/javascript/backend/express) — the first adapter to read, with the most detail on error-handler placement +- [Issue detection](/sdk/javascript/issue-detection/overview) — crashes, hangs and HTTP errors on a server +- [Performance](/sdk/javascript/performance) — the transactions and spans the adapters create +- [OpenTelemetry](/sdk/javascript/opentelemetry) — export transactions to your own backend +- [Node.js platform](/sdk/javascript/platforms/node) — the options that apply to every Node process diff --git a/docs/sdk/javascript/breadcrumbs.md b/docs/sdk/javascript/breadcrumbs.md new file mode 100644 index 00000000..a580fd98 --- /dev/null +++ b/docs/sdk/javascript/breadcrumbs.md @@ -0,0 +1,120 @@ +--- +title: "Breadcrumbs" +description: "What breadcrumbs are in the Bugsee JavaScript SDK, which ones are recorded automatically, how to record your own with addBreadcrumb, and how to rewrite or drop them with setBreadcrumbFilter." +sidebar_position: 22 +slug: "/sdk/javascript/breadcrumbs" +--- + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +Breadcrumbs are a short trail of steps leading up to an issue: a screen the user opened, a form they submitted, something your code decided. They appear on the report timeline. Unlike console logs, a breadcrumb is structured: it has a type, a category, a message and a data object. + +The examples use the client returned by `launch`, kept in a module of your own: + +```ts title="bugsee.ts" +import { launch } from '@bugsee/bugsee'; + +export const bugsee = await launch(''); +``` + +Import this module first in your entry file, before your app bootstraps, not lazily. Capture covers only what runs after `launch()`, and code that runs earlier is not recorded. + +## Turning breadcrumbs on or off + +Breadcrumb capture is **on by default** in the JavaScript SDK. The mobile Bugsee SDKs default it to off, because web UI breadcrumbs are a core signal. + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `captureBreadcrumbs` | `boolean` | `true` | Record breadcrumbs: yours and the automatic ones. | +| `captureInteractions` | `boolean` | `true` | Browser. Also controls the automatic `ui.*` breadcrumbs, and the input stream. | + +```ts +import { launch } from '@bugsee/bugsee'; + +export const bugsee = await launch('', { + captureBreadcrumbs: false, // no breadcrumb is recorded at all +}); +``` + +A malformed `captureBreadcrumbs` value turns capture off and is reported through the `onError` launch option. + +## Where breadcrumbs come from + +- **Your code**, with `addBreadcrumb`. +- **User interface changes in the browser.** The SDK records `ui.change`, `ui.submit` and `ui.focus` breadcrumbs when a form value changes, a form is submitted, or an element gets focus. Each carries the target's element id, class and tag in `data` (`view.id`, `view.class`, `view.tag`) and never reads a value or any text the user typed. A field the SDK treats as sensitive, such as a password, and anything inside an element with a `data-bugsee-hidden` attribute, produces no breadcrumb at all. +- **Framework adapters.** Some adapters add breadcrumbs for navigation. For example the Next.js client hook records the destination of a route change. + +During a [blackout](/sdk/javascript/lifecycle) the automatic `ui.*` breadcrumbs are not recorded. Breadcrumbs you add yourself still are. + +## Record your own breadcrumb + +```ts +import { bugsee } from './bugsee'; + +bugsee.addBreadcrumb({ + type: 'navigation', + category: 'checkout', + message: 'Opened the payment step', + level: 'info', + data: { step: 3, cartItems: 2 }, +}); +``` + +| Field | Type | Description | +| --- | --- | --- | +| `type` | `string` | A free-form kind, for example `navigation`, `user` or `http`. | +| `category` | `string` | A free-form group, for example `checkout` or `ui.click`. | +| `message` | `string` | A short description. | +| `level` | `'error' \| 'warning' \| 'info' \| 'debug' \| 'verbose'` | Severity of the step. | +| `data` | `Record` | Extra structured detail. Keep it small and JSON-friendly. | +| `timestamp` | `number` | Milliseconds since the epoch. The SDK stamps the current time when you omit it. | + +All fields are optional. The `Breadcrumb` and `BreadcrumbInput` types are exported by `@bugsee/bugsee`. + +:::caution +`addBreadcrumb` does not sanitize anything. A breadcrumb is application data, so a URL with a token in `message` or `data` is recorded as it is. Redact it yourself, or use a [breadcrumb filter](#filter-breadcrumbs). +::: + +### When nothing is recorded + +`addBreadcrumb` does nothing when `captureBreadcrumbs` is `false`, or once the collector has switched the SDK off for your app. + +## Filter breadcrumbs + +`setBreadcrumbFilter(filter)` installs a function that sees every breadcrumb before it is recorded: yours, the automatic ones and the adapters'. Return the breadcrumb, changed or not, to keep it, or `null` to drop it. Pass `null` to remove the filter. + +```ts +import { bugsee } from './bugsee'; + +const SECRET_PARAMS = /([?&](?:token|access_token|code|session)=)[^&#\s]*/gi; + +bugsee.setBreadcrumbFilter((crumb) => { + // Drop a whole category of your own breadcrumbs + if (crumb.category === 'auth') { + return null; + } + return { + ...crumb, + message: crumb.message?.replace(SECRET_PARAMS, '$1'), + // Remove data you do not want on a report + data: crumb.data === undefined ? undefined : { ...crumb.data, email: undefined }, + }; +}); +``` + +The filter receives a `Breadcrumb`, which is the fields above with `timestamp` always set. + +Rules: + +- **A filter that throws drops the breadcrumb.** The error goes to `onError`, and nothing unredacted is recorded. +- **There is one filter at a time.** A later call replaces it. Set it right after `launch`. Breadcrumbs recorded before the filter is installed are kept as they are. `relaunch()` returns a new client, so set the filter again on it. +- **Your network filter does not reach breadcrumbs.** If a breadcrumb of yours carries a URL, redact it here. See [Privacy: Breadcrumbs](/sdk/javascript/privacy/breadcrumbs). + +## Related pages + +- [Privacy: Breadcrumbs](/sdk/javascript/privacy/breadcrumbs) — keep sensitive data out of the trail. +- [Console logs](/sdk/javascript/logs) — unstructured log lines. +- [Events & traces](/sdk/javascript/events-and-traces) — your own named events and values. +- [Configuration](/sdk/javascript/configuration) — every launch option. diff --git a/docs/sdk/javascript/configuration.mdx b/docs/sdk/javascript/configuration.mdx new file mode 100644 index 00000000..a77b7422 --- /dev/null +++ b/docs/sdk/javascript/configuration.mdx @@ -0,0 +1,333 @@ +--- +title: "Configuration" +description: "Launch options of the Bugsee JavaScript SDK: shared options, then browser, Node.js and Bun, Electron, edge and worker options, extension options, invalid-value rules and reading options back." +sidebar_position: 2 +slug: "/sdk/javascript/configuration" +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +You configure the SDK with the options object you pass as the second argument of `launch(appToken, options)`. Every option is optional. Option names are plain camelCase names, such as `captureNetwork`. The same names work on every runtime that has the option. + + + + +```ts +import { launch } from '@bugsee/bugsee'; + +launch('', { + appVersion: '1.4.2', + appBuild: '381', + captureNetworkBodies: false, + maxRecordingTime: 30, + onError: (error) => console.error(error), +}); +``` + + + + +```js +import { launch } from '@bugsee/bugsee'; + +launch('', { + appVersion: '1.4.2', + appBuild: '381', + captureNetworkBodies: false, + maxRecordingTime: 30, + onError: (error) => console.error(error), +}); +``` + + + + +Which options exist depends on the runtime. This page has a section for each: + +- [Shared options](#shared-options): every runtime. +- [Browser](#browser). +- [Node.js and Bun](#nodejs-and-bun). +- [Electron](#electron). +- [Edge and workers](#edge-and-workers): Cloudflare Workers, Vercel Edge, Web and Service Workers. +- [Extension options](#extension-options): performance, trace propagation and OpenTelemetry, from the umbrella package. + +The TypeScript types are the exact reference for your version: `BugseeLaunchOptionsWithPerformance` in the browser and `BugseeNodeLaunchOptions` on Node.js, both exported from `@bugsee/bugsee`. + +## Invalid values + +The SDK checks every option it reads. An invalid value never throws. It is reported through `onError`, and the option takes a safe value: + +- **On-by-default capture options turn off.** `captureLogs`, `captureNetwork`, `captureNetworkBodies`, `captureSystemTraces`, `captureSystemEvents` and `captureBreadcrumbs` are on by default. A value that is not `true` or `false` (`0`, `null`, `''`, `'false'`) turns the option off, so a mistake never leaves capture running. +- **Options that collect more data stay off.** Only `true` (or an options object, where one is accepted) turns on an option that defaults to off, such as `captureLocalVariables`, `captureSourceContext` and `captureUserIdle`. +- **Other options keep their default.** For instance `detectCrashes` and `captureNetworkDefaultSanitizer` keep their default, which is on. +- **Protective options stay protective.** `startInBlackout` and `diskProtection` treat any value other than `false` as on. + +Pass `onError` while you integrate, so you see these messages. + +## Shared options + +These options exist on every runtime. Where a default differs by runtime, the table says so. + +### App identity + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `endpoint` | `string` | `https://api.bugsee.com` | API origin, without a trailing slash. | +| `appId` | `string` | none | Package or bundle identifier of your app. | +| `appVersion` | `string` | detected | Version of your app. Detected from build-time constants, then the environment, then `package.json` (servers) or meta tags (browser). Falls back to `0.0.0`. See [Quick start](/sdk/javascript/quick-start#app-version-and-build). | +| `appBuild` | `string` | detected | Build of your app, detected the same way. | +| `sdkVersion` | `string` | package version | SDK version reported in the environment. You rarely need to set it. | + +### Capture + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `captureLogs` | `boolean` | `true` | Capture console output as logs. See [Console logs](/sdk/javascript/logs). | +| `captureLogsLevel` | `'error' \| 'warning' \| 'info' \| 'debug' \| 'verbose'` or `1`-`5` | `'verbose'` | Lowest log level to capture. | +| `captureNetwork` | `boolean` | `true` | Capture network requests. See [Network events](/sdk/javascript/network). | +| `captureNetworkBodies` | `boolean` | `true` | Capture request and response bodies. | +| `maxNetworkBodySize` | `number` | `20480` | Largest body to capture, in bytes. | +| `captureNetworkBodyWithoutType` | `boolean` | `false` | Capture a body even when its `Content-Type` is missing or blank. | +| `captureNetworkDefaultSanitizer` | `boolean` | `true` | Apply the built-in redaction to URLs, headers, bodies and error text. A network filter you set replaces it; see [Privacy: Network](/sdk/javascript/privacy/network). | +| `captureBreadcrumbs` | `boolean` | `true` | Capture breadcrumbs. Mobile Bugsee SDKs default this to off; JavaScript keeps it on. See [Breadcrumbs](/sdk/javascript/breadcrumbs). | +| `captureSystemTraces` | `boolean` | `true` | Capture periodic system traces (memory, CPU, event-loop lag and so on, depending on the runtime). | +| `captureSystemEvents` | `boolean` | `true` | Capture system events (process or page lifecycle and similar). | +| `maxRecordingTime` | `number` | `60` | Rolling recording window, in seconds. | +| `maxDataSize` | `number` | `50` Node.js and Bun and Electron main, `20` browser (`30` with the IndexedDB store), `10` edge and workers | Size of the rolling capture buffer, in megabytes. | + +### Detection and reporting + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `detectCrashes` | `boolean` | `true` | Detect uncaught errors and unhandled promise rejections. See [Errors & crashes](/sdk/javascript/issue-detection/errors-and-crashes). | +| `detectHttpErrors` | `boolean` | `false` | Report HTTP 5xx responses as `error` reports, once per session for each method, templated URL and status. 4xx responses, transport failures and aborted requests are not reported. See [HTTP errors](/sdk/javascript/issue-detection/http-errors). | +| `reportDefaultCrashPriority` | priority | `'blocker'` | Severity a crash report starts with. | +| `reportDefaultErrorPriority` | priority | `'high'` | Severity an error report starts with. | +| `reportDefaultBugPriority` | priority | `'high'` | Severity a bug report starts with when none is given. The browser report dialog pre-selects it. | +| `notifyFlushDelay` | `number` | `0` | `notify()` batching window, in milliseconds. `0` sends as soon as the current tick ends. | + +A priority is one of `'verylow'`, `'low'`, `'medium'`, `'high'`, `'critical'` or `'blocker'`. + +### Callbacks + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `onError` | `(error: unknown) => void` | no-op | Receives internal SDK problems: invalid options, a failed provider, a repeated `launch()`, a missing token. | +| `lifecycleEventsListener` | `(eventType: string, data?: unknown) => void` | none | Observes launch, stop, blackout and report events, from the very first `Launching` event. See [Lifecycle & status](/sdk/javascript/lifecycle#lifecycle-events). | + +## Browser + +These options apply to the browser build, and so also to the browser side of the framework adapters and to Electron renderers. + +### Capture and persistence + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `captureInteractions` | `boolean` | `true` | Capture user interactions: presses become entries of the SDK's input stream, and changes, submits and focus become UI breadcrumbs. | +| `captureViewHierarchy` | `boolean` | `true` | Capture the DOM view hierarchy when a report is made. | +| `captureUrl` | `boolean` | `true` | Record the page address, sanitized, as the `url` system trace. Needs `captureSystemTraces`. | +| `urlSanitizer` | `(url: string) => string \| null` | none | Your own sanitizer for the `url` trace. It runs after the default one and gets its result. Return `null` to record nothing for that URL. A throw records nothing. | +| `captureAsyncOrigins` | `boolean` | `true` | Record where asynchronous platform calls (such as `video.play()`) were made, so a rejection with no stack still has a call site. Only `false` opts out. | +| `captureEnvironmentHints` | `boolean` | `true` | Observe hints such as a private-browsing heuristic, reported as a system event. | +| `captureUserIdle` | `boolean` | `false` | Record the `user_idle_state` trace. Only works when the page's idle-detection permission is already granted; the SDK never asks for it. | +| `persistUserIdentifier` | `boolean` | `false` | Keep the user identifier set with `setUserIdentifier` in `localStorage`, so it survives a reload. Off by default because the identifier is often personal data and a browser can be shared. Call `clearUserIdentifier()` on logout. | +| `startInBlackout` | `boolean` | `false` | Launch with a blackout already in force, so visual and interaction capture stays off until `endBlackout()`. See [Lifecycle & status](/sdk/javascript/lifecycle#blackout). | +| `persist` | `boolean` | on when the page has IndexedDB and Web Locks | Keep the capture window and the report queue in IndexedDB so they survive a reload. `true` forces it, `false` keeps everything in memory. | +| `recover` | `boolean` | `true` | Re-upload a report left behind by an earlier reload or crash. Needs a persistent store. | +| `captureDiskSpace` | `boolean` | `false` | Add low-storage states to the `capture` trace. Needs a durable store. | +| `diskProtection` | `boolean` | `true` | Stop persisting replay, log and network data when the browser's storage quota runs low. Only `false` opts out. | + +### Session replay + +`replay` is on by default and masks aggressively. Pass `false` to turn it off, or an object to tune it. See [Session replay](/sdk/javascript/session-replay) and [Privacy: Session replay](/sdk/javascript/privacy/replay). + +```ts +launch('', { + replay: { + maskTextSelector: '.account-balance', + blockSelector: '.secret-panel', + canvas: { fps: 2, quality: 0.6 }, + }, +}); +``` + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `replay` | `boolean \| object` | `true` | `false` disables replay. An invalid value (`null`, `0`, a string, an array) turns it off and is reported. | +| `replay.maskAllText` | `boolean` | `true` | Mask every text node. | +| `replay.maskAllInputs` | `boolean` | `true` | Mask every input value. | +| `replay.blockAllMedia` | `boolean` | `true` | Block all media and iframes. | +| `replay.blockAllCanvas` | `boolean` | `false` | Block every canvas except those marked to show. | +| `replay.maskTextSelector` | `string` | none | CSS selector of extra elements whose text to mask. | +| `replay.blockSelector` | `string` | none | CSS selector of extra elements to block. | +| `replay.ignoreSelector` | `string` | none | CSS selector of elements whose input events to ignore. | +| `replay.checkoutEveryNms` | `number` | `60000` | Interval, in milliseconds, between full snapshots. It bounds the retained window. | +| `replay.canvas` | `boolean \| { fps?, quality?, imageType? }` | off | Opt-in canvas recording. Defaults when on: `fps` 2, `quality` 0.6, `imageType` `'image/webp'`. It records pixels without masking, so use it only for canvases without sensitive content. | + +Replay needs a DOM. In a DOM-less host, such as a server-side render pass, nothing is recorded whatever this option says. + +### Report dialog + +These options shape the dialog that `showReportDialog()` shows; see [Bug reporting](/sdk/javascript/manual/bug-reporting). + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `reportSummaryRequired` | `boolean` | `false` | The summary must be filled in before Send. | +| `reportDescriptionRequired` | `boolean` | `false` | The description must be filled in. | +| `reportEmailRequired` | `boolean` | `false` | The reporter's email must be filled in. | +| `reportLabelsEnabled` | `boolean` | `false` | Show the labels field. | +| `reportLabelsRequired` | `boolean` | `false` | At least one label is required. Only with `reportLabelsEnabled`. | +| `reportPrioritySelectorEnabled` | `boolean` | `false` | Show the severity picker. | + +## Node.js and Bun + +These options apply to `@bugsee/bugsee` on Node.js, to `@bugsee/bun`, and to the main process of Electron. Bun takes the same options as Node.js, with the exceptions noted. + +### Process and capture buffer + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `appRoot` | `string` | `process.cwd()` | Application root, used to turn stack-frame paths into relative ones. Pass `''` to keep absolute paths. | +| `deviceId` | `string` | none | Device identifier. The SDK never generates or stores one on a server. | +| `appIdentitySource` | `() => { version?, build? } \| undefined` | none | An extra place to look for the version and build, consulted after build-time constants and before the environment and `package.json`. | +| `unhandledRejections` | `'preserve' \| 'warn' \| 'none'` | `'preserve'` | `'preserve'` captures the rejection, then reproduces Node.js's own outcome (print and exit with code 1). `'warn'` captures and prints but keeps the process alive. `'none'` installs no listener. | +| `exitOnUncaught` | `boolean` | `true` | Flush the crash report, then exit with code 1 after an uncaught exception. Does not affect rejections. | +| `shutdownTimeoutMs` | `number` | `3000` | Time budget, in milliseconds, to flush the crash report before exiting. | +| `recover` | `boolean` | `true` | Store each report durably before upload and re-upload any left behind by a crashed or killed run on the next launch. Needs the on-disk store. | +| `capturedDataStore` | `'disk' \| 'memory'` | `'disk'` | Where the rolling capture buffer lives. `'memory'` gives up durable capture and crash recovery. | +| `dataDir` | `string` | `/bugsee/...` | Directory for on-disk data. Several processes can share one directory safely; each uses its own subdirectory. | +| `dataRootBase` | `string` | `os.tmpdir()` | Base for the default data directory. Ignored when `dataDir` is set. | +| `captureWriter` | `'inline' \| 'worker'` | `'inline'` | `'worker'` writes capture data from a worker thread, so a slow disk never blocks your code. | +| `captureDiskSpace` | `boolean` | `false` | Report free and total disk space of the data volume as system traces. | +| `diskProtection` | `boolean` | `true` | Below 50 MiB free the on-disk store stops persisting replay, log and network data; below 10 MiB it persists nothing. The in-memory window is kept either way. Only `false` opts out. | + +### Diagnostics + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `detectHangs` | `boolean` | `true` | Detect a blocked event loop and report an `AppHang`. See [Hangs](/sdk/javascript/issue-detection/hangs). | +| `hangFairMs` | `number` | `3000` | Block duration, in milliseconds, reported as `AppHang::Fair`. | +| `hangMediumMs` | `number` | `5000` | Block duration reported as `AppHang::Medium`. | +| `hangSevereMs` | `number` | `10000` | Block duration reported as `AppHang::Severe`. | +| `profiling` | `boolean` | `false` | Attach a rolling V8 CPU profile (`profile.json`) to reports. Costs some overhead. | +| `profilingSamplingIntervalMicros` | `number` | `1000` | CPU profiler sampling interval, in microseconds. | +| `captureLocalVariables` | `boolean \| object` | `false` | Capture the local variables in scope at a throw, onto the stack frames. Always off on Bun. | +| `captureSourceContext` | `boolean \| object` | `false` | Attach the source lines around each throwing application frame. It uploads your source code, so it is opt-in. | + +`captureLocalVariables` costs about 3% steady-state in internal benchmarks (approximate, not repeated for every release) because it enables the V8 debugger, and pausing on caught exceptions costs more on every throw. Variable names that look sensitive are redacted and values are truncated, but a variable can still hold personal data. Pass an object to tune it: + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `includeCaught` | `boolean` | `false` | Also capture at caught exceptions, not only uncaught ones. Costly in code that uses exceptions for control flow. | +| `maxFrames` | `number` | `5` | Frames to capture. | +| `maxVariables` | `number` | `20` | Variables per frame. | +| `maxValueLength` | `number` | `120` | Longest captured value, in characters. | +| `maxCaughtPerSecond` | `number` | `50` | Rate limit for caught exceptions. Uncaught exceptions are never limited. | + +`captureSourceContext` takes an object with these keys: + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `contextLines` | `number` | `5` | Lines before and after the throwing line. | +| `maxFrames` | `number` | `5` | Frames to attach source to. | +| `maxLineLength` | `number` | `200` | Longest line kept, in characters. | + +See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). + +### Incoming requests and trace propagation + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `instrumentIncomingRequests` | `boolean` | `true` | Instrument incoming requests on `node:http` servers and `Bun.serve`: a per-request context and an `http.server` transaction. Only `false` opts out; an invalid value is treated as off and reported. See [Backend overview](/sdk/javascript/backend/overview). | +| `propagateTrace` | `boolean` | `true` | Add the W3C `traceparent` header and a `bugsee` trace state to outgoing requests. Nothing is added unless the URL matches `tracePropagationTargets`. | +| `tracePropagationTargets` | `Array` | none | Which outgoing URLs may receive trace headers (substring or regular expression). List your own services only. | +| `traceResponse` | `{ traceresponse?, serverTiming?, timingAllowOrigin? }` | off | Add trace context to incoming responses so a browser frontend can adopt the backend's span. | + +## Electron + +`launchMain(appToken, options)` in the main process takes every Node.js option above, plus: + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `ipcMain` | Electron `ipcMain` | required | Used to receive capture from renderers and to control them. | +| `app` | Electron `app` | none | Reports `app.getVersion()` as the app version, process metrics, and renderer-gone events. | +| `powerMonitor` | Electron `powerMonitor` | none | Enables power and thermal events and traces. | +| `screen` | Electron `screen` | none | Enables display events and the `displays` trace. Pass it after the app is ready. | +| `BrowserWindow` | Electron `BrowserWindow` | none | Tracks windows that already exist. | +| `gpuInfoType` | `'basic' \| 'complete'` | `'basic'` | Detail level of the GPU information read from `app.getGPUInfo`. | +| `captureWindowEvents` | `boolean` | `true` | Window focus, show and hide events and renderer responsiveness. Needs `app`. | +| `crashReporter` | Electron `crashReporter` | none | Enables native crash collection. | +| `crashReporterExtra` | `Record` | none | Extra fields sent with native crashes. | +| `video` | `{ source, ... }` | off | Opt-in pixel video next to the default DOM replay. | + +`launchRenderer(appToken, options)` takes the browser options above. Replay is on and streams to the main process. See [Electron](/sdk/javascript/platforms/electron). + +## Edge and workers + +Cloudflare Workers, Vercel Edge and Web or Service Workers take the shared options above, with these changes: `maxDataSize` defaults to `10` and there are no options for disk, hangs or profiling. Edge runtimes buffer in memory and upload only when an incident happens. + +| Option | Applies to | Type | Default | Description | +| --- | --- | --- | --- | --- | +| `partitionCaptureByTenant` | Cloudflare, Vercel Edge | `boolean` | `true` on Cloudflare, `false` on Vercel Edge | Keep a separate capture buffer for each tenant so one isolate serving several tenants never mixes their data. | +| `maxTenantPartitions` | Cloudflare, Vercel Edge | `number` | `8` | Tenant buffers kept. The `maxDataSize` budget is divided across them. | +| `asyncLocalStorage` | Cloudflare, Vercel Edge | object | probed from `globalThis` | The async store for per-request context. Supply it where the runtime does not expose one. | +| `platformType` | Vercel Edge, Cloudflare, Web and Service Workers | string | Vercel Edge `'edge-light'`, Cloudflare `'workers'`; workers are detected (`'service-worker'` inside a Service Worker, else `'web-worker'`) | Runtime identity reported with a report. Set `'service-worker'` explicitly if detection fails. | +| `persist` | Web Workers, Service Workers | `boolean` | `true` for Service Workers, `false` for Web Workers | Keep report bundles in IndexedDB and re-upload any a stopped worker left behind. | +| `recover` | Web Workers, Service Workers | `boolean` | `true` | Re-upload a bundle left behind by an earlier activation. | + +See [Cloudflare](/sdk/javascript/platforms/cloudflare), [Vercel Edge](/sdk/javascript/platforms/vercel-edge) and [Web Workers](/sdk/javascript/platforms/web-workers). + +## Extension options + +`@bugsee/bugsee` adds performance monitoring and OpenTelemetry on top of the platform build, and these options on top of the platform options. The bare platform packages do not have them. + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `performanceMonitoring` | `boolean` | `true` | Master switch for web vitals and performance transactions. | +| `performanceSampleRate` | `number` | `1` | Fraction of transactions to keep, from 0 to 1. Errors are never sampled. | +| `performanceUploadMode` | `'batched' \| 'realtime'` | `'batched'` | Upload on an interval, or per transaction. | +| `performanceFlushIntervalMs` | `number` | `30000` | Interval for batched uploads, in milliseconds. | +| `pageName` | `string` | current path, or `pageload` | Name of the page-load transaction (browser). | +| `traceNavigations` | `boolean` | `true` | Open a `navigation` transaction for each single-page route change (browser). | +| `traceInteractions` | `boolean` | `true` | Open a `ui.interaction` transaction for slow user interactions (browser). | +| `propagateTrace` | `boolean` | browser `false`, server `true` | Add `traceparent` and trace state to outgoing requests. In the browser, same-origin requests propagate and other origins need `tracePropagationTargets`. | +| `tracePropagationTargets` | `Array` | none | URLs allowed to receive trace headers. | +| `tracePropagationOrigin` | `string` | `location.origin` | Browser: the origin treated as same-origin. | +| `appStartTimeMs` | `number` | process start time | Server: start time used for the startup transaction. | +| `otelExportUrl` | `string \| URL` | none | OTLP/HTTP JSON traces endpoint. When set, finished transactions are also exported there, and Bugsee still receives them. | +| `otelExportHeaders` | `Record` | none | Headers for the OTLP export, lowercase keys. | +| `otelExportResource` | `Record` | none | OTLP resource attributes. | +| `otelConsume` | `boolean` | `false` | Turn your OpenTelemetry spans into Bugsee transactions. | +| `onOtelSpanProcessor` | `(processor) => void` | none | Receives the span processor to register on your `TracerProvider`. | + +The performance and propagation options need `performanceMonitoring` on. See [Performance](/sdk/javascript/performance) and [OpenTelemetry](/sdk/javascript/opentelemetry). + +## Reading options back + +The client reports what is in effect: + +```ts +const bugsee = await launch('', { maxRecordingTime: 30 }); + +bugsee.getLaunchOptions(); // effective options, defaults applied +bugsee.getHostLaunchOptions(); // only the options you passed +``` + +Both return a plain object keyed by the canonical option identifier, `com.bugsee.option.*` (for example `com.bugsee.option.capture.network`), the names shared by the Bugsee SDKs on every platform. Option objects such as `replay` or `captureLocalVariables` appear as `true`. + +## Options kept by `relaunch()` + +`relaunch(options)` starts from defaults, as the mobile SDKs do: the options you pass replace the previous ones, and omitted options go back to their default. Identity and integration settings are kept from the previous launch: `endpoint`, `appId`, `appVersion`, `appBuild`, `appRoot`, `dataDir`, `onError` and `urlSanitizer`. The network, log and breadcrumb filters and the report handler are installed on the client, not passed as options, so they are not kept: install them again on the client that `relaunch()` returns. See [Lifecycle & status](/sdk/javascript/lifecycle#relaunch). + +## Related pages + +- [Quick start](/sdk/javascript/quick-start) — add the package, launch the SDK and send a first report. +- [Lifecycle & status](/sdk/javascript/lifecycle) — launch, stop, relaunch and events. +- [Privacy](/sdk/javascript/privacy/overview) — masking and redaction options. +- [Diagnostics](/sdk/javascript/issue-detection/diagnostics) — profiling, local variables and source context. +- [Packages](/sdk/javascript/packages) — which package takes which options. diff --git a/docs/sdk/javascript/events-and-traces.md b/docs/sdk/javascript/events-and-traces.md new file mode 100644 index 00000000..2bf8e76c --- /dev/null +++ b/docs/sdk/javascript/events-and-traces.md @@ -0,0 +1,102 @@ +--- +title: "Custom events & traces" +description: "Record your own events and traces on the report timeline with the Bugsee JavaScript SDK: event and trace, what the SDK records on its own, and the options that control system data." +sidebar_position: 23 +slug: "/sdk/javascript/events-and-traces" +--- + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +Events and traces are the two ways to put your own data on the report timeline: + +- An **event** is something that happened at a moment in time: `checkout_started`, `coupon_applied`. It has a name and optional parameters. +- A **trace** is a named value that changes over time: `cart_size`, `queue_length`. Each call adds one point to the curve. + +The examples use the client returned by `launch`, kept in a module of your own: + +```ts title="bugsee.ts" +import { launch } from '@bugsee/bugsee'; + +export const bugsee = await launch(''); +``` + +Import this module first in your entry file, before your app bootstraps, not lazily. Capture covers only what runs after `launch()`, and code that runs earlier is not recorded. + +## Custom events + +```ts +import { bugsee } from './bugsee'; + +bugsee.event('checkout_started'); +bugsee.event('coupon_applied', { code: 'SPRING', discountPercent: 15 }); +``` + +`event(name, params?)` takes a `string` name and an optional object of parameters. The SDK stamps the time of the call. Parameters travel with the report as JSON, so keep them to strings, numbers, booleans, arrays and plain objects. + +## Custom traces + +```ts +import { bugsee } from './bugsee'; + +bugsee.trace('cart_size', 3); +bugsee.trace('queue_length', 120); +bugsee.trace('current_plan', 'pro'); +``` + +`trace(name, value)` takes a `string` name and a value. Use a number for a value you want to see as a curve. + +## What these calls do not do + +- They do nothing after the SDK has been switched off for your app. +- There is no filter for events and traces. Whatever you pass is recorded, so do not put personal data or secrets in names or parameters. +- The SDK validates nothing here. A name or value that cannot be serialized as JSON can be lost. + +:::note +Events and traces you record are kept apart from the ones the SDK records itself. The SDK never writes into your event and trace streams, and you never overwrite its own. +::: + +## What the SDK records by itself + +Besides your own data, the SDK records **system events** and **system traces**. They appear on the same timeline. + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `captureSystemEvents` | `boolean` | `true` | Record system events, such as the process start and, in the browser, the page being hidden. | +| `captureSystemTraces` | `boolean` | `true` | Record system traces, such as memory use, in a browser also the sanitized page address, and on Node.js the process metrics. | + +```ts +import { launch } from '@bugsee/bugsee'; + +export const bugsee = await launch('', { + captureSystemEvents: true, + captureSystemTraces: false, +}); +``` + +A malformed value turns the option off and is reported through the `onError` launch option. For the options that tune individual browser traces, see [Configuration](/sdk/javascript/configuration). + +## Route and view + +`setRoute(route)` and `setView(view)` record the screen the user is on as system traces. Framework adapters call them for you on every navigation. Call them yourself when your app has its own router. + +```ts +import { bugsee } from './bugsee'; + +// Pass the route PATTERN, never the URL with real ids +bugsee.setRoute('/orders/:id'); + +// A name, or a name and the type of view +bugsee.setView({ name: 'OrderDetails', type: 'page' }); +bugsee.setView(null); // no view +``` + +`setRoute` expects a router pattern. The SDK strips any query and fragment, redacts an email address in a path segment, and clips the string at 1024 characters. A value that is empty or not a string is ignored. These traces are written where the platform records a page or screen: the browser, and an Electron renderer. On Node.js and the edge runtimes the call is accepted and writes nothing. + +## Related pages + +- [Breadcrumbs](/sdk/javascript/breadcrumbs) — a structured trail of steps. +- [User & session data](/sdk/javascript/user-session-data) — attach an identifier and attributes to every report. +- [Console logs](/sdk/javascript/logs) — text lines on the timeline. +- [Performance](/sdk/javascript/performance) — transactions, spans and web vitals. diff --git a/docs/sdk/javascript/faq.md b/docs/sdk/javascript/faq.md new file mode 100644 index 00000000..08dee75d --- /dev/null +++ b/docs/sdk/javascript/faq.md @@ -0,0 +1,140 @@ +--- +title: "FAQ" +description: "Practical questions and answers about the Bugsee JavaScript SDK (beta): runtimes, packages, tokens, privacy defaults, errors that are not reported and known beta behavior." +sidebar_position: 22 +slug: "/sdk/javascript/faq" +--- + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +**1. Which runtimes does the SDK support?** + +Browsers, Node.js 18 or later, and Bun 1.1.13 or later are the main targets. Electron, Cloudflare Workers, Vercel Edge, and Web and Service Workers are supported through their own packages. See [Overview](/sdk/javascript/overview#requirements). + +
+ +**2. Which package do I install?** + +For a browser app or a Node.js server, `@bugsee/bugsee`. For Bun, Electron, Cloudflare, Vercel Edge and workers, the package named for the runtime. Frameworks use their adapter package alone, which includes `@bugsee/bugsee`. The table in [Quick start](/sdk/javascript/quick-start#1-add-the-package) lists them all, and [Packages](/sdk/javascript/packages) explains the rest. + +
+ +**3. Should I install `@bugsee/browser`, `@bugsee/node` or `@bugsee/core`?** + +No. Those are the building blocks the umbrella and the other packages are made from. Their APIs can change without notice. Install `@bugsee/bugsee` or the package for your runtime. + +
+ +**4. Is there an SDK for React Native, or for web content inside a native app?** + +React Native has its own SDK; see the [React Native documentation](/sdk/react_native/overview). Web content shown in a native WebView is covered by the native Bugsee SDKs. + +
+ +**5. What do the npm `latest` and `beta` tags mean?** + +For now both point at the current beta, so the install commands in these docs need no tag. Add `@beta` yourself if you want to keep following betas once a stable release exists, and keep all `@bugsee/*` packages at the same version. See [Release notes](/sdk/javascript/release-notes). + +
+ +**6. `launch()` does not throw, but nothing is captured.** + +A missing, empty or non-string token returns a disabled client and reports one message through `onError` (or `console.warn` when you gave none). Check that the token reaches your code at runtime; an environment variable that is not set, or that your bundler does not expose to browser code, is the usual cause. See [Quick start](/sdk/javascript/quick-start#troubleshooting). + +
+ +**7. Why does `launch()` return a `Promise` in the browser but not on Node.js?** + +In the browser the launch is asynchronous, because part of the SDK (session replay) is loaded on demand. Servers, edge runtimes and workers return the client directly. Await the browser result only when you need the client right away; capture starts either way. See [Lifecycle & status](/sdk/javascript/lifecycle#launch). + +
+ +**8. I called `launch()` twice and my second options were ignored.** + +Bugsee is a per-process singleton. A second call returns the existing client and reports the repeat through `onError`. Use `relaunch(options)` to restart with new options; it starts from defaults, not from your previous options. See [Lifecycle & status](/sdk/javascript/lifecycle#relaunch). + +
+ +**9. What is captured by default, and is it safe for personal data?** + +Console logs, network requests (with request and response bodies), breadcrumbs, system traces and events, and in the browser a DOM replay and interactions. Replay masks all text and inputs and blocks media by default. Network URLs, headers and bodies pass through a built-in redaction (sensitive headers and keys, and secret-looking values). Redaction is a safety net, not a guarantee: review what your app sends, and use the filters. See [Privacy](/sdk/javascript/privacy/overview). + +
+ +**10. I set a network filter and sensitive data showed up.** + +A network filter you set with `setNetworkEventFilter` replaces the default redaction instead of adding to it. Compose your filter with the default one by calling `getDefaultNetworkSanitizer()` inside it. See [Privacy: Network](/sdk/javascript/privacy/network). + +
+ +**11. Breadcrumbs are on although the mobile SDKs default them to off.** + +Yes. In JavaScript, `captureBreadcrumbs` defaults to `true`, because UI interactions are a core signal on the web. Set `captureBreadcrumbs: false` to turn them off. See [Breadcrumbs](/sdk/javascript/breadcrumbs). + +
+ +**12. An error in my framework is not reported.** + +Many frameworks catch errors before they reach the global handler, so the SDK never sees them. Add the adapter for your framework: React needs its error boundary, Vue needs `installBugseeErrorHandler` in production, Angular needs `BugseeErrorHandler`, and backend frameworks need their adapter's error hook. On the backend, 4xx errors are skipped by default. See [Frameworks](/sdk/javascript/frameworks/react) and [Backend overview](/sdk/javascript/backend/overview). + +
+ +**13. My Node.js process exits after an uncaught exception. Is that the SDK?** + +The SDK flushes the crash report first, then exits with code 1, as Node.js would. That is `exitOnUncaught: true`, the default. Unhandled rejections follow `unhandledRejections`: the default `'preserve'` captures them and then reproduces Node.js's own outcome. See [Configuration](/sdk/javascript/configuration#process-and-capture-buffer). + +
+ +**14. A short script finishes before its report is uploaded.** + +Await `bugsee.flush()` or `bugsee.stop()` before exiting. A long-running server does not need to. See [Lifecycle & status](/sdk/javascript/lifecycle#flush-and-stop). + +
+ +**15. Where does the SDK write data on a server, and what if the filesystem is read-only or ephemeral?** + +By default on Node.js and Bun the SDK keeps its rolling capture buffer and report queue on disk under `/bugsee`, so a crash or kill still delivers its recording on the next launch. Set `dataDir` to move it. On a read-only or throwaway filesystem, set `capturedDataStore: 'memory'`, which gives up durable capture and recovery. See [Configuration](/sdk/javascript/configuration#process-and-capture-buffer). + +
+ +**16. Why is `captureLocalVariables` or `captureSourceContext` off?** + +Both are opt-in by design. Local variables cost steady overhead and can contain personal data, and source context uploads your source code. `captureLocalVariables` does not work on Bun at all. See [Diagnostics](/sdk/javascript/issue-detection/diagnostics). + +
+ +**17. My stack traces are minified.** + +Upload source maps for each release, with the same version and build you pass to `launch()`. The Vite and webpack plugins do it at build time; other build tools use `bugsee-cli`. Angular needs the CLI step. See [Symbolication](/sdk/javascript/symbolication/overview). + +
+ +**18. Reports show version `0.0.0`.** + +The SDK could not detect your app version. Pass `appVersion` to `launch()`; that works in every runtime. On Node.js and Bun the SDK also reads `BUGSEE_APP_VERSION` and the `package.json` version at run time. In a browser it uses, in this order, a constant that the Vite or webpack plugin bakes in at build time (or that you define yourself), then `bugsee:app-version` and `bugsee:app-build` meta tags. See [Quick start](/sdk/javascript/quick-start#app-version-and-build). + +
+ +**19. Does `RelaunchedAfterCrash` always mean a crash?** + +No. It is a hint based on evidence left on storage. It can report a crash that did not happen, and miss one that did. See [Lifecycle & status](/sdk/javascript/lifecycle#lifecycle-events). + +
+ +**20. `logException` seems to send fewer reports than I call it.** + +Identical errors are deduplicated, and `logException` is rate-limited to 100 reports per 60 seconds. Errors are not sampled; only performance transactions have a sample rate (`performanceSampleRate`). See [Crash & error reporting](/sdk/javascript/manual/crash-error-reporting). + +
+ +**21. Which bundlers are supported for source maps?** + +Vite and webpack have dedicated plugins and are the best exercised. Rollup, esbuild and Rspack use the shared plugin engine and are less exercised. Other tools can use `bugsee-cli` directly. See [Bundler plugins](/sdk/javascript/symbolication/bundler-plugins). + +
+ +**22. Is the SDK stable?** + +It is in beta. APIs, options and defaults can change between betas, and the internal packages carry no stability promise at all. Read the [release notes](/sdk/javascript/release-notes) before updating. diff --git a/docs/sdk/javascript/frameworks/angular.mdx b/docs/sdk/javascript/frameworks/angular.mdx new file mode 100644 index 00000000..8fa4f3b7 --- /dev/null +++ b/docs/sdk/javascript/frameworks/angular.mdx @@ -0,0 +1,164 @@ +--- +title: "Angular" +description: "Set up the Bugsee JavaScript SDK in an Angular app with @bugsee/angular: the ErrorHandler, Router route names, and uploading source maps with the CLI." +sidebar_position: 3 +slug: "/sdk/javascript/frameworks/angular" +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +`@bugsee/angular` adds Angular-specific error reporting to the [browser SDK](/sdk/javascript/platforms/browser): an `ErrorHandler` that reports uncaught errors, and route naming from the Angular Router. + +## Requirements + +- Angular 16 or newer: `@angular/core` and `@angular/router` are peer dependencies. +- An app token. Create a JavaScript application in Bugsee and choose **Angular** as its target; see [Create your app](/sdk/javascript/installation#create-your-app). + +## Install + +Install the adapter. It pulls in `@bugsee/bugsee` and re-exports it, so `launch()` comes from the adapter and you do not add `@bugsee/bugsee` yourself. + + + + +```bash +npm install @bugsee/angular +``` + + + + +```bash +pnpm add @bugsee/angular +``` + + + + +```bash +yarn add @bugsee/angular +``` + + + + +```bash +bun add @bugsee/angular +``` + + + + +## Set up + +Launch Bugsee as early as possible, at the top of your entry module. In the browser `launch()` returns a `Promise` of the client. Await it only if you need the client right away. + +```ts title="main.ts" +import { launch } from '@bugsee/angular'; + +launch(''); +``` + +Register the Bugsee error handler in place of Angular's default `ErrorHandler`: + +```ts title="app.config.ts" +import { ErrorHandler } from '@angular/core'; +import { BugseeErrorHandler } from '@bugsee/angular'; + +bootstrapApplication(AppComponent, { + providers: [{ provide: ErrorHandler, useClass: BugseeErrorHandler }], +}); +``` + +`BugseeErrorHandler` reports the error to Bugsee, then runs Angular's default handler so the console output stays. It unwraps Angular's own error wrapper where one exists, so the report shows the real error. + +To chain a handler of your own instead, build one with `createAngularErrorHandler`: + +```ts +import { ErrorHandler } from '@angular/core'; +import { createAngularErrorHandler } from '@bugsee/angular'; + +providers: [ + { + provide: ErrorHandler, + useFactory: () => createAngularErrorHandler({ delegate: myHandler }), + }, +]; +``` + +### Route names (Angular Router) + +Name the active navigation after the matched route pattern. Call `setRouteNameFromRouter(router)` on each `NavigationEnd` event: + +```ts +import { NavigationEnd, Router } from '@angular/router'; +import { setRouteNameFromRouter } from '@bugsee/angular'; +import { filter } from 'rxjs'; + +constructor(router: Router) { + router.events + .pipe(filter((event) => event instanceof NavigationEnd)) + .subscribe(() => setRouteNameFromRouter(router)); +} +``` + +## API + +`@bugsee/angular` installs `@bugsee/bugsee` for you and re-exports everything from it, so `launch`, the client types and the rest of the SDK API come from this one package. You do not install or import `@bugsee/bugsee` separately. + +| Export | Description | +| --- | --- | +| `BugseeErrorHandler` | `ErrorHandler` class that reports, then runs Angular's default handler. | +| `createAngularErrorHandler(options?)` | Builds an `ErrorHandler`-shaped object. The `delegate` option is the handler to run after reporting. | +| `reportAngularError(error, options?)` | Reports an error you caught yourself. | +| `setRouteNameFromRouter(router)` | Names the active navigation after the matched route. | +| `createBugseeRenderTracker()` | Records render timing for performance monitoring. | + +## Launch options + +`launch(appToken, options)` accepts all [browser options](/sdk/javascript/platforms/browser#browser-options). The most relevant: + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `captureLogs` | `boolean` | `true` | Capture console output. | +| `captureNetwork` | `boolean` | `true` | Capture network requests. | +| `maxRecordingTime` | `number` | `60` | Seconds of recording to keep. | +| `replay` | `boolean` or object | `true` | Session replay settings, or `false` to turn replay off. | +| `captureInteractions` | `boolean` | `true` | Capture user interactions. | + +## Source maps + +The Angular builder does not accept bundler plugins, so there is no plugin for it. Add the Bugsee CLI as a step after `ng build`: it injects debug IDs into the built files and uploads the source maps. + +```bash +ng build --source-map +export BUGSEE_APP_TOKEN= +bugsee-cli sourcemaps inject dist//browser +bugsee-cli debug-files upload dist//browser --type sourcemaps --version "$APP_VERSION" --build "$APP_BUILD" +``` + +Run `inject` before you deploy. If you turn on `"subresourceIntegrity": true`, `inject` refuses to run unless you pass `--allow-sri`; see [Manual source map upload](/sdk/javascript/symbolication/manual) for details. + +## Verify + +Throw from a click handler or a component: + +```ts +onClick() { + throw new Error('Bugsee test error'); +} +``` + +Trigger it. The error shows up in the Bugsee dashboard. + +## Related pages + +- [Browser](/sdk/javascript/platforms/browser) — launch options, persistence and replay +- [Manual source map upload](/sdk/javascript/symbolication/manual) — the CLI recipe for Angular +- [Symbolication](/sdk/javascript/symbolication/overview) — source maps and debug IDs +- [Privacy](/sdk/javascript/privacy/overview) — what replay masks diff --git a/docs/sdk/javascript/frameworks/astro.mdx b/docs/sdk/javascript/frameworks/astro.mdx new file mode 100644 index 00000000..19f6e5dd --- /dev/null +++ b/docs/sdk/javascript/frameworks/astro.mdx @@ -0,0 +1,132 @@ +--- +title: "Astro" +description: "Set up the Bugsee JavaScript SDK in an Astro app with the @bugsee/astro integration: browser launch on every page, server middleware, edge runtime and island hydration errors." +sidebar_position: 9 +slug: "/sdk/javascript/frameworks/astro" +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +`@bugsee/astro` is an Astro integration. It launches the browser client on every page and adds a server middleware that launches the server SDK, reports request errors and injects the trace. It is a single install: it bundles the browser, Node.js and Edge SDKs. + +## Requirements + +- Astro with the integration API (`integrations` in `astro.config.mjs`). +- Node.js 18 or newer for server code. +- An app token. Create a JavaScript application in Bugsee and choose **Astro** as its target; see [Create your app](/sdk/javascript/installation#create-your-app). + +## Install + + + + +```bash +npm install @bugsee/astro +``` + + + + +```bash +pnpm add @bugsee/astro +``` + + + + +```bash +yarn add @bugsee/astro +``` + + + + +```bash +bun add @bugsee/astro +``` + + + + +## Set up + +Add the integration to your Astro config. There is nothing else to wire. + +```js title="astro.config.mjs" +import { defineConfig } from 'astro/config'; +import { bugsee } from '@bugsee/astro'; + +export default defineConfig({ + integrations: [bugsee({ appToken: process.env.BUGSEE_TOKEN, runtime: 'node' })], +}); +``` + +Use `runtime: 'edge'` for Vercel or Cloudflare edge deployments. The default is the Node.js runtime. + +The token is inlined into the client script so the browser can launch. An application token is not a secret. + +## Options + +| Option | Type | Default | Description | +| --- | --- | --- | --- | +| `appToken` | `string` | required | Your Bugsee application token. | +| `runtime` | `'node'` \| `'edge'` | `'node'` | The server runtime. Use `'edge'` for Vercel or Cloudflare edge deployments. | +| `client` | object | `{}` | Extra browser launch options, for example `{ replay: false }` or `{ maxRecordingTime: 30 }`. | +| `server` | object | `{}` | Extra server launch options, for example `{ captureLocalVariables: true }`. | + +```js title="astro.config.mjs" +bugsee({ + appToken: process.env.BUGSEE_TOKEN, + client: { captureNetwork: true }, + server: { instrumentIncomingRequests: true }, +}); +``` + +`client` takes the [browser options](/sdk/javascript/platforms/browser#browser-options). `server` takes the [Node.js options](/sdk/javascript/platforms/node#node-options), or the [Vercel Edge options](/sdk/javascript/platforms/vercel-edge#options) with `runtime: 'edge'`. `client` and `server` are serialized into the generated code, so pass plain values, not functions. + +## Entry points + +| Entry | Description | +| --- | --- | +| `@bugsee/astro` | The integration: `bugsee` (also the default export). | +| `@bugsee/astro/client` | `registerClient(appToken, options?)`, `relaunch`. | +| `@bugsee/astro/server` | `registerServer(appToken, options?)` for Node.js. | +| `@bugsee/astro/edge` | `registerServerEdge`, `createEdgeMiddleware`. | +| `@bugsee/astro/middleware` | `createBugseeMiddleware(options?)` and the generated `onRequest`. | + +You normally use only the integration. + +## Island hydration errors + +Astro catches an island's hydration failure itself and re-dispatches it as a cancelable `astro:hydration-error` event, plus a `console.error`. Nothing is rethrown, so the page's error handlers never see it. The browser launch listens for that event and reports the error without cancelling the event, so Astro's own console output is unchanged. + +For component errors during rendering, also add the adapter for your island framework: [React](/sdk/javascript/frameworks/react), [Vue](/sdk/javascript/frameworks/vue), [Svelte](/sdk/javascript/frameworks/svelte) or [Solid](/sdk/javascript/frameworks/solid). + +## Notes + +- **Source maps.** Astro builds with Vite. See [Bundler plugins](/sdk/javascript/symbolication/bundler-plugins). +- **Backend context.** Each server request gets a context so logs and errors tie to it. See [Backend](/sdk/javascript/backend/overview). + +## Verify + +Throw from a server-rendered page: + +```html title="src/pages/test.astro" +--- +throw new Error('Bugsee test error'); +--- +``` + +Open `/test`. The error shows up in the Bugsee dashboard. + +## Related pages + +- [Browser](/sdk/javascript/platforms/browser) — client launch options +- [Node.js](/sdk/javascript/platforms/node) — server launch options +- [Vercel Edge](/sdk/javascript/platforms/vercel-edge) — the edge runtime build +- [Bundler plugins](/sdk/javascript/symbolication/bundler-plugins) — upload source maps from Vite diff --git a/docs/sdk/javascript/frameworks/component-names.mdx b/docs/sdk/javascript/frameworks/component-names.mdx new file mode 100644 index 00000000..44c0a045 --- /dev/null +++ b/docs/sdk/javascript/frameworks/component-names.mdx @@ -0,0 +1,84 @@ +--- +title: "Component names" +description: "Keep component names in the Bugsee JavaScript SDK's reports when minification mangles them: the Babel plugin for React, Preact and Solid, the Svelte preprocessor, and the Vue mixin." +sidebar_position: 10 +slug: "/sdk/javascript/frameworks/component-names" +--- + +:::warning[Beta] +This page documents the Bugsee JavaScript SDK, which is in beta (0.1.x) and can change between betas. +::: + +Minification renames your components, so a click or an error that happens inside `UserCard` can end up attributed to something like `t` or `e`. The component name plugins fix that at build time. They label the DOM elements a component renders with the component's name, in a `data-bugsee-component` attribute. Bugsee reads that attribute in the browser to attribute clicks and errors to the component, even in a minified build. + +The plugins are optional and have nothing to do with source maps. Without them, everything is still captured and your stack traces are still readable once you [upload source maps](/sdk/javascript/symbolication/overview). They only add the component name. + +| Framework | How | Package | +| --- | --- | --- | +| React, Preact, Solid | A Babel plugin with no options. Needs `@babel/core` 7. | @bugsee/babel-plugin-component-annotate | +| Svelte, SvelteKit | A Svelte preprocessor. Needs `svelte` 4 or newer. | @bugsee/svelte-plugin-component-annotate | +| Vue | A runtime mixin, not a build plugin. | Included in [`@bugsee/vue`](/sdk/javascript/frameworks/vue#component-names-in-minified-builds) | + +## React, Preact and Solid + +Install the plugin as a development dependency: + +```bash +npm install --save-dev @bugsee/babel-plugin-component-annotate +``` + +Add it to your Babel configuration: + +```js title="babel.config.cjs" +module.exports = { + plugins: [['@bugsee/babel-plugin-component-annotate']], +}; +``` + +The plugin adds `data-bugsee-component=""` to each host element, such as a `