Skip to content

Commit 22ebb3b

Browse files
authored
ref(core): Skip hub in top level captureXXX methods (#10688)
Directly call these on `getCurrentScope()` instead.
1 parent 9c21df4 commit 22ebb3b

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

packages/core/src/exports.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ export function captureException(
4141
exception: any,
4242
hint?: ExclusiveEventHintOrCaptureContext,
4343
): string {
44-
// eslint-disable-next-line deprecation/deprecation
45-
return getCurrentHub().captureException(exception, parseEventHintOrCaptureContext(hint));
44+
return getCurrentScope().captureException(exception, parseEventHintOrCaptureContext(hint));
4645
}
4746

4847
/**
@@ -57,8 +56,7 @@ export function captureMessage(message: string, captureContext?: CaptureContext
5756
// arity of the `captureMessage(message, level)` method.
5857
const level = typeof captureContext === 'string' ? captureContext : undefined;
5958
const context = typeof captureContext !== 'string' ? { captureContext } : undefined;
60-
// eslint-disable-next-line deprecation/deprecation
61-
return getCurrentHub().captureMessage(message, level, context);
59+
return getCurrentScope().captureMessage(message, level, context);
6260
}
6361

6462
/**
@@ -69,8 +67,7 @@ export function captureMessage(message: string, captureContext?: CaptureContext
6967
* @returns the id of the captured event.
7068
*/
7169
export function captureEvent(event: Event, hint?: EventHint): string {
72-
// eslint-disable-next-line deprecation/deprecation
73-
return getCurrentHub().captureEvent(event, hint);
70+
return getCurrentScope().captureEvent(event, hint);
7471
}
7572

7673
/**

packages/node/test/onunhandledrejection.test.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
1-
import { Hub } from '@sentry/core';
2-
import type { NodeClient } from '../src/client';
1+
import * as SentryCore from '@sentry/core';
2+
import type { Client } from '@sentry/types';
33

44
import { makeUnhandledPromiseHandler, onUnhandledRejectionIntegration } from '../src/integrations/onunhandledrejection';
55

66
// don't log the test errors we're going to throw, so at a quick glance it doesn't look like the test itself has failed
77
global.console.warn = () => null;
88
global.console.error = () => null;
99

10-
const client = { getOptions: () => ({}) } as unknown as NodeClient;
11-
12-
jest.mock('@sentry/core', () => {
13-
// we just want to short-circuit it, so dont worry about types
14-
const original = jest.requireActual('@sentry/core');
15-
return {
16-
...original,
17-
getClient: () => client,
18-
};
19-
});
20-
2110
describe('unhandled promises', () => {
2211
test('install global listener', () => {
12+
const client = { getOptions: () => ({}) } as unknown as Client;
13+
SentryCore.setCurrentClient(client);
14+
2315
const integration = onUnhandledRejectionIntegration();
2416
integration.setup!(client);
2517
expect(process.listeners('unhandledRejection')).toHaveLength(1);
2618
});
2719

2820
test('makeUnhandledPromiseHandler', () => {
21+
const client = { getOptions: () => ({}) } as unknown as Client;
22+
SentryCore.setCurrentClient(client);
23+
2924
const promise = {
3025
domain: {
3126
sentryContext: {
@@ -36,15 +31,15 @@ describe('unhandled promises', () => {
3631
},
3732
};
3833

39-
const captureException = jest.spyOn(Hub.prototype, 'captureException');
34+
const captureException = jest.spyOn(SentryCore, 'captureException').mockImplementation(() => 'test');
4035

4136
const handler = makeUnhandledPromiseHandler(client, {
4237
mode: 'warn',
4338
});
4439

4540
handler('bla', promise);
4641

47-
expect(captureException.mock.calls[0][1]).toEqual({
42+
expect(captureException).toHaveBeenCalledWith('bla', {
4843
originalException: {
4944
domain: {
5045
sentryContext: {

0 commit comments

Comments
 (0)