Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 2 additions & 6 deletions packages/astro/test/client/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,11 @@ describe('Sentry client SDK', () => {
});

it('sets the runtime tag on the isolation scope', () => {
const isolationScope = getIsolationScope();

// @ts-expect-error need access to protected _tags attribute
expect(isolationScope._tags).toEqual({});
expect(getIsolationScope().getScopeData().tags).toEqual({});

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

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

describe('automatically adds integrations', () => {
Expand Down
14 changes: 6 additions & 8 deletions packages/astro/test/server/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as SentryNode from '@sentry/node';
import { SDK_VERSION } from '@sentry/node';
import { GLOBAL_OBJ } from '@sentry/utils';
import { vi } from 'vitest';

import { init } from '../../src/server/sdk';
Expand All @@ -11,7 +10,10 @@ describe('Sentry server SDK', () => {
describe('init', () => {
afterEach(() => {
vi.clearAllMocks();
GLOBAL_OBJ.__SENTRY__.hub = undefined;

SentryNode.getGlobalScope().clear();
SentryNode.getIsolationScope().clear();
SentryNode.getCurrentScope().clear();
});

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

it('sets the runtime tag on the isolation scope', () => {
const isolationScope = SentryNode.getIsolationScope();

// @ts-expect-error need access to protected _tags attribute
expect(isolationScope._tags).toEqual({});
expect(SentryNode.getIsolationScope().getScopeData().tags).toEqual({});

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

// @ts-expect-error need access to protected _tags attribute
expect(isolationScope._tags).toEqual({ runtime: 'node' });
expect(SentryNode.getIsolationScope().getScopeData().tags).toEqual({ runtime: 'node' });
});
});
});
10 changes: 4 additions & 6 deletions packages/nextjs/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { applySdkMetadata, hasTracingEnabled } from '@sentry/core';
import { addEventProcessor, applySdkMetadata, hasTracingEnabled, setTag } from '@sentry/core';
import type { BrowserOptions } from '@sentry/react';
import {
DEFAULT_TRACE_PROPAGATION_TARGETS,
getCurrentScope,
getDefaultIntegrations as getReactDefaultIntegrations,
init as reactInit,
} from '@sentry/react';
Expand Down Expand Up @@ -49,15 +48,14 @@ export function init(options: BrowserOptions): void {

reactInit(opts);

const scope = getCurrentScope();
scope.setTag('runtime', 'browser');
setTag('runtime', 'browser');
const filterTransactions: EventProcessor = event =>
event.type === 'transaction' && event.transaction === '/404' ? null : event;
filterTransactions.id = 'NextClient404Filter';
scope.addEventProcessor(filterTransactions);
addEventProcessor(filterTransactions);

if (process.env.NODE_ENV === 'development') {
scope.addEventProcessor(devErrorSymbolicationEventProcessor);
addEventProcessor(devErrorSymbolicationEventProcessor);
}
}

Expand Down
18 changes: 6 additions & 12 deletions packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { addTracingExtensions, applySdkMetadata, getClient } from '@sentry/core';
import { addEventProcessor, addTracingExtensions, applySdkMetadata, getClient, setTag } from '@sentry/core';
import type { NodeOptions } from '@sentry/node';
import {
Integrations as OriginalIntegrations,
getCurrentScope,
getDefaultIntegrations,
init as nodeInit,
} from '@sentry/node';
import { Integrations as OriginalIntegrations, getDefaultIntegrations, init as nodeInit } from '@sentry/node';
import type { EventProcessor } from '@sentry/types';
import { logger } from '@sentry/utils';

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

filterTransactions.id = 'NextServer404TransactionFilter';

const scope = getCurrentScope();
scope.setTag('runtime', 'node');
setTag('runtime', 'node');
if (IS_VERCEL) {
scope.setTag('vercel', true);
setTag('vercel', true);
}

scope.addEventProcessor(filterTransactions);
addEventProcessor(filterTransactions);

if (process.env.NODE_ENV === 'development') {
scope.addEventProcessor(devErrorSymbolicationEventProcessor);
addEventProcessor(devErrorSymbolicationEventProcessor);
}

DEBUG_BUILD && logger.log('SDK successfully initialized');
Expand Down
17 changes: 8 additions & 9 deletions packages/nextjs/test/clientSdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseClient } from '@sentry/core';
import { BaseClient, getGlobalScope, getIsolationScope } from '@sentry/core';
import * as SentryReact from '@sentry/react';
import type { BrowserClient } from '@sentry/react';
import { WINDOW, getClient, getCurrentScope } from '@sentry/react';
Expand Down Expand Up @@ -36,7 +36,10 @@ const TEST_DSN = 'https://[email protected]/1337';
describe('Client init()', () => {
afterEach(() => {
jest.clearAllMocks();
WINDOW.__SENTRY__.hub = undefined;

getGlobalScope().clear();
getIsolationScope().clear();
getCurrentScope().clear();
});

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

it('sets runtime on scope', () => {
const currentScope = getCurrentScope();

// @ts-expect-error need access to protected _tags attribute
expect(currentScope._tags).toEqual({});
expect(SentryReact.getIsolationScope().getScopeData().tags).toEqual({});

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

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

it('adds 404 transaction filter', () => {
Expand Down
18 changes: 9 additions & 9 deletions packages/nextjs/test/serverSdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ function findIntegrationByName(integrations: Integration[] = [], name: string):
describe('Server init()', () => {
afterEach(() => {
jest.clearAllMocks();
// @ts-expect-error for testing
delete GLOBAL_OBJ.__SENTRY__;

SentryNode.getGlobalScope().clear();
SentryNode.getIsolationScope().clear();
SentryNode.getCurrentScope().clear();

GLOBAL_OBJ.__SENTRY__.hub = undefined;
delete process.env.VERCEL;
});

Expand Down Expand Up @@ -68,15 +72,11 @@ describe('Server init()', () => {
});

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

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

init({});

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

// TODO: test `vercel` tag when running on Vercel
Expand Down
6 changes: 3 additions & 3 deletions packages/remix/src/index.client.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { applySdkMetadata } from '@sentry/core';
import { getCurrentScope, init as reactInit } from '@sentry/react';
import { applySdkMetadata, setTag } from '@sentry/core';
import { init as reactInit } from '@sentry/react';
import type { RemixOptions } from './utils/remixOptions';
export { captureRemixErrorBoundaryError } from './client/errors';
export {
Expand All @@ -22,5 +22,5 @@ export function init(options: RemixOptions): void {

reactInit(opts);

getCurrentScope().setTag('runtime', 'browser');
setTag('runtime', 'browser');
}
5 changes: 2 additions & 3 deletions packages/remix/src/index.server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { applySdkMetadata } from '@sentry/core';
import type { NodeOptions } from '@sentry/node';
import { getClient } from '@sentry/node';
import { getCurrentScope, init as nodeInit } from '@sentry/node';
import { getClient, init as nodeInit, setTag } from '@sentry/node';
import { logger } from '@sentry/utils';

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

nodeInit(options as NodeOptions);

getCurrentScope().setTag('runtime', 'node');
setTag('runtime', 'node');
}
17 changes: 7 additions & 10 deletions packages/remix/test/index.client.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { getCurrentScope } from '@sentry/core';
import * as SentryReact from '@sentry/react';
import { GLOBAL_OBJ } from '@sentry/utils';

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

Expand All @@ -9,7 +7,10 @@ const reactInit = jest.spyOn(SentryReact, 'init');
describe('Client init()', () => {
afterEach(() => {
jest.clearAllMocks();
GLOBAL_OBJ.__SENTRY__.hub = undefined;

SentryReact.getGlobalScope().clear();
SentryReact.getIsolationScope().clear();
SentryReact.getCurrentScope().clear();
});

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

it('sets runtime on scope', () => {
const currentScope = getCurrentScope();

// @ts-expect-error need access to protected _tags attribute
expect(currentScope._tags).toEqual({});
expect(SentryReact.getIsolationScope().getScopeData().tags).toEqual({});

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

// @ts-expect-error need access to protected _tags attribute
expect(currentScope._tags).toEqual({ runtime: 'browser' });
expect(SentryReact.getIsolationScope().getScopeData().tags).toEqual({ runtime: 'browser' });
});
});
15 changes: 8 additions & 7 deletions packages/remix/test/index.server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const nodeInit = jest.spyOn(SentryNode, 'init');
describe('Server init()', () => {
afterEach(() => {
jest.clearAllMocks();

SentryNode.getGlobalScope().clear();
SentryNode.getIsolationScope().clear();
SentryNode.getCurrentScope().clear();

GLOBAL_OBJ.__SENTRY__.hub = undefined;
});

Expand Down Expand Up @@ -46,15 +51,11 @@ describe('Server init()', () => {
});

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

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

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

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

it('has both node and tracing integrations', () => {
Expand Down
23 changes: 14 additions & 9 deletions packages/sveltekit/test/client/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { getClient, getIsolationScope } from '@sentry/core';
import type { BrowserClient } from '@sentry/svelte';
import * as SentrySvelte from '@sentry/svelte';
import { SDK_VERSION, WINDOW, browserTracingIntegration } from '@sentry/svelte';
import {
SDK_VERSION,
browserTracingIntegration,
getClient,
getCurrentScope,
getGlobalScope,
getIsolationScope,
} from '@sentry/svelte';
import { vi } from 'vitest';

import { BrowserTracing, init } from '../../src/client';
Expand All @@ -13,7 +19,10 @@ describe('Sentry client SDK', () => {
describe('init', () => {
afterEach(() => {
vi.clearAllMocks();
WINDOW.__SENTRY__.hub = undefined;

getGlobalScope().clear();
getIsolationScope().clear();
getCurrentScope().clear();
});

it('adds SvelteKit metadata to the SDK options', () => {
Expand All @@ -39,15 +48,11 @@ describe('Sentry client SDK', () => {
});

it('sets the runtime tag on the isolation scope', () => {
const isolationScope = getIsolationScope();

// @ts-expect-error need access to protected _tags attribute
expect(isolationScope._tags).toEqual({});
expect(getIsolationScope().getScopeData().tags).toEqual({});

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

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

describe('automatically added integrations', () => {
Expand Down
14 changes: 6 additions & 8 deletions packages/sveltekit/test/server/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as SentryNode from '@sentry/node';
import type { NodeClient } from '@sentry/node';
import { SDK_VERSION, getClient } from '@sentry/node';
import { GLOBAL_OBJ } from '@sentry/utils';

import { init } from '../../src/server/sdk';

Expand All @@ -11,7 +10,10 @@ describe('Sentry server SDK', () => {
describe('init', () => {
afterEach(() => {
vi.clearAllMocks();
GLOBAL_OBJ.__SENTRY__.hub = undefined;

SentryNode.getGlobalScope().clear();
SentryNode.getIsolationScope().clear();
SentryNode.getCurrentScope().clear();
});

it('adds SvelteKit metadata to the SDK options', () => {
Expand All @@ -37,15 +39,11 @@ describe('Sentry server SDK', () => {
});

it('sets the runtime tag on the isolation scope', () => {
const isolationScope = SentryNode.getIsolationScope();

// @ts-expect-error need access to protected _tags attribute
expect(isolationScope._tags).toEqual({});
expect(SentryNode.getIsolationScope().getScopeData().tags).toEqual({});

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

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

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