From 3442ff71b09897363b8d41b78ea34798b328ef30 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 4 Dec 2024 15:12:33 +0000 Subject: [PATCH] feat(core): Deprecate APIs around `RequestSession`s --- .../suites/sessions/server.ts | 1 + docs/migration/draft-v9-migration-guide.md | 7 +++++ packages/core/src/index.ts | 1 + packages/core/src/scope.ts | 6 +++- packages/core/src/server-runtime-client.ts | 30 ++++++++++++++----- packages/core/src/sessionflusher.ts | 7 ++++- packages/core/src/types-hoist/index.ts | 3 ++ packages/core/src/types-hoist/scope.ts | 7 +++++ packages/core/src/types-hoist/session.ts | 11 +++++++ packages/core/test/lib/scope.test.ts | 9 ++++++ packages/core/test/lib/sessionflusher.test.ts | 7 +++++ .../http/SentryHttpInstrumentation.ts | 1 + .../node/src/integrations/tracing/express.ts | 1 + packages/node/src/sdk/index.ts | 1 + .../node/test/integrations/express.test.ts | 7 +++++ packages/node/test/sdk/client.test.ts | 22 ++++++++++++++ packages/types/src/index.ts | 3 ++ 17 files changed, 114 insertions(+), 10 deletions(-) diff --git a/dev-packages/node-integration-tests/suites/sessions/server.ts b/dev-packages/node-integration-tests/suites/sessions/server.ts index 2415140b6140..62b154accd45 100644 --- a/dev-packages/node-integration-tests/suites/sessions/server.ts +++ b/dev-packages/node-integration-tests/suites/sessions/server.ts @@ -13,6 +13,7 @@ import express from 'express'; const app = express(); +// eslint-disable-next-line deprecation/deprecation const flusher = (Sentry.getClient() as Sentry.NodeClient)['_sessionFlusher'] as SessionFlusher; // Flush after 2 seconds (to avoid waiting for the default 60s) diff --git a/docs/migration/draft-v9-migration-guide.md b/docs/migration/draft-v9-migration-guide.md index 684fd40ab894..e66bca5376f8 100644 --- a/docs/migration/draft-v9-migration-guide.md +++ b/docs/migration/draft-v9-migration-guide.md @@ -47,6 +47,10 @@ - Deprecated `addTracingHeadersToFetchRequest` method - this was only meant for internal use and is not needed anymore. - Deprecated `generatePropagationContext()` in favor of using `generateTraceId()` directly. - Deprecated `spanId` field on `propagationContext` - this field will be removed in v9, and should neither be read or set anymore. +- Deprecated `RequestSession` type. No replacements. +- Deprecated `RequestSessionStatus` type. No replacements. +- Deprecated `SessionFlusherLike` type. No replacements. +- Deprecated `SessionFlusher`. No replacements. ## `@sentry/nestjs` @@ -69,6 +73,9 @@ - **The `@sentry/types` package has been deprecated. Import everything from `@sentry/core` instead.** - Deprecated `Request` in favor of `RequestEventData`. +- Deprecated `RequestSession`. No replacements. +- Deprecated `RequestSessionStatus`. No replacements. +- Deprecated `SessionFlusherLike`. No replacements. ## `@sentry/nuxt` diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 751279cde693..1fa67beebd5d 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -47,6 +47,7 @@ export { export { setAsyncContextStrategy } from './asyncContext'; export { getMainCarrier } from './carrier'; export { makeSession, closeSession, updateSession } from './session'; +// eslint-disable-next-line deprecation/deprecation export { SessionFlusher } from './sessionflusher'; export { Scope } from './scope'; export { notifyEventProcessors } from './eventProcessors'; diff --git a/packages/core/src/scope.ts b/packages/core/src/scope.ts index 656ada3d6355..455f0b78b309 100644 --- a/packages/core/src/scope.ts +++ b/packages/core/src/scope.ts @@ -94,6 +94,7 @@ class ScopeClass implements ScopeInterface { protected _session?: Session; /** Request Mode Session Status */ + // eslint-disable-next-line deprecation/deprecation protected _requestSession?: RequestSession; /** The client on this scope */ @@ -222,6 +223,7 @@ class ScopeClass implements ScopeInterface { /** * @inheritDoc */ + // eslint-disable-next-line deprecation/deprecation public getRequestSession(): RequestSession | undefined { return this._requestSession; } @@ -229,6 +231,7 @@ class ScopeClass implements ScopeInterface { /** * @inheritDoc */ + // eslint-disable-next-line deprecation/deprecation public setRequestSession(requestSession?: RequestSession): this { this._requestSession = requestSession; return this; @@ -350,7 +353,8 @@ class ScopeClass implements ScopeInterface { const [scopeInstance, requestSession] = scopeToMerge instanceof Scope - ? [scopeToMerge.getScopeData(), scopeToMerge.getRequestSession()] + ? // eslint-disable-next-line deprecation/deprecation + [scopeToMerge.getScopeData(), scopeToMerge.getRequestSession()] : isPlainObject(scopeToMerge) ? [captureContext as ScopeContext, (captureContext as ScopeContext).requestSession] : []; diff --git a/packages/core/src/server-runtime-client.ts b/packages/core/src/server-runtime-client.ts index 5435d5c8fff0..bb0efe6652dc 100644 --- a/packages/core/src/server-runtime-client.ts +++ b/packages/core/src/server-runtime-client.ts @@ -42,6 +42,7 @@ export interface ServerRuntimeClientOptions extends ClientOptions extends BaseClient { + // eslint-disable-next-line deprecation/deprecation protected _sessionFlusher: SessionFlusher | undefined; /** @@ -80,10 +81,12 @@ export class ServerRuntimeClient< */ // eslint-disable-next-line @typescript-eslint/no-explicit-any public captureException(exception: any, hint?: EventHint, scope?: Scope): string { - // Check if the flag `autoSessionTracking` is enabled, and if `_sessionFlusher` exists because it is initialised only - // when the `requestHandler` middleware is used, and hence the expectation is to have SessionAggregates payload - // sent to the Server only when the `requestHandler` middleware is used + // Check if `_sessionFlusher` exists because it is initialized (defined) only when the `autoSessionTracking` is enabled. + // 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. if (this._options.autoSessionTracking && this._sessionFlusher) { + // eslint-disable-next-line deprecation/deprecation const requestSession = getIsolationScope().getRequestSession(); // Necessary checks to ensure this is code block is executed only within a request @@ -100,9 +103,10 @@ export class ServerRuntimeClient< * @inheritDoc */ public captureEvent(event: Event, hint?: EventHint, scope?: Scope): string { - // Check if the flag `autoSessionTracking` is enabled, and if `_sessionFlusher` exists because it is initialised only - // when the `requestHandler` middleware is used, and hence the expectation is to have SessionAggregates payload - // sent to the Server only when the `requestHandler` middleware is used + // Check if `_sessionFlusher` exists because it is initialized only when the `autoSessionTracking` is enabled. + // 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. if (this._options.autoSessionTracking && this._sessionFlusher) { const eventType = event.type || 'exception'; const isException = @@ -110,6 +114,7 @@ export class ServerRuntimeClient< // If the event is of type Exception, then a request session should be captured if (isException) { + // eslint-disable-next-line deprecation/deprecation const requestSession = getIsolationScope().getRequestSession(); // Ensure that this is happening within the bounds of a request, and make sure not to override @@ -134,12 +139,19 @@ export class ServerRuntimeClient< return super.close(timeout); } - /** Method that initialises an instance of SessionFlusher on Client */ + /** + * Initializes an instance of SessionFlusher on the client which will aggregate and periodically flush session data. + * + * NOTICE: This method will implicitly create an interval that is periodically called. + * To clean up this resources, call `.close()` when you no longer intend to use the client. + * Not doing so will result in a memory leak. + */ public initSessionFlusher(): void { const { release, environment } = this._options; if (!release) { - DEBUG_BUILD && logger.warn('Cannot initialise an instance of SessionFlusher if no release is provided!'); + DEBUG_BUILD && logger.warn('Cannot initialize an instance of SessionFlusher if no release is provided!'); } else { + // eslint-disable-next-line deprecation/deprecation this._sessionFlusher = new SessionFlusher(this, { release, environment, @@ -214,6 +226,8 @@ export class ServerRuntimeClient< /** * Method responsible for capturing/ending a request session by calling `incrementSessionStatusCount` to increment * appropriate session aggregates bucket + * + * @deprecated This method should not be used or extended. It's functionality will move into the `httpIntegration` and not be part of any public API. */ protected _captureRequestSession(): void { if (!this._sessionFlusher) { diff --git a/packages/core/src/sessionflusher.ts b/packages/core/src/sessionflusher.ts index e35b8f70785d..317ac8e1ab80 100644 --- a/packages/core/src/sessionflusher.ts +++ b/packages/core/src/sessionflusher.ts @@ -14,8 +14,10 @@ type ReleaseHealthAttributes = { }; /** - * @inheritdoc + * @deprecated `SessionFlusher` is deprecated and will be removed in the next major version of the SDK. */ +// TODO(v9): The goal for the SessionFlusher is to become a stupidly simple mechanism to aggregate "Sessions" (actually "RequestSessions"). It should probably live directly inside the Http integration/instrumentation. +// eslint-disable-next-line deprecation/deprecation export class SessionFlusher implements SessionFlusherLike { public readonly flushTimeout: number; private _pendingAggregates: Map; @@ -80,12 +82,14 @@ export class SessionFlusher implements SessionFlusherLike { return; } const isolationScope = getIsolationScope(); + // eslint-disable-next-line deprecation/deprecation const requestSession = isolationScope.getRequestSession(); if (requestSession && requestSession.status) { this._incrementSessionStatusCount(requestSession.status, new Date()); // This is not entirely necessarily but is added as a safe guard to indicate the bounds of a request and so in // case captureRequestSession is called more than once to prevent double count + // eslint-disable-next-line deprecation/deprecation isolationScope.setRequestSession(undefined); /* eslint-enable @typescript-eslint/no-unsafe-member-access */ } @@ -95,6 +99,7 @@ export class SessionFlusher implements SessionFlusherLike { * Increments status bucket in pendingAggregates buffer (internal state) corresponding to status of * the session received */ + // eslint-disable-next-line deprecation/deprecation private _incrementSessionStatusCount(status: RequestSessionStatus, date: Date): number { // Truncate minutes and seconds on Session Started attribute to have one minute bucket keys const sessionStartedTrunc = new Date(date).setSeconds(0, 0); diff --git a/packages/core/src/types-hoist/index.ts b/packages/core/src/types-hoist/index.ts index 5dd1839aeba7..1a289845c9ad 100644 --- a/packages/core/src/types-hoist/index.ts +++ b/packages/core/src/types-hoist/index.ts @@ -104,8 +104,11 @@ export type { Session, SessionContext, SessionStatus, + // eslint-disable-next-line deprecation/deprecation RequestSession, + // eslint-disable-next-line deprecation/deprecation RequestSessionStatus, + // eslint-disable-next-line deprecation/deprecation SessionFlusherLike, SerializedSession, } from './session'; diff --git a/packages/core/src/types-hoist/scope.ts b/packages/core/src/types-hoist/scope.ts index d3fe29f5e4b1..57990d310820 100644 --- a/packages/core/src/types-hoist/scope.ts +++ b/packages/core/src/types-hoist/scope.ts @@ -23,6 +23,7 @@ export interface ScopeContext { contexts: Contexts; tags: { [key: string]: Primitive }; fingerprint: string[]; + // eslint-disable-next-line deprecation/deprecation requestSession: RequestSession; propagationContext: PropagationContext; } @@ -168,12 +169,18 @@ export interface Scope { /** * Returns the `RequestSession` if there is one + * + * @deprecated Use `getSession()` and `setSession()` instead of `getRequestSession()` and `setRequestSession()`; */ + // eslint-disable-next-line deprecation/deprecation getRequestSession(): RequestSession | undefined; /** * Sets the `RequestSession` on the scope + * + * @deprecated Use `getSession()` and `setSession()` instead of `getRequestSession()` and `setRequestSession()`; */ + // eslint-disable-next-line deprecation/deprecation setRequestSession(requestSession?: RequestSession): this; /** diff --git a/packages/core/src/types-hoist/session.ts b/packages/core/src/types-hoist/session.ts index 5bc49b9a7733..47cfa348acbb 100644 --- a/packages/core/src/types-hoist/session.ts +++ b/packages/core/src/types-hoist/session.ts @@ -1,6 +1,10 @@ import type { User } from './user'; +/** + * @deprecated This type is deprecated and will be removed in the next major version of the SDK. + */ export interface RequestSession { + // eslint-disable-next-line deprecation/deprecation status?: RequestSessionStatus; } @@ -35,6 +39,10 @@ export interface Session { export type SessionContext = Partial; export type SessionStatus = 'ok' | 'exited' | 'crashed' | 'abnormal'; + +/** + * @deprecated This type is deprecated and will be removed in the next major version of the SDK. + */ export type RequestSessionStatus = 'ok' | 'errored' | 'crashed'; /** JSDoc */ @@ -46,6 +54,9 @@ export interface SessionAggregates { aggregates: Array; } +/** + * @deprecated This type is deprecated and will be removed in the next major version of the SDK. + */ export interface SessionFlusherLike { /** * Increments the Session Status bucket in SessionAggregates Object corresponding to the status of the session diff --git a/packages/core/test/lib/scope.test.ts b/packages/core/test/lib/scope.test.ts index df95e08dcb97..76130e779fed 100644 --- a/packages/core/test/lib/scope.test.ts +++ b/packages/core/test/lib/scope.test.ts @@ -261,8 +261,10 @@ describe('Scope', () => { test('_requestSession clone', () => { const parentScope = new Scope(); + // eslint-disable-next-line deprecation/deprecation parentScope.setRequestSession({ status: 'errored' }); const scope = parentScope.clone(); + // eslint-disable-next-line deprecation/deprecation expect(parentScope.getRequestSession()).toEqual(scope.getRequestSession()); }); @@ -288,15 +290,19 @@ describe('Scope', () => { // Test that ensures if the status value of `status` of `_requestSession` is changed in a child scope // that it should also change in parent scope because we are copying the reference to the object const parentScope = new Scope(); + // eslint-disable-next-line deprecation/deprecation parentScope.setRequestSession({ status: 'errored' }); const scope = parentScope.clone(); + // eslint-disable-next-line deprecation/deprecation const requestSession = scope.getRequestSession(); if (requestSession) { requestSession.status = 'ok'; } + // eslint-disable-next-line deprecation/deprecation expect(parentScope.getRequestSession()).toEqual({ status: 'ok' }); + // eslint-disable-next-line deprecation/deprecation expect(scope.getRequestSession()).toEqual({ status: 'ok' }); }); @@ -316,6 +322,7 @@ describe('Scope', () => { scope.setUser({ id: '1' }); scope.setFingerprint(['abcd']); scope.addBreadcrumb({ message: 'test' }); + // eslint-disable-next-line deprecation/deprecation scope.setRequestSession({ status: 'ok' }); expect(scope['_extra']).toEqual({ a: 2 }); scope.clear(); @@ -349,6 +356,7 @@ describe('Scope', () => { scope.setUser({ id: '1337' }); scope.setLevel('info'); scope.setFingerprint(['foo']); + // eslint-disable-next-line deprecation/deprecation scope.setRequestSession({ status: 'ok' }); }); @@ -453,6 +461,7 @@ describe('Scope', () => { level: 'warning' as const, tags: { bar: '3', baz: '4' }, user: { id: '42' }, + // eslint-disable-next-line deprecation/deprecation requestSession: { status: 'errored' as RequestSessionStatus }, propagationContext: { traceId: '8949daf83f4a4a70bee4c1eb9ab242ed', diff --git a/packages/core/test/lib/sessionflusher.test.ts b/packages/core/test/lib/sessionflusher.test.ts index 00f9becfdbf0..53fe930b58c2 100644 --- a/packages/core/test/lib/sessionflusher.test.ts +++ b/packages/core/test/lib/sessionflusher.test.ts @@ -19,6 +19,7 @@ describe('Session Flusher', () => { }); test('test incrementSessionStatusCount updates the internal SessionFlusher state', () => { + // eslint-disable-next-line deprecation/deprecation const flusher = new SessionFlusher(mockClient, { release: '1.0.0', environment: 'dev' }); const date = new Date('2021-04-08T12:18:23.043Z'); @@ -42,6 +43,7 @@ describe('Session Flusher', () => { }); test('test undefined attributes are excluded, on incrementSessionStatusCount call', () => { + // eslint-disable-next-line deprecation/deprecation const flusher = new SessionFlusher(mockClient, { release: '1.0.0' }); const date = new Date('2021-04-08T12:18:23.043Z'); @@ -55,6 +57,7 @@ describe('Session Flusher', () => { }); test('flush is called every 60 seconds after initialisation of an instance of SessionFlusher', () => { + // eslint-disable-next-line deprecation/deprecation const flusher = new SessionFlusher(mockClient, { release: '1.0.0', environment: 'dev' }); const flusherFlushFunc = jest.spyOn(flusher, 'flush'); jest.advanceTimersByTime(59000); @@ -68,6 +71,7 @@ describe('Session Flusher', () => { }); test('sendSessions is called on flush if sessions were captured', () => { + // eslint-disable-next-line deprecation/deprecation const flusher = new SessionFlusher(mockClient, { release: '1.0.0', environment: 'dev' }); const flusherFlushFunc = jest.spyOn(flusher, 'flush'); const date = new Date('2021-04-08T12:18:23.043Z'); @@ -88,6 +92,7 @@ describe('Session Flusher', () => { }); test('sendSessions is not called on flush if no sessions were captured', () => { + // eslint-disable-next-line deprecation/deprecation const flusher = new SessionFlusher(mockClient, { release: '1.0.0', environment: 'dev' }); const flusherFlushFunc = jest.spyOn(flusher, 'flush'); @@ -98,12 +103,14 @@ describe('Session Flusher', () => { }); test('calling close on SessionFlusher should disable SessionFlusher', () => { + // eslint-disable-next-line deprecation/deprecation const flusher = new SessionFlusher(mockClient, { release: '1.0.x' }); flusher.close(); expect((flusher as any)._isEnabled).toEqual(false); }); test('calling close on SessionFlusher will force call flush', () => { + // eslint-disable-next-line deprecation/deprecation const flusher = new SessionFlusher(mockClient, { release: '1.0.x' }); const flusherFlushFunc = jest.spyOn(flusher, 'flush'); const date = new Date('2021-04-08T12:18:23.043Z'); diff --git a/packages/node/src/integrations/http/SentryHttpInstrumentation.ts b/packages/node/src/integrations/http/SentryHttpInstrumentation.ts index 382e5bde8a0a..ed28d5a66934 100644 --- a/packages/node/src/integrations/http/SentryHttpInstrumentation.ts +++ b/packages/node/src/integrations/http/SentryHttpInstrumentation.ts @@ -149,6 +149,7 @@ export class SentryHttpInstrumentation extends InstrumentationBase(); if (client && client.getOptions().autoSessionTracking) { + // eslint-disable-next-line deprecation/deprecation isolationScope.setRequestSession({ status: 'ok' }); } diff --git a/packages/node/src/integrations/tracing/express.ts b/packages/node/src/integrations/tracing/express.ts index 73312353da46..bcb668d52f80 100644 --- a/packages/node/src/integrations/tracing/express.ts +++ b/packages/node/src/integrations/tracing/express.ts @@ -129,6 +129,7 @@ export function expressErrorHandler(options?: ExpressHandlerOptions): ExpressMid // running in SessionAggregates mode const isSessionAggregatesMode = client['_sessionFlusher'] !== undefined; if (isSessionAggregatesMode) { + // eslint-disable-next-line deprecation/deprecation const requestSession = getIsolationScope().getRequestSession(); // If an error bubbles to the `errorHandler`, then this is an unhandled error, and should be reported as a // Crashed session. The `_requestSession.status` is checked to ensure that this error is happening within diff --git a/packages/node/src/sdk/index.ts b/packages/node/src/sdk/index.ts index 1104386fb2ca..8cc3b5ff8609 100644 --- a/packages/node/src/sdk/index.ts +++ b/packages/node/src/sdk/index.ts @@ -156,6 +156,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 if (options.autoSessionTracking) { startSessionTracking(); } diff --git a/packages/node/test/integrations/express.test.ts b/packages/node/test/integrations/express.test.ts index 417c3b783216..1213e7bb38cf 100644 --- a/packages/node/test/integrations/express.test.ts +++ b/packages/node/test/integrations/express.test.ts @@ -59,6 +59,7 @@ describe('expressErrorHandler()', () => { jest.spyOn(client, '_captureRequestSession'); + // eslint-disable-next-line deprecation/deprecation getIsolationScope().setRequestSession({ status: 'ok' }); let isolationScope: Scope; @@ -68,6 +69,7 @@ describe('expressErrorHandler()', () => { }); setImmediate(() => { + // eslint-disable-next-line deprecation/deprecation expect(isolationScope.getRequestSession()).toEqual({ status: 'ok' }); done(); }); @@ -80,6 +82,7 @@ describe('expressErrorHandler()', () => { jest.spyOn(client, '_captureRequestSession'); + // eslint-disable-next-line deprecation/deprecation getIsolationScope().setRequestSession({ status: 'ok' }); let isolationScope: Scope; @@ -89,6 +92,7 @@ describe('expressErrorHandler()', () => { }); setImmediate(() => { + // eslint-disable-next-line deprecation/deprecation expect(isolationScope.getRequestSession()).toEqual({ status: 'ok' }); done(); }); @@ -106,8 +110,10 @@ describe('expressErrorHandler()', () => { jest.spyOn(client, '_captureRequestSession'); withScope(() => { + // eslint-disable-next-line deprecation/deprecation getIsolationScope().setRequestSession({ status: 'ok' }); sentryErrorMiddleware({ name: 'error', message: 'this is an error' }, req, res, () => { + // eslint-disable-next-line deprecation/deprecation expect(getIsolationScope().getRequestSession()).toEqual({ status: 'crashed' }); }); }); @@ -130,6 +136,7 @@ describe('expressErrorHandler()', () => { }); setImmediate(() => { + // eslint-disable-next-line deprecation/deprecation expect(isolationScope.getRequestSession()).toEqual(undefined); done(); }); diff --git a/packages/node/test/sdk/client.test.ts b/packages/node/test/sdk/client.test.ts index 5f351ff3e990..5add93731c5e 100644 --- a/packages/node/test/sdk/client.test.ts +++ b/packages/node/test/sdk/client.test.ts @@ -82,10 +82,12 @@ describe('NodeClient', () => { initOpenTelemetry(client); withIsolationScope(isolationScope => { + // eslint-disable-next-line deprecation/deprecation isolationScope.setRequestSession({ status: 'ok' }); client.captureException(new Error('test exception')); + // eslint-disable-next-line deprecation/deprecation const requestSession = isolationScope.getRequestSession(); expect(requestSession!.status).toEqual('ok'); }); @@ -103,10 +105,12 @@ describe('NodeClient', () => { client.initSessionFlusher(); withIsolationScope(isolationScope => { + // eslint-disable-next-line deprecation/deprecation isolationScope.setRequestSession({ status: 'ok' }); client.captureException(new Error('test exception')); + // eslint-disable-next-line deprecation/deprecation const requestSession = isolationScope.getRequestSession(); expect(requestSession!.status).toEqual('ok'); }); @@ -124,10 +128,12 @@ describe('NodeClient', () => { client.initSessionFlusher(); withIsolationScope(isolationScope => { + // eslint-disable-next-line deprecation/deprecation isolationScope.setRequestSession({ status: 'crashed' }); client.captureException(new Error('test exception')); + // eslint-disable-next-line deprecation/deprecation const requestSession = isolationScope.getRequestSession(); expect(requestSession!.status).toEqual('crashed'); }); @@ -145,10 +151,12 @@ describe('NodeClient', () => { client.initSessionFlusher(); withIsolationScope(isolationScope => { + // eslint-disable-next-line deprecation/deprecation isolationScope.setRequestSession({ status: 'ok' }); client.captureException(new Error('test exception')); + // eslint-disable-next-line deprecation/deprecation const requestSession = isolationScope.getRequestSession(); expect(requestSession!.status).toEqual('errored'); }); @@ -167,6 +175,7 @@ describe('NodeClient', () => { let isolationScope: Scope; withIsolationScope(_isolationScope => { + // eslint-disable-next-line deprecation/deprecation _isolationScope.setRequestSession({ status: 'ok' }); isolationScope = _isolationScope; }); @@ -174,6 +183,7 @@ describe('NodeClient', () => { client.captureException(new Error('test exception')); setImmediate(() => { + // eslint-disable-next-line deprecation/deprecation const requestSession = isolationScope.getRequestSession(); expect(requestSession).toEqual({ status: 'ok' }); done(); @@ -194,8 +204,10 @@ describe('NodeClient', () => { client.initSessionFlusher(); withIsolationScope(isolationScope => { + // eslint-disable-next-line deprecation/deprecation isolationScope.setRequestSession({ status: 'ok' }); client.captureEvent({ message: 'message', exception: { values: [{ type: 'exception type 1' }] } }); + // eslint-disable-next-line deprecation/deprecation const requestSession = isolationScope.getRequestSession(); expect(requestSession!.status).toEqual('ok'); }); @@ -209,10 +221,12 @@ describe('NodeClient', () => { client.initSessionFlusher(); withIsolationScope(isolationScope => { + // eslint-disable-next-line deprecation/deprecation isolationScope.setRequestSession({ status: 'ok' }); client.captureEvent({ message: 'message', exception: { values: [{ type: 'exception type 1' }] } }); + // eslint-disable-next-line deprecation/deprecation const requestSession = isolationScope.getRequestSession(); expect(requestSession!.status).toEqual('errored'); }); @@ -230,10 +244,12 @@ describe('NodeClient', () => { client.initSessionFlusher(); withIsolationScope(isolationScope => { + // eslint-disable-next-line deprecation/deprecation isolationScope.setRequestSession({ status: 'ok' }); client.captureEvent({ message: 'message' }); + // eslint-disable-next-line deprecation/deprecation const requestSession = isolationScope.getRequestSession(); expect(requestSession!.status).toEqual('ok'); }); @@ -254,6 +270,7 @@ describe('NodeClient', () => { isolationScope.clear(); client.captureEvent({ message: 'message', exception: { values: [{ type: 'exception type 1' }] } }); + // eslint-disable-next-line deprecation/deprecation expect(isolationScope.getRequestSession()).toEqual(undefined); }); }); @@ -270,10 +287,12 @@ describe('NodeClient', () => { client.initSessionFlusher(); withIsolationScope(isolationScope => { + // eslint-disable-next-line deprecation/deprecation isolationScope.setRequestSession({ status: 'ok' }); client.captureEvent({ message: 'message', type: 'transaction' }); + // eslint-disable-next-line deprecation/deprecation const requestSession = isolationScope.getRequestSession(); expect(requestSession!.status).toEqual('ok'); }); @@ -287,10 +306,12 @@ describe('NodeClient', () => { initOpenTelemetry(client); withIsolationScope(isolationScope => { + // eslint-disable-next-line deprecation/deprecation isolationScope.setRequestSession({ status: 'ok' }); client.captureEvent({ message: 'message', exception: { values: [{ type: 'exception type 1' }] } }); + // eslint-disable-next-line deprecation/deprecation const requestSession = isolationScope.getRequestSession(); expect(requestSession!.status).toEqual('ok'); }); @@ -527,6 +548,7 @@ describe('flush/close', () => { // not due to the interval running every 60s clearInterval(client['_sessionFlusher']!['_intervalId']); + // eslint-disable-next-line deprecation/deprecation const sessionFlusherFlushFunc = jest.spyOn(SessionFlusher.prototype, 'flush'); const delay = 1; diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 372e5e854a87..2008eb88c39a 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -419,10 +419,13 @@ export type SessionContext = SessionContext_imported; /** @deprecated This type has been moved to `@sentry/core`. */ export type SessionStatus = SessionStatus_imported; /** @deprecated This type has been moved to `@sentry/core`. */ +// eslint-disable-next-line deprecation/deprecation export type RequestSession = RequestSession_imported; /** @deprecated This type has been moved to `@sentry/core`. */ +// eslint-disable-next-line deprecation/deprecation export type RequestSessionStatus = RequestSessionStatus_imported; /** @deprecated This type has been moved to `@sentry/core`. */ +// eslint-disable-next-line deprecation/deprecation export type SessionFlusherLike = SessionFlusherLike_imported; /** @deprecated This type has been moved to `@sentry/core`. */ export type SerializedSession = SerializedSession_imported;