Skip to content

Commit e94bf2f

Browse files
author
Luca Forstner
committed
Add docs for browserSessionIntegration and trackIncomingRequestsAsSessions as alternative to autoSessionTracking in JS SDKs
1 parent c0fcbc6 commit e94bf2f

File tree

17 files changed

+123
-20
lines changed

17 files changed

+123
-20
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: BrowserSession
3+
description: "Track healthy Sessions in the Browser."
4+
notSupported:
5+
- javascript.cordova
6+
- javascript.node
7+
- javascript.aws-lambda
8+
- javascript.azure-functions
9+
- javascript.connect
10+
- javascript.express
11+
- javascript.fastify
12+
- javascript.gcp-functions
13+
- javascript.hapi
14+
- javascript.koa
15+
- javascript.nestjs
16+
- javascript.deno
17+
- javascript.cloudflare
18+
- javascript.bun
19+
---
20+
21+
<Alert level="info">
22+
23+
This integration only works inside a browser environment.
24+
25+
</Alert>
26+
27+
_Import name: `Sentry.browserSessionIntegration`_
28+
29+
Sentry's [Release Health](/product/releases/health/) feature allows you to track user adoption and your application's crash-free rate.
30+
31+
The BrowserSession integration will create a Session that is used to track the health of your release when the user loads your page or application.
32+
Sessions will be marked as faulty when an error is captured while a Session is active.
33+
Read more about <PlatformLink to="/configuration/releases/#sessions">Sessions</PlatformLink>.
34+
35+
```JavaScript
36+
Sentry.init({
37+
integrations: [Sentry.browserSessionIntegration()],
38+
});
39+
```

docs/platforms/javascript/common/configuration/integrations/http.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ The callback function receives two arguments:
7373
- `urlPath`: The URL path of the incoming request, including the query string if available. For example: `/users?name=John`.
7474
- `request`: An object of type `IncomingMessage` containing the incoming request. You can use this to filter on properties like the request method or headers.
7575

76+
### `trackIncomingRequestsAsSessions`
77+
78+
_Type: `boolean`_ (Defaults to `true`)
79+
80+
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.
81+
Read more about [Release Health](/product/releases/health/).
82+
7683
### `instrumentation`
7784

