Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: BrowserSession
description: "Track healthy Sessions in the Browser."
notSupported:
- javascript.cordova
- javascript.node
- javascript.aws-lambda
- javascript.azure-functions
- javascript.connect
- javascript.express
- javascript.fastify
- javascript.gcp-functions
- javascript.hapi
- javascript.koa
- javascript.nestjs
- javascript.deno
- javascript.cloudflare
- javascript.bun
---

<Alert level="info">

This integration only works inside a browser environment.

</Alert>

_Import name: `Sentry.browserSessionIntegration`_

Sentry's [Release Health](/product/releases/health/) feature allows you to track user adoption and your application's crash-free rate.
When the BrowserSession integration is enabled, it automatically creates a session each time a user loads your page or application. These sessions are used to track your release health. If an error is captured during an active session, the session will be flagged as faulty.
Read more about <PlatformLink to="/configuration/releases/#sessions">Sessions</PlatformLink>.

```JavaScript
Sentry.init({
integrations: [Sentry.browserSessionIntegration()],
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ The callback function receives two arguments:
- `urlPath`: The URL path of the incoming request, including the query string if available. For example: `/users?name=John`.
- `request`: An object of type `IncomingMessage` containing the incoming request. You can use this to filter on properties like the request method or headers.

### `trackIncomingRequestsAsSessions`

_Type: `boolean`_ (Defaults to `true`)

Determines whether the integration should create [Sessions](/product/releases/health/#sessions) for incoming requests to track the health and crash-free rate of your releases in Sentry.
Read more about [Release Health](/product/releases/health/).

### `instrumentation`

You can also pass some hooks through to the [underlying OpenTelemetry Instrumentation](https://www.npmjs.com/package/@opentelemetry/instrumentation-http):
Expand Down
44 changes: 28 additions & 16 deletions docs/platforms/javascript/common/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ Turns debug mode on or off. If debug is enabled SDK will attempt to print out us

Sets the release. Some SDKs will try to automatically configure a release out of the box but it's a better idea to manually set it to guarantee that the release is in sync with your deploy integrations or source map uploads. Release names are strings, but some formats are detected by Sentry and might be rendered differently. Learn more about how to send release data so Sentry can tell you about regressions between releases and identify the potential source in [the releases documentation](/product/releases/) or the <SandboxLink scenario="releases">sandbox</SandboxLink>.

<PlatformCategorySection supported={['server', 'serverless']}>
By default the SDK will try to read this value from the `SENTRY_RELEASE` environment variable.
<PlatformCategorySection supported={["server", "serverless"]}>
By default, the SDK will try to read this value from the `SENTRY_RELEASE`
environment variable.
</PlatformCategorySection>

<PlatformCategorySection supported={['browser']}>
By default the SDK will try to read this value from `window.SENTRY_RELEASE.id` if available.
<PlatformCategorySection supported={["browser"]}>
By default, the SDK will try to read this value from `window.SENTRY_RELEASE.id`
if available.
</PlatformCategorySection>

<PlatformSection supported={["javascript.electron"]}>
Expand Down Expand Up @@ -102,9 +104,10 @@ Grouping in Sentry is different for events with stack traces and without. As a r
<PlatformCategorySection supported={['server', 'serverless']}>
<ConfigKey name="server-name">

This option can be used to supply a "server name." When provided, the name of the server is sent along and persisted in the event. For many integrations, the server name actually corresponds to the device hostname, even in situations where the machine is not actually a server.
This option can be used to supply a "server name." When provided, the name of the server is sent along and persisted in the event. For many integrations, the server name actually corresponds to the device hostname, even in situations where the machine is not actually a server.

Most SDKs will attempt to auto-discover this value.

Most SDKs will attempt to auto-discover this value.
</ConfigKey>

</PlatformCategorySection>
Expand Down Expand Up @@ -141,6 +144,13 @@ Grouping in Sentry is different for events with stack traces and without. As a r

Defaults to `true`. When set to `true`, the SDK will send session events to Sentry. This is supported in all browser SDKs, emitting one session per pageload and page navigation to Sentry. In mobile SDKs, when the app goes to the background for longer than 30 seconds, sessions are ended.

<Alert title="Deprecation Notice">

{/* We don't use platform links here because we always have to link to node and browser here and doing a conditional just for that feels overkill. */}
Starting with SDK version 8.43.0 and up, the `autoSessionTracking` option has been deprecated. You can use the [BrowserSession integration](/platforms/javascript/configuration/integrations/browsersession/) in browser environments and the [Http integration](/platforms/javascript/guides/node/configuration/integrations/http/) (via the `trackIncomingRequestsAsSessions` option) in Node.js runtime.

</Alert>

</ConfigKey>

<ConfigKey name="auto-session-tracking" supported={["javascript.electron"]} >
Expand All @@ -155,7 +165,6 @@ Data to be set to the initial scope. Initial scope can be defined either as an o

Object:


```javascript
Sentry.init({
dsn: "___PUBLIC_DSN___",
Expand Down Expand Up @@ -316,17 +325,20 @@ Switches out the transport used to send events. How this works depends on the SD

Options used to configure the transport. This is an object with the following possible optional keys:

<PlatformCategorySection supported={['server', 'serverless']}>
- `headers`: An object containing headers to be sent with every request.
- `proxy`: A proxy used for outbound requests. Can be http or https.
- `caCerts`: A path or list of paths to a CA certificate, or a buffer of CA certificates.
- `httpModule`: A custom HTTP module to use for requests. Defaults to the the native `http` and `https` modules.
- `keepAlive`: Determines whether to keep the socket alive between requests. Defaults to `false`.
<PlatformCategorySection supported={["server", "serverless"]}>
- `headers`: An object containing headers to be sent with every request. -
`proxy`: A proxy used for outbound requests. Can be http or https. -
`caCerts`: A path or list of paths to a CA certificate, or a buffer of CA
certificates. - `httpModule`: A custom HTTP module to use for requests.
Defaults to the the native `http` and `https` modules. - `keepAlive`:
Determines whether to keep the socket alive between requests. Defaults to
`false`.
</PlatformCategorySection>

<PlatformCategorySection supported={['browser', 'desktop']}>
- `headers`: An object containing headers to be sent with every request. Used by the SDK's fetch and XHR transports.
- `fetchOptions`: An object containing options to be passed to the `fetch` call. Used by the SDK's fetch transport.
<PlatformCategorySection supported={["browser", "desktop"]}>
- `headers`: An object containing headers to be sent with every request. Used
by the SDK's fetch and XHR transports. - `fetchOptions`: An object containing
options to be passed to the `fetch` call. Used by the SDK's fetch transport.
</PlatformCategorySection>

</ConfigKey>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use the <PlatformLink
to="/configuration/integrations/browserwindowsession">BrowserWindowSession</PlatformLink>
integration in the renderer processes.

Unless `autoSessionTracking` is set to `false`, this integration will be automatically added.
{/* TODO(v9): When electron does a new major, update this since autoSessionTracking got removed */}

Unless `autoSessionTracking` is set to `false`, this integration will be automatically added.

```javascript
import * as Sentry from "@sentry/electron/main";
Expand All @@ -31,8 +32,6 @@ import * as Sentry from "@sentry/electron/main";

Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [
Sentry.mainProcessSessionIntegration({ sendOnCreate: true }),
],
integrations: [Sentry.mainProcessSessionIntegration({ sendOnCreate: true })],
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Due to the nature of `crashed` and `abnormal` exits, these sessions are finished

To receive data on user adoption, such as users crash free rate percentage, and the number of users that have adopted a specific release, set the user on the [`initialScope`](/platforms/javascript/configuration/options/#initial-scope) when initializing the SDK.

{/* TODO(v9): When electron does a new major, update this since autoSessionTracking got removed */}

To disable sending sessions, set the `autoSessionTracking` flag to `false`:

```javascript
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{/* TODO(v9): Update this for the new behaviour (sessions are persisted in sessionStorage or memory) */}

We create a session for every page load. For single-page applications, we will create a new session for every navigation change (History API).

We mark the session as:
Expand All @@ -14,3 +16,17 @@ Sentry.init({
autoSessionTracking: false, // default: true
});
```

{/* TODO(v9): Remove this notice? */}

<PlatformSection notSupported={["javacript.cordova", "javascript.capacitor", "javascript.electron"]}>

<Alert title="Deprecation Notice">

{/* We don't use platform links here because we always have to link to node and browser here and doing a conditional just for that feels overkill. */}

Starting with SDK version 8.43.0 and up, the `autoSessionTracking` option has been deprecated. You can use the [BrowserSession integration](/platforms/javascript/configuration/integrations/browsersession/) in browser environments and the [Http integration](/platforms/javascript/guides/node/configuration/integrations/http/) (via the `trackIncomingRequestsAsSessions` option) in Node.js runtime.

</Alert>

</PlatformSection>
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ Sentry.init({
autoSessionTracking: false, // default: true
});
```

{/* TODO(v9): Remove this notice? */}

<PlatformSection notSupported={["javacript.cordova", "javascript.capacitor", "javascript.electron"]}>

<Alert title="Deprecation Notice">

{/* We don't use platform links here because we always have to link to node and browser here and doing a conditional just for that feels overkill. */}

Starting with SDK version 8.43.0 and up, the `autoSessionTracking` option has been deprecated. You can use the [BrowserSession integration](/platforms/javascript/configuration/integrations/browsersession/) in browser environments and the [Http integration](/platforms/javascript/guides/node/configuration/integrations/http/) (via the `trackIncomingRequestsAsSessions` option) in Node.js runtime.

</Alert>

</PlatformSection>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Depending on whether an integration enhances the functionality of a particular r
| [`globalHandlersIntegration`](./globalhandlers) | ✓ | ✓ | | | |
| [`httpContextIntegration`](./httpcontext) | ✓ | | | | ✓ |
| [`browserProfilingIntegration`](./browserprofiling) | | | ✓ | | |
| [`browserSessionIntegration`](./browsersession) | ✓ | | | | ✓ |
| [`contextLinesIntegration`](./contextlines) | | ✓ | | | |
| [`httpClientIntegration`](./httpclient) | | ✓ | | | |
| [`moduleMetadataIntegration`](./modulemetadata) | | | | | ✓ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| [`inboundFiltersIntegration`](./inboundfilters) | ✓ | ✓ | | | |
| [`linkedErrorsIntegration`](./linkederrors) | ✓ | ✓ | | | |
| [`browserProfilingIntegration`](./browserprofiling) | | | ✓ | | |
| [`browserSessionIntegration`](./browsersession) | ✓ | | | | ✓ |
| [`browserTracingIntegration`](./browsertracing) | | | ✓ | | ✓ |
| [`captureConsoleIntegration`](./captureconsole) | | | | | ✓ |
| [`contextLinesIntegration`](./contextlines) | | ✓ | | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| [`inboundFiltersIntegration`](./inboundfilters) | ✓ | ✓ | | | |
| [`linkedErrorsIntegration`](./linkederrors) | ✓ | ✓ | | | |
| [`browserProfilingIntegration`](./browserprofiling) | | | ✓ | | |
| [`browserSessionIntegration`](./browsersession) | ✓ | | | | ✓ |
| [`browserTracingIntegration`](./browsertracing) | | | ✓ | | ✓ |
| [`captureConsoleIntegration`](./captureconsole) | | | | | ✓ |
| [`contextLinesIntegration`](./contextlines) | | ✓ | | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Depending on whether an integration enhances the functionality of a particular r
| [`globalHandlersIntegration`](./globalhandlers) | ✓ | ✓ | | | |
| [`httpContextIntegration`](./httpcontext) | ✓ | | | | ✓ |
| [`browserProfilingIntegration`](./browserprofiling) | | | ✓ | | |
| [`browserSessionIntegration`](./browsersession) | ✓ | | | | ✓ |
| [`contextLinesIntegration`](./contextlines) | | ✓ | | | |
| [`httpClientIntegration`](./httpclient) | | ✓ | | | |
| [`moduleMetadataIntegration`](./modulemetadata) | | | | | ✓ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Depending on whether an integration enhances the functionality of a particular r
| [`globalHandlersIntegration`](./globalhandlers) | ✓ | ✓ | | | |
| [`httpContextIntegration`](./httpcontext) | ✓ | | | | ✓ |
| [`browserProfilingIntegration`](./browserprofiling) | | | ✓ | | |
| [`browserSessionIntegration`](./browsersession) | ✓ | | | | ✓ |
| [`contextLinesIntegration`](./contextlines) | | ✓ | | | |
| [`httpClientIntegration`](./httpclient) | | ✓ | | | |
| [`moduleMetadataIntegration`](./modulemetadata) | | | | | ✓ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Depending on whether an integration enhances the functionality of a particular r
| [`globalHandlersIntegration`](./globalhandlers) | ✓ | ✓ | | | |
| [`httpContextIntegration`](./httpcontext) | ✓ | | | | ✓ |
| [`browserProfilingIntegration`](./browserprofiling) | | | ✓ | | |
| [`browserSessionIntegration`](./browsersession) | ✓ | | | | ✓ |
| [`contextLinesIntegration`](./contextlines) | | ✓ | | | |
| [`httpClientIntegration`](./httpclient) | | ✓ | | | |
| [`moduleMetadataIntegration`](./modulemetadata) | | | | | ✓ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Depending on whether an integration enhances the functionality of a particular r
| [`globalHandlersIntegration`](./globalhandlers) | ✓ | ✓ | | | |
| [`httpContextIntegration`](./httpcontext) | ✓ | | | | ✓ |
| [`browserProfilingIntegration`](./browserprofiling) | | | ✓ | | |
| [`browserSessionIntegration`](./browsersession) | ✓ | | | | ✓ |
| [`contextLinesIntegration`](./contextlines) | | ✓ | | | |
| [`httpClientIntegration`](./httpclient) | | ✓ | | | |
| [`moduleMetadataIntegration`](./modulemetadata) | | | | | ✓ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Depending on whether an integration enhances the functionality of a particular r
| [`globalHandlersIntegration`](./globalhandlers) | ✓ | ✓ | | | |
| [`httpContextIntegration`](./httpcontext) | ✓ | | | | ✓ |
| [`browserProfilingIntegration`](./browserprofiling) | | | ✓ | | |
| [`browserSessionIntegration`](./browsersession) | ✓ | | | | ✓ |
| [`contextLinesIntegration`](./contextlines) | | ✓ | | | |
| [`httpClientIntegration`](./httpclient) | | ✓ | | | |
| [`moduleMetadataIntegration`](./modulemetadata) | | | | | ✓ |
Expand Down
Loading
Loading