Skip to content

Commit a7097d9

Browse files
authored
ref: Make scope setters on hub only write to isolation scope (#10572)
1 parent 2014d6a commit a7097d9

File tree

7 files changed

+24
-41
lines changed

7 files changed

+24
-41
lines changed

packages/astro/test/client/sdk.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type { BrowserClient } from '@sentry/browser';
22
import { getActiveSpan } from '@sentry/browser';
3-
import { browserTracingIntegration, getCurrentScope } from '@sentry/browser';
3+
import { browserTracingIntegration } from '@sentry/browser';
44
import * as SentryBrowser from '@sentry/browser';
55
import { BrowserTracing, SDK_VERSION, WINDOW, getClient } from '@sentry/browser';
66
import { vi } from 'vitest';
77

8+
import { getIsolationScope } from '@sentry/core';
89
import { init } from '../../../astro/src/client/sdk';
910

1011
const browserInit = vi.spyOn(SentryBrowser, 'init');
@@ -38,16 +39,16 @@ describe('Sentry client SDK', () => {
3839
);
3940
});
4041

41-
it('sets the runtime tag on the scope', () => {
42-
const currentScope = getCurrentScope();
42+
it('sets the runtime tag on the isolation scope', () => {
43+
const isolationScope = getIsolationScope();
4344

4445
// @ts-expect-error need access to protected _tags attribute
45-
expect(currentScope._tags).toEqual({});
46+
expect(isolationScope._tags).toEqual({});
4647

4748
init({ dsn: 'https://[email protected]/1337' });
4849

4950
// @ts-expect-error need access to protected _tags attribute
50-
expect(currentScope._tags).toEqual({ runtime: 'browser' });
51+
expect(isolationScope._tags).toEqual({ runtime: 'browser' });
5152
});
5253

5354
describe('automatically adds integrations', () => {

packages/astro/test/server/sdk.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ describe('Sentry server SDK', () => {
3636
);
3737
});
3838

39-
it('sets the runtime tag on the scope', () => {
40-
const currentScope = SentryNode.getCurrentScope();
39+
it('sets the runtime tag on the isolation scope', () => {
40+
const isolationScope = SentryNode.getIsolationScope();
4141

4242
// @ts-expect-error need access to protected _tags attribute
43-
expect(currentScope._tags).toEqual({});
43+
expect(isolationScope._tags).toEqual({});
4444

4545
init({ dsn: 'https://[email protected]/1337' });
4646

4747
// @ts-expect-error need access to protected _tags attribute
48-
expect(currentScope._tags).toEqual({ runtime: 'node' });
48+
expect(isolationScope._tags).toEqual({ runtime: 'node' });
4949
});
5050
});
5151
});

packages/core/src/hub.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,6 @@ export class Hub implements HubInterface {
439439
* @deprecated Use `Sentry.setUser()` instead.
440440
*/
441441
public setUser(user: User | null): void {
442-
// TODO(v8): The top level `Sentry.setUser()` function should write ONLY to the isolation scope.
443-
// eslint-disable-next-line deprecation/deprecation
444-
this.getScope().setUser(user);
445442
// eslint-disable-next-line deprecation/deprecation
446443
this.getIsolationScope().setUser(user);
447444
}
@@ -451,9 +448,6 @@ export class Hub implements HubInterface {
451448
* @deprecated Use `Sentry.setTags()` instead.
452449
*/
453450
public setTags(tags: { [key: string]: Primitive }): void {
454-
// TODO(v8): The top level `Sentry.setTags()` function should write ONLY to the isolation scope.
455-
// eslint-disable-next-line deprecation/deprecation
456-
this.getScope().setTags(tags);
457451
// eslint-disable-next-line deprecation/deprecation
458452
this.getIsolationScope().setTags(tags);
459453
}
@@ -463,9 +457,6 @@ export class Hub implements HubInterface {
463457
* @deprecated Use `Sentry.setExtras()` instead.
464458
*/
465459
public setExtras(extras: Extras): void {
466-
// TODO(v8): The top level `Sentry.setExtras()` function should write ONLY to the isolation scope.
467-
// eslint-disable-next-line deprecation/deprecation
468-
this.getScope().setExtras(extras);
469460
// eslint-disable-next-line deprecation/deprecation
470461
this.getIsolationScope().setExtras(extras);
471462
}
@@ -475,9 +466,6 @@ export class Hub implements HubInterface {
475466
* @deprecated Use `Sentry.setTag()` instead.
476467
*/
477468
public setTag(key: string, value: Primitive): void {
478-
// TODO(v8): The top level `Sentry.setTag()` function should write ONLY to the isolation scope.
479-
// eslint-disable-next-line deprecation/deprecation
480-
this.getScope().setTag(key, value);
481469
// eslint-disable-next-line deprecation/deprecation
482470
this.getIsolationScope().setTag(key, value);
483471
}
@@ -487,9 +475,6 @@ export class Hub implements HubInterface {
487475
* @deprecated Use `Sentry.setExtra()` instead.
488476
*/
489477
public setExtra(key: string, extra: Extra): void {
490-
// TODO(v8): The top level `Sentry.setExtra()` function should write ONLY to the isolation scope.
491-
// eslint-disable-next-line deprecation/deprecation
492-
this.getScope().setExtra(key, extra);
493478
// eslint-disable-next-line deprecation/deprecation
494479
this.getIsolationScope().setExtra(key, extra);
495480
}
@@ -500,9 +485,6 @@ export class Hub implements HubInterface {
500485
*/
501486
// eslint-disable-next-line @typescript-eslint/no-explicit-any
502487
public setContext(name: string, context: { [key: string]: any } | null): void {
503-
// TODO(v8): The top level `Sentry.setContext()` function should write ONLY to the isolation scope.
504-
// eslint-disable-next-line deprecation/deprecation
505-
this.getScope().setContext(name, context);
506488
// eslint-disable-next-line deprecation/deprecation
507489
this.getIsolationScope().setContext(name, context);
508490
}

packages/sveltekit/src/client/sdk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { applySdkMetadata, hasTracingEnabled } from '@sentry/core';
1+
import { applySdkMetadata, hasTracingEnabled, setTag } from '@sentry/core';
22
import type { BrowserOptions, browserTracingIntegration } from '@sentry/svelte';
33
import { getDefaultIntegrations as getDefaultSvelteIntegrations } from '@sentry/svelte';
4-
import { WINDOW, getCurrentScope, init as initSvelteSdk } from '@sentry/svelte';
4+
import { WINDOW, init as initSvelteSdk } from '@sentry/svelte';
55
import type { Integration } from '@sentry/types';
66

77
import {
@@ -42,7 +42,7 @@ export function init(options: BrowserOptions): void {
4242
restoreFetch(actualFetch);
4343
}
4444

45-
getCurrentScope().setTag('runtime', 'browser');
45+
setTag('runtime', 'browser');
4646
}
4747

4848
// TODO v8: Remove this again

packages/sveltekit/src/server/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { applySdkMetadata, getCurrentScope } from '@sentry/core';
1+
import { applySdkMetadata, setTag } from '@sentry/core';
22
import type { NodeOptions } from '@sentry/node';
33
import { getDefaultIntegrations as getDefaultNodeIntegrations } from '@sentry/node';
44
import { init as initNodeSdk } from '@sentry/node';
@@ -19,5 +19,5 @@ export function init(options: NodeOptions): void {
1919

2020
initNodeSdk(opts);
2121

22-
getCurrentScope().setTag('runtime', 'node');
22+
setTag('runtime', 'node');
2323
}

packages/sveltekit/test/client/sdk.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getClient, getCurrentScope } from '@sentry/core';
1+
import { getClient, getIsolationScope } from '@sentry/core';
22
import type { BrowserClient } from '@sentry/svelte';
33
import * as SentrySvelte from '@sentry/svelte';
44
import { SDK_VERSION, WINDOW, browserTracingIntegration } from '@sentry/svelte';
@@ -38,16 +38,16 @@ describe('Sentry client SDK', () => {
3838
);
3939
});
4040

41-
it('sets the runtime tag on the scope', () => {
42-
const currentScope = getCurrentScope();
41+
it('sets the runtime tag on the isolation scope', () => {
42+
const isolationScope = getIsolationScope();
4343

4444
// @ts-expect-error need access to protected _tags attribute
45-
expect(currentScope._tags).toEqual({});
45+
expect(isolationScope._tags).toEqual({});
4646

4747
init({ dsn: 'https://[email protected]/1337' });
4848

4949
// @ts-expect-error need access to protected _tags attribute
50-
expect(currentScope._tags).toEqual({ runtime: 'browser' });
50+
expect(isolationScope._tags).toEqual({ runtime: 'browser' });
5151
});
5252

5353
describe('automatically added integrations', () => {

packages/sveltekit/test/server/sdk.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ describe('Sentry server SDK', () => {
3636
);
3737
});
3838

39-
it('sets the runtime tag on the scope', () => {
40-
const currentScope = SentryNode.getCurrentScope();
39+
it('sets the runtime tag on the isolation scope', () => {
40+
const isolationScope = SentryNode.getIsolationScope();
4141

4242
// @ts-expect-error need access to protected _tags attribute
43-
expect(currentScope._tags).toEqual({});
43+
expect(isolationScope._tags).toEqual({});
4444

4545
init({ dsn: 'https://[email protected]/1337' });
4646

4747
// @ts-expect-error need access to protected _tags attribute
48-
expect(currentScope._tags).toEqual({ runtime: 'node' });
48+
expect(isolationScope._tags).toEqual({ runtime: 'node' });
4949
});
5050

5151
it('adds rewriteFramesIntegration by default', () => {

0 commit comments

Comments
 (0)