From 8f503c8b76ce0fd2075bd50f8e99f548d157ff5b Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Tue, 10 Dec 2024 12:36:36 +0000 Subject: [PATCH 1/3] feat: Deprecate `autoSessionTracking` --- docs/migration/draft-v9-migration-guide.md | 5 +++++ packages/core/src/server-runtime-client.ts | 2 ++ packages/core/src/types-hoist/options.ts | 6 +++++- .../src/integrations/http/SentryHttpInstrumentation.ts | 1 + packages/node/src/integrations/http/index.ts | 2 ++ packages/node/src/integrations/tracing/express.ts | 1 + packages/node/src/sdk/index.ts | 8 ++++++-- packages/vercel-edge/src/sdk.ts | 3 +++ 8 files changed, 25 insertions(+), 3 deletions(-) diff --git a/docs/migration/draft-v9-migration-guide.md b/docs/migration/draft-v9-migration-guide.md index d3b31b4f2570..6f19f9e40337 100644 --- a/docs/migration/draft-v9-migration-guide.md +++ b/docs/migration/draft-v9-migration-guide.md @@ -19,6 +19,11 @@ 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. 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. +- **The `autoSessionTracking` option is deprecated.** + + 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. + To disable session tracking, it is recommended unset `autoSessionTracking` and to remove the `browserSessionIntegration` in browser environments, or configure the `httpIntegration` with the `trackIncomingRequestsAsSessions` option set to `false`. + ## `@sentry/utils` - **The `@sentry/utils` package has been deprecated. Import everything from `@sentry/core` instead.** diff --git a/packages/core/src/server-runtime-client.ts b/packages/core/src/server-runtime-client.ts index bc9489406282..c683ad0d2d54 100644 --- a/packages/core/src/server-runtime-client.ts +++ b/packages/core/src/server-runtime-client.ts @@ -84,6 +84,7 @@ export class ServerRuntimeClient< // The expectation is that session aggregates are only sent when `autoSessionTracking` is enabled. // 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. // TODO(v9): This should move into the httpIntegration. + // eslint-disable-next-line deprecation/deprecation if (this._options.autoSessionTracking && this._sessionFlusher) { // eslint-disable-next-line deprecation/deprecation const requestSession = getIsolationScope().getRequestSession(); @@ -106,6 +107,7 @@ export class ServerRuntimeClient< // The expectation is that session aggregates are only sent when `autoSessionTracking` is enabled. // 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. // TODO(v9): This should move into the httpIntegration. + // eslint-disable-next-line deprecation/deprecation if (this._options.autoSessionTracking && this._sessionFlusher) { const eventType = event.type || 'exception'; const isException = diff --git a/packages/core/src/types-hoist/options.ts b/packages/core/src/types-hoist/options.ts index 5179c1fdb70e..a6b8fa170ba1 100644 --- a/packages/core/src/types-hoist/options.ts +++ b/packages/core/src/types-hoist/options.ts @@ -26,7 +26,11 @@ export interface ClientOptions(); + // eslint-disable-next-line deprecation/deprecation if (client && client.getOptions().autoSessionTracking) { // eslint-disable-next-line deprecation/deprecation isolationScope.setRequestSession({ status: 'ok' }); diff --git a/packages/node/src/integrations/http/index.ts b/packages/node/src/integrations/http/index.ts index 10f0583b5ac6..c976bb4da2a1 100644 --- a/packages/node/src/integrations/http/index.ts +++ b/packages/node/src/integrations/http/index.ts @@ -38,6 +38,7 @@ interface HttpOptions { * * Note: If `autoSessionTracking` is set to `false` in `Sentry.init()` or the Client owning this integration, this option will be ignored. */ + // TODO(v9): Remove the note above. trackIncomingRequestsAsSessions?: boolean; /** @@ -218,6 +219,7 @@ function getConfigWithDefaults(options: Partial = {}): HttpInstrume if ( client && + // eslint-disable-next-line deprecation/deprecation client.getOptions().autoSessionTracking !== false && options.trackIncomingRequestsAsSessions !== false ) { diff --git a/packages/node/src/integrations/tracing/express.ts b/packages/node/src/integrations/tracing/express.ts index bcb668d52f80..e6cdcf514b2c 100644 --- a/packages/node/src/integrations/tracing/express.ts +++ b/packages/node/src/integrations/tracing/express.ts @@ -122,6 +122,7 @@ export function expressErrorHandler(options?: ExpressHandlerOptions): ExpressMid if (shouldHandleError(error)) { const client = getClient(); + // eslint-disable-next-line deprecation/deprecation if (client && client.getOptions().autoSessionTracking) { // Check if the `SessionFlusher` is instantiated on the client to go into this branch that marks the // `requestSession.status` as `Crashed`, and this check is necessary because the `SessionFlusher` is only diff --git a/packages/node/src/sdk/index.ts b/packages/node/src/sdk/index.ts index 8cc3b5ff8609..2ce75908168d 100644 --- a/packages/node/src/sdk/index.ts +++ b/packages/node/src/sdk/index.ts @@ -157,6 +157,7 @@ function _init( logger.log(`Running in ${isCjs() ? 'CommonJS' : 'ESM'} mode.`); // TODO(V9): Remove this code since all of the logic should be in an integration + // eslint-disable-next-line deprecation/deprecation if (options.autoSessionTracking) { startSessionTracking(); } @@ -218,9 +219,11 @@ function getClientOptions( const autoSessionTracking = typeof release !== 'string' ? false - : options.autoSessionTracking === undefined + : // eslint-disable-next-line deprecation/deprecation + options.autoSessionTracking === undefined ? true - : options.autoSessionTracking; + : // eslint-disable-next-line deprecation/deprecation + options.autoSessionTracking; if (options.spotlight == null) { const spotlightEnv = envToBool(process.env.SENTRY_SPOTLIGHT, { strict: true }); @@ -315,6 +318,7 @@ function updateScopeFromEnvVariables(): void { */ function startSessionTracking(): void { const client = getClient(); + // eslint-disable-next-line deprecation/deprecation if (client && client.getOptions().autoSessionTracking) { client.initSessionFlusher(); } diff --git a/packages/vercel-edge/src/sdk.ts b/packages/vercel-edge/src/sdk.ts index 6fc0e6196de6..78f1f49ba092 100644 --- a/packages/vercel-edge/src/sdk.ts +++ b/packages/vercel-edge/src/sdk.ts @@ -87,6 +87,7 @@ export function init(options: VercelEdgeOptions = {}): Client | undefined { options.release = detectedRelease; } else { // If release is not provided, then we should disable autoSessionTracking + // eslint-disable-next-line deprecation/deprecation options.autoSessionTracking = false; } } @@ -94,7 +95,9 @@ export function init(options: VercelEdgeOptions = {}): Client | undefined { options.environment = options.environment || process.env.SENTRY_ENVIRONMENT || getVercelEnv(false) || process.env.NODE_ENV; + // eslint-disable-next-line deprecation/deprecation if (options.autoSessionTracking === undefined && options.dsn !== undefined) { + // eslint-disable-next-line deprecation/deprecation options.autoSessionTracking = true; } From c7ea053c5d299c6837551af2334f3e46d0900d21 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Tue, 10 Dec 2024 13:53:07 +0000 Subject: [PATCH 2/3] lint --- packages/browser/src/sdk.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/browser/src/sdk.ts b/packages/browser/src/sdk.ts index caddc31bc167..425212015455 100644 --- a/packages/browser/src/sdk.ts +++ b/packages/browser/src/sdk.ts @@ -44,6 +44,7 @@ export function getDefaultIntegrations(options: Options): Integration[] { httpContextIntegration(), ]; + // eslint-disable-next-line deprecation/deprecation if (options.autoSessionTracking !== false) { integrations.push(browserSessionIntegration()); } From 0846471490a32a14ecbe5dba851e07224d5b244e Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 11 Dec 2024 11:34:07 +0000 Subject: [PATCH 3/3] review --- docs/migration/draft-v9-migration-guide.md | 2 +- packages/angular/src/sdk.ts | 1 + packages/core/src/types-hoist/options.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/migration/draft-v9-migration-guide.md b/docs/migration/draft-v9-migration-guide.md index 6f19f9e40337..acf268c81ef4 100644 --- a/docs/migration/draft-v9-migration-guide.md +++ b/docs/migration/draft-v9-migration-guide.md @@ -22,7 +22,7 @@ - **The `autoSessionTracking` option is deprecated.** 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. - To disable session tracking, it is recommended unset `autoSessionTracking` and to remove the `browserSessionIntegration` in browser environments, or configure the `httpIntegration` with the `trackIncomingRequestsAsSessions` option set to `false`. + 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`. ## `@sentry/utils` diff --git a/packages/angular/src/sdk.ts b/packages/angular/src/sdk.ts index 5a9de0bf9fb4..5bfb6882851b 100755 --- a/packages/angular/src/sdk.ts +++ b/packages/angular/src/sdk.ts @@ -42,6 +42,7 @@ export function getDefaultIntegrations(options: BrowserOptions = {}): Integratio httpContextIntegration(), ]; + // eslint-disable-next-line deprecation/deprecation if (options.autoSessionTracking !== false) { integrations.push(browserSessionIntegration()); } diff --git a/packages/core/src/types-hoist/options.ts b/packages/core/src/types-hoist/options.ts index a6b8fa170ba1..38748df82fd5 100644 --- a/packages/core/src/types-hoist/options.ts +++ b/packages/core/src/types-hoist/options.ts @@ -30,7 +30,7 @@ export interface ClientOptions