Skip to content

Commit 72239ee

Browse files
authored
Merge pull request #14640 from getsentry/lforst-deprecate-auto-session-tracking
2 parents 4ba5ae7 + 0846471 commit 72239ee

File tree

10 files changed

+27
-3
lines changed

10 files changed

+27
-3
lines changed

docs/migration/draft-v9-migration-guide.md

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
In v9, we will streamline this behavior so that passing `undefined` will result in tracing being disabled, the same as not passing the option at all.
2020
If you are relying on `undefined` being passed in and having tracing enabled because of this, you should update your config to set e.g. `tracesSampleRate: 0` instead, which will also enable tracing in v9.
2121

22+
- **The `autoSessionTracking` option is deprecated.**
23+
24+
To enable session tracking, it is recommended to unset `autoSessionTracking` and ensure that either, in browser environments the `browserSessionIntegration` is added, or in server environments the `httpIntegration` is added.
25+
To disable session tracking, it is recommended unset `autoSessionTracking` and to remove the `browserSessionIntegration` in browser environments, or in server environments configure the `httpIntegration` with the `trackIncomingRequestsAsSessions` option set to `false`.
26+
2227
## `@sentry/utils`
2328

2429
- **The `@sentry/utils` package has been deprecated. Import everything from `@sentry/core` instead.**

packages/angular/src/sdk.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function getDefaultIntegrations(options: BrowserOptions = {}): Integratio
4242
httpContextIntegration(),
4343
];
4444

45+
// eslint-disable-next-line deprecation/deprecation
4546
if (options.autoSessionTracking !== false) {
4647
integrations.push(browserSessionIntegration());
4748
}

packages/browser/src/sdk.ts

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export function getDefaultIntegrations(options: Options): Integration[] {
4444
httpContextIntegration(),
4545
];
4646

47+
// eslint-disable-next-line deprecation/deprecation
4748
if (options.autoSessionTracking !== false) {
4849
integrations.push(browserSessionIntegration());
4950
}

packages/core/src/server-runtime-client.ts

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class ServerRuntimeClient<
8484
// The expectation is that session aggregates are only sent when `autoSessionTracking` is enabled.
8585
// TODO(v9): Our goal in the future is to not have the `autoSessionTracking` option and instead rely on integrations doing the creation and sending of sessions. We will not have a central kill-switch for sessions.
8686
// TODO(v9): This should move into the httpIntegration.
87+
// eslint-disable-next-line deprecation/deprecation
8788
if (this._options.autoSessionTracking && this._sessionFlusher) {
8889
// eslint-disable-next-line deprecation/deprecation
8990
const requestSession = getIsolationScope().getRequestSession();
@@ -106,6 +107,7 @@ export class ServerRuntimeClient<
106107
// The expectation is that session aggregates are only sent when `autoSessionTracking` is enabled.
107108
// TODO(v9): Our goal in the future is to not have the `autoSessionTracking` option and instead rely on integrations doing the creation and sending of sessions. We will not have a central kill-switch for sessions.
108109
// TODO(v9): This should move into the httpIntegration.
110+
// eslint-disable-next-line deprecation/deprecation
109111
if (this._options.autoSessionTracking && this._sessionFlusher) {
110112
const eventType = event.type || 'exception';
111113
const isException =

packages/core/src/types-hoist/options.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
2626

2727
/**
2828
* A flag enabling Sessions Tracking feature.
29-
* By default, Sessions Tracking is enabled.
29+
* By default, Session Tracking is enabled.
30+
*
31+
* @deprecated Setting the `autoSessionTracking` option is deprecated.
32+
* To enable session tracking, it is recommended to unset `autoSessionTracking` and ensure that either, in browser environments the `browserSessionIntegration` is added, or in server environments the `httpIntegration` is added.
33+
* To disable session tracking, it is recommended unset `autoSessionTracking` and to remove the `browserSessionIntegration` in browser environments, or in server environments configure the `httpIntegration` with the `trackIncomingRequestsAsSessions` option set to `false`.
3034
*/
3135
autoSessionTracking?: boolean;
3236

packages/node/src/integrations/http/SentryHttpInstrumentation.ts

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
147147
});
148148

