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
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ sentryTest('it does not download the SDK if the SDK was loaded in the meanwhile'
expect(sentryEventCount).toBe(1);

// Ensure loader does not overwrite init/config
const options = await page.evaluate(() => (window as any).Sentry.getCurrentHub().getClient()?.getOptions());
const options = await page.evaluate(() => (window as any).Sentry.getClient()?.getOptions());
expect(options?.replaysSessionSampleRate).toBe(0.42);

expect(eventData.exception?.values?.length).toBe(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sentryTest('should handle custom added BrowserTracing integration', async ({ get
expect(eventData.transaction_info?.source).toEqual('url');

const tracePropagationTargets = await page.evaluate(() => {
const browserTracing = (window as any).Sentry.getCurrentHub().getClient().getIntegrationById('BrowserTracing');
const browserTracing = (window as any).Sentry.getClient().getIntegrationById('BrowserTracing');
return browserTracing.options.tracePropagationTargets;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ sentryTest('always calls onLoad init correctly', async ({ getLocalTestUrl, page

expect(await page.evaluate('window.__hadSentry')).toEqual(false);
expect(await page.evaluate('window.__sentryOnLoad')).toEqual(1);
expect(await page.evaluate('Sentry.getCurrentHub().getClient().getOptions().sampleRate')).toEqual(0.5);
expect(await page.evaluate('Sentry.getClient().getOptions().sampleRate')).toEqual(0.5);
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ sentryTest('should handle custom added integrations & default integrations', asy
});

const hasCustomIntegration = await page.evaluate(() => {
return !!(window as any).Sentry.getCurrentHub().getClient().getIntegrationById('CustomIntegration');
return !!(window as any).Sentry.getClient().getIntegrationById('CustomIntegration');
});

const hasReplay = await page.evaluate(() => {
return !!(window as any).Sentry.getCurrentHub().getClient().getIntegrationById('Replay');
return !!(window as any).Sentry.getClient().getIntegrationById('Replay');
});
const hasBrowserTracing = await page.evaluate(() => {
return !!(window as any).Sentry.getCurrentHub().getClient().getIntegrationById('BrowserTracing');
return !!(window as any).Sentry.getClient().getIntegrationById('BrowserTracing');
});

expect(hasCustomIntegration).toEqual(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ sentryTest(
});

const hasCustomIntegration = await page.evaluate(() => {
return !!(window as any).Sentry.getCurrentHub().getClient().getIntegrationById('CustomIntegration');
return !!(window as any).Sentry.getClient().getIntegrationById('CustomIntegration');
});

const hasReplay = await page.evaluate(() => {
return !!(window as any).Sentry.getCurrentHub().getClient().getIntegrationById('Replay');
return !!(window as any).Sentry.getClient().getIntegrationById('Replay');
});
const hasBrowserTracing = await page.evaluate(() => {
return !!(window as any).Sentry.getCurrentHub().getClient().getIntegrationById('BrowserTracing');
return !!(window as any).Sentry.getClient().getIntegrationById('BrowserTracing');
});

expect(hasCustomIntegration).toEqual(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sentryTest('should handle custom added Replay integration', async ({ getLocalTes
expect(eventData.segment_id).toBe(0);

const useCompression = await page.evaluate(() => {
const replay = (window as any).Sentry.getCurrentHub().getClient().getIntegrationById('Replay');
const replay = (window as any).Sentry.getClient().getIntegrationById('Replay');
return replay._replay.getOptions().useCompression;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ sentryTest('sentryOnLoad callback is called before Sentry.onLoad()', async ({ ge

expect(eventData.message).toBe('Test exception');

expect(await page.evaluate('Sentry.getCurrentHub().getClient().getOptions().tracesSampleRate')).toEqual(0.123);
expect(await page.evaluate('Sentry.getClient().getOptions().tracesSampleRate')).toEqual(0.123);
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Sentry.onLoad(function () {
// this should be called _after_ window.sentryOnLoad
Sentry.captureException(`Test exception: ${Sentry.getCurrentHub().getClient().getOptions().tracesSampleRate}`);
Sentry.captureException(`Test exception: ${Sentry.getClient().getOptions().tracesSampleRate}`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ sentryTest('sentryOnLoad callback is used', async ({ getLocalTestUrl, page }) =>

expect(eventData.message).toBe('Test exception: 0.123');

expect(await page.evaluate('Sentry.getCurrentHub().getClient().getOptions().tracesSampleRate')).toEqual(0.123);
expect(await page.evaluate('Sentry.getClient().getOptions().tracesSampleRate')).toEqual(0.123);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
// eslint-disable-next-line deprecation/deprecation
const transaction = Sentry.startTransaction({ name: 'test-transaction', op: 'e2e-test' });
// eslint-disable-next-line deprecation/deprecation
Sentry.getCurrentHub().getScope().setSpan(transaction);
Sentry.getCurrentScope().setSpan(transaction);

// eslint-disable-next-line deprecation/deprecation
const span = transaction.startChild();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ app.use(cors());

app.get('/test/express', (_req, res) => {
// eslint-disable-next-line deprecation/deprecation
const transaction = Sentry.getCurrentHub().getScope().getTransaction();
const transaction = Sentry.getCurrentScope().getTransaction();
if (transaction) {
// eslint-disable-next-line deprecation/deprecation
transaction.traceId = '86f39e84263a4de99c326acab3bfe3bd';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ app.use(cors());

app.get('/test/express', (_req, res) => {
// eslint-disable-next-line deprecation/deprecation
const transaction = Sentry.getCurrentHub().getScope().getTransaction();
const transaction = Sentry.getCurrentScope().getTransaction();
if (transaction) {
// eslint-disable-next-line deprecation/deprecation
transaction.traceId = '86f39e84263a4de99c326acab3bfe3bd';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ app.use(Sentry.Handlers.requestHandler());

// ### Taken from manual tests ###
// Hack that resets the 60s default flush interval, and replaces it with just a one second interval
const flusher = (Sentry.getCurrentHub()?.getClient() as Sentry.NodeClient)['_sessionFlusher'] as SessionFlusher;
const flusher = (Sentry.getClient() as Sentry.NodeClient)['_sessionFlusher'] as SessionFlusher;

let flusherIntervalId = flusher && flusher['_intervalId'];

Expand Down
5 changes: 3 additions & 2 deletions packages/astro/test/client/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { BrowserClient } from '@sentry/browser';
import { getCurrentScope } from '@sentry/browser';
import * as SentryBrowser from '@sentry/browser';
import { BrowserTracing, SDK_VERSION, WINDOW, getClient, getCurrentHub } from '@sentry/browser';
import { BrowserTracing, SDK_VERSION, WINDOW, getClient } from '@sentry/browser';
import { vi } from 'vitest';

import { init } from '../../../astro/src/client/sdk';
Expand Down Expand Up @@ -37,7 +38,7 @@ describe('Sentry client SDK', () => {
});

it('sets the runtime tag on the scope', () => {
const currentScope = getCurrentHub().getScope();
const currentScope = getCurrentScope();

// @ts-expect-error need access to protected _tags attribute
expect(currentScope._tags).toEqual({});
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/test/server/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getCurrentHub } from '@sentry/core';
import * as SentryNode from '@sentry/node';
import { SDK_VERSION } from '@sentry/node';
import { GLOBAL_OBJ } from '@sentry/utils';
Expand Down Expand Up @@ -38,7 +37,7 @@ describe('Sentry server SDK', () => {
});

it('sets the runtime tag on the scope', () => {
const currentScope = getCurrentHub().getScope();
const currentScope = SentryNode.getCurrentScope();

// @ts-expect-error need access to protected _tags attribute
expect(currentScope._tags).toEqual({});
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 @@ -167,6 +167,7 @@ export const showReportDialog: ShowReportDialogFunction = (
return;
}

// eslint-disable-next-line deprecation/deprecation
const { client, scope } = hub.getStackTop();
const dsn = options.dsn || (client && client.getDsn());
if (!dsn) {
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/test/unit/profiling/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('BrowserProfilingIntegration', () => {
const client = Sentry.getClient<BrowserClient>();

// eslint-disable-next-line deprecation/deprecation
const currentTransaction = Sentry.getCurrentHub().getScope().getTransaction();
const currentTransaction = Sentry.getCurrentScope().getTransaction();
expect(currentTransaction?.op).toBe('pageload');
currentTransaction?.end();
await client?.flush(1000);
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export function configureScope(callback: (scope: Scope) => void): ReturnType<Hub
* @param breadcrumb The breadcrumb to record.
*/
export function addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): ReturnType<Hub['addBreadcrumb']> {
// eslint-disable-next-line deprecation/deprecation
getCurrentHub().addBreadcrumb(breadcrumb, hint);
}

Expand All @@ -109,6 +110,7 @@ export function addBreadcrumb(breadcrumb: Breadcrumb, hint?: BreadcrumbHint): Re
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function setContext(name: string, context: { [key: string]: any } | null): ReturnType<Hub['setContext']> {
// eslint-disable-next-line deprecation/deprecation
getCurrentHub().setContext(name, context);
}

Expand All @@ -117,6 +119,7 @@ export function setContext(name: string, context: { [key: string]: any } | null)
* @param extras Extras object to merge into current context.
*/
export function setExtras(extras: Extras): ReturnType<Hub['setExtras']> {
// eslint-disable-next-line deprecation/deprecation
getCurrentHub().setExtras(extras);
}

Expand All @@ -126,6 +129,7 @@ export function setExtras(extras: Extras): ReturnType<Hub['setExtras']> {
* @param extra Any kind of data. This data will be normalized.
*/
export function setExtra(key: string, extra: Extra): ReturnType<Hub['setExtra']> {
// eslint-disable-next-line deprecation/deprecation
getCurrentHub().setExtra(key, extra);
}

Expand All @@ -134,6 +138,7 @@ export function setExtra(key: string, extra: Extra): ReturnType<Hub['setExtra']>
* @param tags Tags context object to merge into current context.
*/
export function setTags(tags: { [key: string]: Primitive }): ReturnType<Hub['setTags']> {
// eslint-disable-next-line deprecation/deprecation
getCurrentHub().setTags(tags);
}

Expand All @@ -146,6 +151,7 @@ export function setTags(tags: { [key: string]: Primitive }): ReturnType<Hub['set
* @param value Value of tag
*/
export function setTag(key: string, value: Primitive): ReturnType<Hub['setTag']> {
// eslint-disable-next-line deprecation/deprecation
getCurrentHub().setTag(key, value);
}

Expand All @@ -155,6 +161,7 @@ export function setTag(key: string, value: Primitive): ReturnType<Hub['setTag']>
* @param user User context object to be set in the current context. Pass `null` to unset the user.
*/
export function setUser(user: User | null): ReturnType<Hub['setUser']> {
// eslint-disable-next-line deprecation/deprecation
getCurrentHub().setUser(user);
}

Expand Down Expand Up @@ -184,16 +191,20 @@ export function withScope<T>(
if (rest.length === 2) {
const [scope, callback] = rest;
if (!scope) {
// eslint-disable-next-line deprecation/deprecation
return getCurrentHub().withScope(callback);
}

const hub = getCurrentHub();
// eslint-disable-next-line deprecation/deprecation
return hub.withScope(() => {
// eslint-disable-next-line deprecation/deprecation
hub.getStackTop().scope = scope as Scope;
return callback(scope as Scope);
});
}

// eslint-disable-next-line deprecation/deprecation
return getCurrentHub().withScope(rest[0]);
}

Expand Down Expand Up @@ -332,20 +343,23 @@ export async function close(timeout?: number): Promise<boolean> {
* @deprecated This function will be removed in the next major version of the Sentry SDK.
*/
export function lastEventId(): string | undefined {
// eslint-disable-next-line deprecation/deprecation
return getCurrentHub().lastEventId();
}

/**
* Get the currently active client.
*/
export function getClient<C extends Client>(): C | undefined {
// eslint-disable-next-line deprecation/deprecation
return getCurrentHub().getClient<C>();
}

/**
* Get the currently active scope.
*/
export function getCurrentScope(): Scope {
// eslint-disable-next-line deprecation/deprecation
return getCurrentHub().getScope();
}

Expand Down
Loading