Skip to content

Commit 2652bf2

Browse files
committed
ref: Store runtime on isolation scope
This was a bit inconsistent now, we sometimes stored it on the current and sometimes on the isolation scope. Fixing this to always be on the isolation scope, for consistency.
1 parent c00bbac commit 2652bf2

File tree

12 files changed

+73
-92
lines changed

12 files changed

+73
-92
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,11 @@ describe('Sentry client SDK', () => {
4040
});
4141

4242
it('sets the runtime tag on the isolation scope', () => {
43-
const isolationScope = getIsolationScope();
44-
45-
// @ts-expect-error need access to protected _tags attribute
46-
expect(isolationScope._tags).toEqual({});
43+
expect(getIsolationScope().getScopeData().tags).toEqual({});
4744

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

50-
// @ts-expect-error need access to protected _tags attribute
51-
expect(isolationScope._tags).toEqual({ runtime: 'browser' });
47+
expect(getIsolationScope().getScopeData().tags).toEqual({ runtime: 'browser' });
5248
});
5349

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

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as SentryNode from '@sentry/node';
22
import { SDK_VERSION } from '@sentry/node';
3-
import { GLOBAL_OBJ } from '@sentry/utils';
43
import { vi } from 'vitest';
54

65
import { init } from '../../src/server/sdk';
@@ -11,7 +10,10 @@ describe('Sentry server SDK', () => {
1110
describe('init', () => {
1211
afterEach(() => {
1312
vi.clearAllMocks();
14-
GLOBAL_OBJ.__SENTRY__.hub = undefined;
13+
14+
SentryNode.getGlobalScope().clear();
15+
SentryNode.getIsolationScope().clear();
16+
SentryNode.getCurrentScope().clear();
1517
});
1618

1719
it('adds Astro metadata to the SDK options', () => {
@@ -37,15 +39,11 @@ describe('Sentry server SDK', () => {
3739
});
3840

3941
it('sets the runtime tag on the isolation scope', () => {
40-
const isolationScope = SentryNode.getIsolationScope();
41-
42-
// @ts-expect-error need access to protected _tags attribute
43-
expect(isolationScope._tags).toEqual({});
42+
expect(SentryNode.getIsolationScope().getScopeData().tags).toEqual({});
4443

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

47-
// @ts-expect-error need access to protected _tags attribute
48-
expect(isolationScope._tags).toEqual({ runtime: 'node' });
46+
expect(SentryNode.getIsolationScope().getScopeData().tags).toEqual({ runtime: 'node' });
4947
});
5048
});
5149
});

packages/nextjs/src/client/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { applySdkMetadata, hasTracingEnabled } from '@sentry/core';
1+
import { addEventProcessor, applySdkMetadata, hasTracingEnabled, setTag } from '@sentry/core';
22
import type { BrowserOptions } from '@sentry/react';
33
import {
44
DEFAULT_TRACE_PROPAGATION_TARGETS,
5-
getCurrentScope,
65
getDefaultIntegrations as getReactDefaultIntegrations,
76
init as reactInit,
87
} from '@sentry/react';
@@ -49,15 +48,14 @@ export function init(options: BrowserOptions): void {
4948

5049
reactInit(opts);
5150

52-
const scope = getCurrentScope();
53-
scope.setTag('runtime', 'browser');
51+
setTag('runtime', 'browser');
5452
const filterTransactions: EventProcessor = event =>
5553
event.type === 'transaction' && event.transaction === '/404' ? null : event;
5654
filterTransactions.id = 'NextClient404Filter';
57-
scope.addEventProcessor(filterTransactions);
55+
addEventProcessor(filterTransactions);
5856

5957
if (process.env.NODE_ENV === 'development') {
60-
scope.addEventProcessor(devErrorSymbolicationEventProcessor);
58+
addEventProcessor(devErrorSymbolicationEventProcessor);
6159
}
6260
}
6361

packages/nextjs/src/server/index.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import { addTracingExtensions, applySdkMetadata, getClient } from '@sentry/core';
1+
import { addEventProcessor, addTracingExtensions, applySdkMetadata, getClient, setTag } from '@sentry/core';
22
import type { NodeOptions } from '@sentry/node';
3-
import {
4-
Integrations as OriginalIntegrations,
5-
getCurrentScope,
6-
getDefaultIntegrations,
7-
init as nodeInit,
8-
} from '@sentry/node';
3+
import { Integrations as OriginalIntegrations, getDefaultIntegrations, init as nodeInit } from '@sentry/node';
94
import type { EventProcessor } from '@sentry/types';
105
import { logger } from '@sentry/utils';
116

@@ -120,16 +115,15 @@ export function init(options: NodeOptions): void {
120115

121116
filterTransactions.id = 'NextServer404TransactionFilter';
122117

123-
const scope = getCurrentScope();
124-
scope.setTag('runtime', 'node');
118+
setTag('runtime', 'node');
125119
if (IS_VERCEL) {
126-
scope.setTag('vercel', true);
120+
setTag('vercel', true);
127121
}
128122

129-
scope.addEventProcessor(filterTransactions);
123+
addEventProcessor(filterTransactions);
130124

131125
if (process.env.NODE_ENV === 'development') {
132-
scope.addEventProcessor(devErrorSymbolicationEventProcessor);
126+
addEventProcessor(devErrorSymbolicationEventProcessor);
133127
}
134128

135129
DEBUG_BUILD && logger.log('SDK successfully initialized');

packages/nextjs/test/clientSdk.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BaseClient } from '@sentry/core';
1+
import { BaseClient, getGlobalScope, getIsolationScope } from '@sentry/core';
22
import * as SentryReact from '@sentry/react';
33
import type { BrowserClient } from '@sentry/react';
44
import { WINDOW, getClient, getCurrentScope } from '@sentry/react';
@@ -36,7 +36,10 @@ const TEST_DSN = 'https://[email protected]/1337';
3636
describe('Client init()', () => {
3737
afterEach(() => {
3838
jest.clearAllMocks();
39-
WINDOW.__SENTRY__.hub = undefined;
39+
40+
getGlobalScope().clear();
41+
getIsolationScope().clear();
42+
getCurrentScope().clear();
4043
});
4144

4245
it('inits the React SDK', () => {
@@ -72,15 +75,11 @@ describe('Client init()', () => {
7275
});
7376

7477
it('sets runtime on scope', () => {
75-
const currentScope = getCurrentScope();
76-
77-
// @ts-expect-error need access to protected _tags attribute
78-
expect(currentScope._tags).toEqual({});
78+
expect(SentryReact.getIsolationScope().getScopeData().tags).toEqual({});
7979

80-
init({});
80+
init({ dsn: 'https://[email protected]/1337' });
8181

82-
// @ts-expect-error need access to protected _tags attribute
83-
expect(currentScope._tags).toEqual({ runtime: 'browser' });
82+
expect(SentryReact.getIsolationScope().getScopeData().tags).toEqual({ runtime: 'browser' });
8483
});
8584

8685
it('adds 404 transaction filter', () => {

packages/nextjs/test/serverSdk.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ function findIntegrationByName(integrations: Integration[] = [], name: string):
1818
describe('Server init()', () => {
1919
afterEach(() => {
2020
jest.clearAllMocks();
21-
// @ts-expect-error for testing
22-
delete GLOBAL_OBJ.__SENTRY__;
21+
22+
SentryNode.getGlobalScope().clear();
23+
SentryNode.getIsolationScope().clear();
24+
SentryNode.getCurrentScope().clear();
25+
2326
delete process.env.VERCEL;
2427
});
2528

@@ -68,15 +71,11 @@ describe('Server init()', () => {
6871
});
6972

7073
it('sets runtime on scope', () => {
71-
const currentScope = getCurrentScope();
74+
expect(SentryNode.getIsolationScope().getScopeData().tags).toEqual({});
7275

73-
// @ts-expect-error need access to protected _tags attribute
74-
expect(currentScope._tags).toEqual({});
76+
init({ dsn: 'https://[email protected]/1337' });
7577

76-
init({});
77-
78-
// @ts-expect-error need access to protected _tags attribute
79-
expect(currentScope._tags).toEqual({ runtime: 'node' });
78+
expect(SentryNode.getIsolationScope().getScopeData().tags).toEqual({ runtime: 'node' });
8079
});
8180

8281
// TODO: test `vercel` tag when running on Vercel

packages/remix/src/index.client.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { applySdkMetadata } from '@sentry/core';
2-
import { getCurrentScope, init as reactInit } from '@sentry/react';
1+
import { applySdkMetadata, setTag } from '@sentry/core';
2+
import { init as reactInit } from '@sentry/react';
33
import type { RemixOptions } from './utils/remixOptions';
44
export { captureRemixErrorBoundaryError } from './client/errors';
55
export {
@@ -22,5 +22,5 @@ export function init(options: RemixOptions): void {
2222

2323
reactInit(opts);
2424

25-
getCurrentScope().setTag('runtime', 'browser');
25+
setTag('runtime', 'browser');
2626
}

packages/remix/src/index.server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { applySdkMetadata } from '@sentry/core';
22
import type { NodeOptions } from '@sentry/node';
3-
import { getClient } from '@sentry/node';
4-
import { getCurrentScope, init as nodeInit } from '@sentry/node';
3+
import { getClient, init as nodeInit, setTag } from '@sentry/node';
54
import { logger } from '@sentry/utils';
65

76
import { DEBUG_BUILD } from './utils/debug-build';
@@ -127,5 +126,5 @@ export function init(options: RemixOptions): void {
127126

128127
nodeInit(options as NodeOptions);
129128

130-
getCurrentScope().setTag('runtime', 'node');
129+
setTag('runtime', 'node');
131130
}

packages/remix/test/index.client.test.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { getCurrentScope } from '@sentry/core';
21
import * as SentryReact from '@sentry/react';
3-
import { GLOBAL_OBJ } from '@sentry/utils';
42

53
import { init } from '../src/index.client';
64

@@ -9,7 +7,10 @@ const reactInit = jest.spyOn(SentryReact, 'init');
97
describe('Client init()', () => {
108
afterEach(() => {
119
jest.clearAllMocks();
12-
GLOBAL_OBJ.__SENTRY__.hub = undefined;
10+
11+
SentryReact.getGlobalScope().clear();
12+
SentryReact.getIsolationScope().clear();
13+
SentryReact.getCurrentScope().clear();
1314
});
1415

1516
it('inits the React SDK', () => {
@@ -39,14 +40,10 @@ describe('Client init()', () => {
3940
});
4041

4142
it('sets runtime on scope', () => {
42-
const currentScope = getCurrentScope();
43-
44-
// @ts-expect-error need access to protected _tags attribute
45-
expect(currentScope._tags).toEqual({});
43+
expect(SentryReact.getIsolationScope().getScopeData().tags).toEqual({});
4644

47-
init({});
45+
init({ dsn: 'https://[email protected]/1337' });
4846

49-
// @ts-expect-error need access to protected _tags attribute
50-
expect(currentScope._tags).toEqual({ runtime: 'browser' });
47+
expect(SentryReact.getIsolationScope().getScopeData().tags).toEqual({ runtime: 'browser' });
5148
});
5249
});

packages/remix/test/index.server.test.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as SentryNode from '@sentry/node';
2-
import { GLOBAL_OBJ } from '@sentry/utils';
32

43
import { Integrations, init } from '../src/index.server';
54

@@ -8,7 +7,10 @@ const nodeInit = jest.spyOn(SentryNode, 'init');
87
describe('Server init()', () => {
98
afterEach(() => {
109
jest.clearAllMocks();
11-
GLOBAL_OBJ.__SENTRY__.hub = undefined;
10+
11+
SentryNode.getGlobalScope().clear();
12+
SentryNode.getIsolationScope().clear();
13+
SentryNode.getCurrentScope().clear();
1214
});
1315

1416
it('inits the Node SDK', () => {
@@ -46,15 +48,11 @@ describe('Server init()', () => {
4648
});
4749

4850
it('sets runtime on scope', () => {
49-
const currentScope = SentryNode.getCurrentScope();
50-
51-
// @ts-expect-error need access to protected _tags attribute
52-
expect(currentScope._tags).toEqual({});
51+
expect(SentryNode.getIsolationScope().getScopeData().tags).toEqual({});
5352

54-
init({});
53+
init({ dsn: 'https://[email protected]/1337' });
5554

56-
// @ts-expect-error need access to protected _tags attribute
57-
expect(currentScope._tags).toEqual({ runtime: 'node' });
55+
expect(SentryNode.getIsolationScope().getScopeData().tags).toEqual({ runtime: 'node' });
5856
});
5957

6058
it('has both node and tracing integrations', () => {

0 commit comments

Comments
 (0)