149149
const client = getClient<NodeClient>();
150+
// eslint-disable-next-line deprecation/deprecation
150151
if (client && client.getOptions().autoSessionTracking) {
151152
// eslint-disable-next-line deprecation/deprecation
152153
isolationScope.setRequestSession({ status: 'ok' });

packages/node/src/integrations/http/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface HttpOptions {
3838
*
3939
* Note: If `autoSessionTracking` is set to `false` in `Sentry.init()` or the Client owning this integration, this option will be ignored.
4040
*/
41+
// TODO(v9): Remove the note above.
4142
trackIncomingRequestsAsSessions?: boolean;
4243

4344
/**
@@ -218,6 +219,7 @@ function getConfigWithDefaults(options: Partial<HttpOptions> = {}): HttpInstrume
218219

219220
if (
220221
client &&
222+
// eslint-disable-next-line deprecation/deprecation
221223
client.getOptions().autoSessionTracking !== false &&
222224
options.trackIncomingRequestsAsSessions !== false
223225
) {

packages/node/src/integrations/tracing/express.ts

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export function expressErrorHandler(options?: ExpressHandlerOptions): ExpressMid
122122

123123
if (shouldHandleError(error)) {
124124
const client = getClient<NodeClient>();
125+
// eslint-disable-next-line deprecation/deprecation
125126
if (client && client.getOptions().autoSessionTracking) {
126127
// Check if the `SessionFlusher` is instantiated on the client to go into this branch that marks the
127128
// `requestSession.status` as `Crashed`, and this check is necessary because the `SessionFlusher` is only

packages/node/src/sdk/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ function _init(
157157
logger.log(`Running in ${isCjs() ? 'CommonJS' : 'ESM'} mode.`);
158158

159159
// TODO(V9): Remove this code since all of the logic should be in an integration
160+
// eslint-disable-next-line deprecation/deprecation
160161
if (options.autoSessionTracking) {
161162
startSessionTracking();
162163
}
@@ -218,9 +219,11 @@ function getClientOptions(
218219
const autoSessionTracking =
219220
typeof release !== 'string'
220221
? false
221-
: options.autoSessionTracking === undefined
222+
: // eslint-disable-next-line deprecation/deprecation
223+
options.autoSessionTracking === undefined
222224
? true
223-
: options.autoSessionTracking;
225+
: // eslint-disable-next-line deprecation/deprecation
226+
options.autoSessionTracking;
224227

225228
if (options.spotlight == null) {
226229
const spotlightEnv = envToBool(process.env.SENTRY_SPOTLIGHT, { strict: true });
@@ -315,6 +318,7 @@ function updateScopeFromEnvVariables(): void {
315318
*/
316319
function startSessionTracking(): void {
317320
const client = getClient<NodeClient>();
321+
// eslint-disable-next-line deprecation/deprecation
318322
if (client && client.getOptions().autoSessionTracking) {
319323
client.initSessionFlusher();
320324
}

packages/vercel-edge/src/sdk.ts

+3
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,17 @@ export function init(options: VercelEdgeOptions = {}): Client | undefined {
8787
options.release = detectedRelease;
8888
} else {
8989
// If release is not provided, then we should disable autoSessionTracking
90+
// eslint-disable-next-line deprecation/deprecation
9091
options.autoSessionTracking = false;
9192
}
9293
}
9394

9495
options.environment =
9596
options.environment || process.env.SENTRY_ENVIRONMENT || getVercelEnv(false) || process.env.NODE_ENV;
9697

98+
// eslint-disable-next-line deprecation/deprecation
9799
if (options.autoSessionTracking === undefined && options.dsn !== undefined) {
100+
// eslint-disable-next-line deprecation/deprecation
98101
options.autoSessionTracking = true;
99102
}
100103

0 commit comments

Comments
 (0)