7885
You can also pass some hooks through to the [underlying OpenTelemetry Instrumentation](https://www.npmjs.com/package/@opentelemetry/instrumentation-http):

docs/platforms/javascript/common/configuration/options.mdx

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ Turns debug mode on or off. If debug is enabled SDK will attempt to print out us
4141

4242
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>.
4343

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

48-
<PlatformCategorySection supported={['browser']}>
49-
By default the SDK will try to read this value from `window.SENTRY_RELEASE.id` if available.
49+
<PlatformCategorySection supported={["browser"]}>
50+
By default the SDK will try to read this value from `window.SENTRY_RELEASE.id`
51+
if available.
5052
</PlatformCategorySection>
5153

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

105-
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.
107+
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.
108+
109+
Most SDKs will attempt to auto-discover this value.
106110

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

110113
</PlatformCategorySection>
@@ -141,6 +144,15 @@ Grouping in Sentry is different for events with stack traces and without. As a r
141144

142145
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.
143146

147+
<Alert title="Deprecation Notice">
148+
149+
{/* 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. */}
150+
151+
The `autoSessionTracking` option is deprecated from SDK version `8.43.0` onwards.
152+
Instead, use the [BrowserSession integration](/platforms/javascript/configuration/integrations/browsersession/) for the Browser and the [Http integration](/platforms/javascript/guides/node/configuration/integrations/http/) (via the `trackIncomingRequestsAsSessions` option) for the Node.js runtime.
153+
154+
</Alert>
155+
144156
</ConfigKey>
145157

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

156168
Object:
157169

158-
159170
```javascript
160171
Sentry.init({
161172
dsn: "___PUBLIC_DSN___",
@@ -316,17 +327,20 @@ Switches out the transport used to send events. How this works depends on the SD
316327

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

319-
<PlatformCategorySection supported={['server', 'serverless']}>
320-
- `headers`: An object containing headers to be sent with every request.
321-
- `proxy`: A proxy used for outbound requests. Can be http or https.
322-
- `caCerts`: A path or list of paths to a CA certificate, or a buffer of CA certificates.
323-
- `httpModule`: A custom HTTP module to use for requests. Defaults to the the native `http` and `https` modules.
324-
- `keepAlive`: Determines whether to keep the socket alive between requests. Defaults to `false`.
330+
<PlatformCategorySection supported={["server", "serverless"]}>
331+
- `headers`: An object containing headers to be sent with every request. -
332+
`proxy`: A proxy used for outbound requests. Can be http or https. -
333+
`caCerts`: A path or list of paths to a CA certificate, or a buffer of CA
334+
certificates. - `httpModule`: A custom HTTP module to use for requests.
335+
Defaults to the the native `http` and `https` modules. - `keepAlive`:
336+
Determines whether to keep the socket alive between requests. Defaults to
337+
`false`.
325338
</PlatformCategorySection>
326339

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

332346
</ConfigKey>

docs/platforms/javascript/guides/electron/configuration/integrations/mainprocesssession.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ use the <PlatformLink
1212
to="/configuration/integrations/browserwindowsession">BrowserWindowSession</PlatformLink>
1313
integration in the renderer processes.
1414

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

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

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

3233
Sentry.init({
3334
dsn: "___PUBLIC_DSN___",
34-
integrations: [
35-
Sentry.mainProcessSessionIntegration({ sendOnCreate: true }),
36-
],
35+
integrations: [Sentry.mainProcessSessionIntegration({ sendOnCreate: true })],
3736
});
3837
```

platform-includes/configuration/auto-session-tracking/javascript.electron.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Due to the nature of `crashed` and `abnormal` exits, these sessions are finished
1010

1111
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.
1212

13+
{/* TODO(v9): When electron does a new major, update this since autoSessionTracking got removed */}
14+
1315
To disable sending sessions, set the `autoSessionTracking` flag to `false`:
1416

1517
```javascript

platform-includes/configuration/auto-session-tracking/javascript.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{/* TODO(v9): Update this for the new behaviour (sessions are persisted in sessionStorage or memory) */}
2+
13
We create a session for every page load. For single-page applications, we will create a new session for every navigation change (History API).
24

35
We mark the session as:
@@ -14,3 +16,18 @@ Sentry.init({
1416
autoSessionTracking: false, // default: true
1517
});
1618
```
19+
20+
{/* TODO(v9): Remove this notice? */}
21+
22+
<PlatformSection notSupported={["javacript.cordova", "javascript.capacitor", "javascript.electron"]}>
23+
24+
<Alert title="Deprecation Notice">
25+
26+
{/* 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. */}
27+
28+
The `autoSessionTracking` option is deprecated from SDK version `8.43.0` onwards.
29+
Instead, use the [BrowserSession integration](/platforms/javascript/configuration/integrations/browsersession/) for the Browser and the [Http integration](/platforms/javascript/guides/node/configuration/integrations/http/) (via the `trackIncomingRequestsAsSessions` option) for the Node.js runtime.
30+
31+
</Alert>
32+
33+
</PlatformSection>

platform-includes/configuration/auto-session-tracking/javascript.node.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,18 @@ Sentry.init({
1414
autoSessionTracking: false, // default: true
1515
});
1616
```
17+
18+
{/* TODO(v9): Remove this notice? */}
19+
20+
<PlatformSection notSupported={["javacript.cordova", "javascript.capacitor", "javascript.electron"]}>
21+
22+
<Alert title="Deprecation Notice">
23+
24+
{/* 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. */}
25+
26+
The `autoSessionTracking` option is deprecated from SDK version `8.43.0` onwards.
27+
Instead, use the [BrowserSession integration](/platforms/javascript/configuration/integrations/browsersession/) for the Browser and the [Http integration](/platforms/javascript/guides/node/configuration/integrations/http/) (via the `trackIncomingRequestsAsSessions` option) for the Node.js runtime.
28+
29+
</Alert>
30+
31+
</PlatformSection>

platform-includes/configuration/integrations/javascript.astro.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Depending on whether an integration enhances the functionality of a particular r
3030
| [`globalHandlersIntegration`](./globalhandlers) ||| | | |
3131
| [`httpContextIntegration`](./httpcontext) || | | ||
3232
| [`browserProfilingIntegration`](./browserprofiling) | | || | |
33+
| [`browserSessionIntegration`](./browsersession) || | | ||
3334
| [`contextLinesIntegration`](./contextlines) | || | | |
3435
| [`httpClientIntegration`](./httpclient) | || | | |
3536
| [`moduleMetadataIntegration`](./modulemetadata) | | | | ||

platform-includes/configuration/integrations/javascript.gatsby.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
| [`inboundFiltersIntegration`](./inboundfilters) ||| | | |
1212
| [`linkedErrorsIntegration`](./linkederrors) ||| | | |
1313
| [`browserProfilingIntegration`](./browserprofiling) | | || | |
14+
| [`browserSessionIntegration`](./browsersession) || | | ||
1415
| [`browserTracingIntegration`](./browsertracing) | | || ||
1516
| [`captureConsoleIntegration`](./captureconsole) | | | | ||
1617
| [`contextLinesIntegration`](./contextlines) | || | | |

platform-includes/configuration/integrations/javascript.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
| [`inboundFiltersIntegration`](./inboundfilters) ||| | | |
1212
| [`linkedErrorsIntegration`](./linkederrors) ||| | | |
1313
| [`browserProfilingIntegration`](./browserprofiling) | | || | |
14+
| [`browserSessionIntegration`](./browsersession) || | | ||
1415
| [`browserTracingIntegration`](./browsertracing) | | || ||
1516
| [`captureConsoleIntegration`](./captureconsole) | | | | ||
1617
| [`contextLinesIntegration`](./contextlines) | || | | |

0 commit comments

Comments
 (0)