Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Deprecate autoSessionTracking #14640

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/migration/draft-v9-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Is this last part about trackIncomingRequestsAsSessions specific to server environments?


## `@sentry/utils`

- **The `@sentry/utils` package has been deprecated. Import everything from `@sentry/core` instead.**
Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function getDefaultIntegrations(options: Options): Integration[] {
httpContextIntegration(),
];

// eslint-disable-next-line deprecation/deprecation
if (options.autoSessionTracking !== false) {
integrations.push(browserSessionIntegration());
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/server-runtime-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 =
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/types-hoist/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp

/**
* A flag enabling Sessions Tracking feature.
* By default, Sessions Tracking is enabled.
* By default, Session Tracking is enabled.
*
* @deprecated Setting 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`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Is this last part about trackIncomingRequestsAsSessions specific to server environments?

*/
autoSessionTracking?: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
});

const client = getClient<NodeClient>();
// eslint-disable-next-line deprecation/deprecation
if (client && client.getOptions().autoSessionTracking) {
// eslint-disable-next-line deprecation/deprecation
isolationScope.setRequestSession({ status: 'ok' });
Expand Down
2 changes: 2 additions & 0 deletions packages/node/src/integrations/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

if (
client &&
// eslint-disable-next-line deprecation/deprecation
client.getOptions().autoSessionTracking !== false &&
options.trackIncomingRequestsAsSessions !== false
) {
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/integrations/tracing/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export function expressErrorHandler(options?: ExpressHandlerOptions): ExpressMid

if (shouldHandleError(error)) {
const client = getClient<NodeClient>();
// 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
Expand Down
8 changes: 6 additions & 2 deletions packages/node/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -315,6 +318,7 @@ function updateScopeFromEnvVariables(): void {
*/
function startSessionTracking(): void {
const client = getClient<NodeClient>();
// eslint-disable-next-line deprecation/deprecation
if (client && client.getOptions().autoSessionTracking) {
client.initSessionFlusher();
}
Expand Down
3 changes: 3 additions & 0 deletions packages/vercel-edge/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ 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;
}
}

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;
}

Expand Down
Loading