8000 ref: Rename getDefaultHub to getCurrentHub (#1457) · lordnox/sentry-javascript@d672d89 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit d672d89

Browse files
authored
ref: Rename getDefaultHub to getCurrentHub (getsentry#1457)
1 parent f52bd29 commit d672d89

File tree

23 files changed

+121
-121
lines changed

23 files changed

+121
-121
lines changed

packages/browser/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export {
1515

1616
export { addBreadcrumb, captureMessage, captureException, captureEvent, configureScope } from '@sentry/minimal';
1717

18-
export { getHubFromCarrier, getDefaultHub, Hub, Scope } from '@sentry/hub';
18+
export { getHubFromCarrier, getCurrentHub, Hub, Scope } from '@sentry/hub';
1919

2020
export { BrowserBackend, BrowserOptions } from './backend';
2121
export { BrowserClient } from './client';

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDefaultHub } from '@sentry/hub';
1+
import { getCurrentHub } from '@sentry/hub';
22
import { Integration, Severity } from '@sentry/types';
33
import { isFunction, isString } from '@sentry/utils/is';
44
import { getGlobalObject, parseUrl } from '@sentry/utils/misc';
@@ -87,7 +87,7 @@ export class Breadcrumbs implements Integration {
8787
}
8888
}
8989

90-
getDefaultHub().addBreadcrumb(breadcrumbData);
90+
getCurrentHub().addBreadcrumb(breadcrumbData);
9191

9292
// this fails for some browsers. :(
9393
if (originalConsoleLevel) {
@@ -148,15 +148,15 @@ export class Breadcrumbs implements Integration {
148148
.apply(global, args)
149149
.then((response: Response) => {
150150
fetchData.status_code = response.status;
151-
getDefaultHub().addBreadcrumb({
151+
getCurrentHub().addBreadcrumb({
152152
category: 'fetch',
153153
data: fetchData,
154154
type: 'http',
155155
});
156156
return response;
157157
})
158158
.catch((error: Error) => {
159-
getDefaultHub().addBreadcrumb({
159+
getCurrentHub().addBreadcrumb({
160160
category: 'fetch',
161161
data: fetchData,
162162
level: Severity.Error,
@@ -196,7 +196,7 @@ export class Breadcrumbs implements Integration {
196196
from = parsedFrom.relative;
197197
}
198198

199-
getDefaultHub().addBreadcrumb({
199+
getCurrentHub().addBreadcrumb({
200200
category: 'navigation',
201201
data: {
202202
from,
@@ -290,7 +290,7 @@ export class Breadcrumbs implements Integration {
290290
} catch (e) {
291291
/* do nothing */
292292
}
293-
getDefaultHub().addBreadcrumb({
293+
getCurrentHub().addBreadcrumb({
294294
category: 'xhr',
295295
data: xhr.__sentry_xhr__,
296296
type: 'http',

packages/browser/src/integrations/helpers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDefaultHub } from '@sentry/hub';
1+
import { getCurrentHub } from '@sentry/hub';
22
import { SentryEvent, SentryWrappedFunction } from '@sentry/types';
33
import { isFunction } from '@sentry/utils/is';
44
import { htmlTreeAsString } from '@sentry/utils/misc';
@@ -64,13 +64,13 @@ export function wrap(
6464
} catch (ex) {
6565
ignoreNextOnError();
6666

67-
getDefaultHub().withScope(async () => {
68-
getDefaultHub().addEventProcessor(async (event: SentryEvent) => ({
67+
getCurrentHub().withScope(async () => {
68+
getCurrentHub().addEventProcessor(async (event: SentryEvent) => ({
6969
...event,
7070
...(options && options.mechanism),
7171
}));
7272

73-
getDefaultHub().captureException(ex);
73+
getCurrentHub().captureException(ex);
7474
});
7575

7676
throw ex;
@@ -126,7 +126,7 @@ export function breadcrumbEventHandler(eventName: string): (event: Event) => voi
126126
target = '<unknown>';
127127
}
128128

129-
getDefaultHub().addBreadcrumb({
129+
getCurrentHub().addBreadcrumb({
130130
category: `ui.${eventName}`, // e.g. ui.click, ui.input
131131
message: target,
132132
});

packages/browser/src/integrations/inboundfilters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { logger } from '@sentry/core';
2-
import { getDefaultHub } from '@sentry/hub';
2+
import { getCurrentHub } from '@sentry/hub';
33
import { Integration, SentryEvent } from '@sentry/types';
44
import { isRegExp } from '@sentry/utils/is';
55
import { BrowserOptions } from '../backend';
@@ -27,7 +27,7 @@ export class InboundFilters implements Integration {
2727
public install(options: BrowserOptions = {}): void {
2828
this.configureOptions(options);
2929

30-
getDefaultHub().addEventProcessor(async (event: SentryEvent) => {
30+
getCurrentHub().addEventProcessor(async (event: SentryEvent) => {
3131
if (this.shouldDropEvent(event)) {
3232
return null;
3333
}

packages/browser/src/integrations/sdkinformation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDefaultHub } from '@sentry/hub';
1+
import { getCurrentHub } from '@sentry/hub';
22
import { Integration, SentryEvent } from '@sentry/types';
33
import { SDK_NAME, SDK_VERSION } from '../version';
44

@@ -13,7 +13,7 @@ export class SDKInformation implements Integration {
1313
* @inheritDoc
1414
*/
1515
public install(): void {
16-
getDefaultHub().addEventProcessor(async (event: SentryEvent) => ({
16+
getCurrentHub().addEventProcessor(async (event: SentryEvent) => ({
1717
...event,
1818
sdk: {
1919
name: SDK_NAME,

packages/browser/test/index.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
captureException,
99
captureMessage,
1010
configureScope,
11-
getDefaultHub,
11+
getCurrentHub,
1212
init,
1313
Scope,
1414
SentryEvent,
@@ -24,11 +24,11 @@ describe('SentryBrowser', () => {
2424
});
2525

2626
beforeEach(() => {
27-
getDefaultHub().pushScope();
27+
getCurrentHub().pushScope();
2828
});
2929

3030
afterEach(() => {
31-
getDefaultHub().popScope();
31+
getCurrentHub().popScope();
3232
});
3333

3434
describe('getContext() / setContext()', () => {
@@ -72,8 +72,8 @@ describe('SentryBrowser', () => {
7272
});
7373

7474
it('should record auto breadcrumbs', done => {
75-
getDefaultHub().pushScope();
76-
getDefaultHub().bindClient(
75+
getCurrentHub().pushScope();
76+
getCurrentHub().bindClient(
7777
new BrowserClient({
7878
afterSend: (event: SentryEvent) => {
7979
expect(event.breadcrumbs!).to.have.lengthOf(2);
@@ -87,7 +87,7 @@ describe('SentryBrowser', () => {
8787
addBreadcrumb({ message: 'test2' });
8888

8989
captureMessage('event');
90-
getDefaultHub().popScope();
90+
getCurrentHub().popScope();
9191
});
9292
});
9393

@@ -103,8 +103,8 @@ describe('SentryBrowser', () => {
103103
});
104104

105105
it('should capture an exception', done => {
106-
getDefaultHub().pushScope();
107-
getDefaultHub().bindClient(
106+
getCurrentHub().pushScope();
107+
getCurrentHub().bindClient(
108108
new BrowserClient({
109109
afterSend: (event: SentryEvent) => {
110110
expect(event.exception).to.not.be.undefined;
@@ -122,12 +122,12 @@ describe('SentryBrowser', () => {
122122
} catch (e) {
123123
captureException(e);
124124
}
125-
getDefaultHub().popScope();
125+
getCurrentHub().popScope();
126126
});
127127

128128
it('should capture a message', done => {
129-
getDefaultHub().pushScope();
130-
getDefaultHub().bindClient(
129+
getCurrentHub().pushScope();
130+
getCurrentHub().bindClient(
131131
new BrowserClient({
132132
afterSend: (event: SentryEvent) => {
133133
expect(event.message).to.equal('test');
@@ -138,12 +138,12 @@ describe('SentryBrowser', () => {
138138
}),
139139
);
140140
captureMessage('test');
141-
getDefaultHub().popScope();
141+
getCurrentHub().popScope();
142142
});
143143

144144
it('should capture an event', done => {
145-
getDefaultHub().pushScope();
146-
getDefaultHub().bindClient(
145+
getCurrentHub().pushScope();
146+
getCurrentHub().bindClient(
147147
new BrowserClient({
148148
afterSend: (event: SentryEvent) => {
149149
expect(event.message).to.equal('test');
@@ -154,7 +154,7 @@ describe('SentryBrowser', () => {
154154
}),
155155
);
156156
captureEvent({ message: 'test' });
157-
getDefaultHub().popScope();
157+
getCurrentHub().popScope();
158158
});
159159
});
160160
});

packages/core/src/sdk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDefaultHub } from '@sentry/hub';
1+
import { getCurrentHub } from '@sentry/hub';
22
import { Integration } from '@sentry/types';
33
import { Client, Options } from './interfaces';
44
import { logger } from './logger';
@@ -21,7 +21,7 @@ export function initAndBind<F extends Client, O extends Options>(
2121
options: O,
2222
defaultIntegrations: Integration[] = [],
2323
): void {
24-
if (getDefaultHub().getClient()) {
24+
if (getCurrentHub().getClient()) {
2525
return;
2626
}
2727

@@ -34,7 +34,7 @@ export function initAndBind<F extends Client, O extends Options>(
3434

3535
// This should happen here if any integration uses {@link Hub.addEventProcessor}
3636
// there needs to be a client on the hub already.
37-
getDefaultHub().bindClient(client);
37+
getCurrentHub().bindClient(client);
3838

3939
let integrations = [...defaultIntegrations];
4040
if (Array.isArray(options.integrations)) {

packages/hub/src/global.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function getMainCarrier(): Carrier {
1818
* contains a more recent version, it replaces the registered version.
1919
* Otherwise, the currently registered hub will be returned.
2020
*/
21-
export function getDefaultHub(): Hub {
21+
export function getCurrentHub(): Hub {
2222
const registry = getMainCarrier();
2323

2424
if (!registry.hub || registry.hub.isOlderThan(API_VERSION)) {

packages/hub/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { Carrier, Layer } from './interfaces';
22
export { Scope } from './scope';
33
export { Hub } from './hub';
4-
export { getDefaultHub, getHubFromCarrier } from './global';
4+
export { getCurrentHub, getHubFromCarrier } from './global';

packages/hub/test/lib/global.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getDefaultHub, getHubFromCarrier, Hub } from '../../src';
1+
import { getCurrentHub, getHubFromCarrier, Hub } from '../../src';
22

33
describe('global', () => {
44
test('getGlobalHub', () => {
5-
expect(getDefaultHub()).toBeTruthy();
5+
expect(getCurrentHub()).toBeTruthy();
66
expect((global as any).__SENTRY__.hub).toBeTruthy();
77
});
88

@@ -17,6 +17,6 @@ describe('global', () => {
1717
test('getGlobalHub', () => {
1818
const newestHub = new Hub(undefined, [], 999999);
1919
(global as any).__SENTRY__.hub = newestHub;
20-
expect(getDefaultHub()).toBe(newestHub);
20+
expect(getCurrentHub()).toBe(newestHub);
2121
});
2222
});

packages/minimal/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDefaultHub, Hub, Scope } from '@sentry/hub';
1+
import { getCurrentHub, Hub, Scope } from '@sentry/hub';
22
import { Breadcrumb, SentryEvent } from '@sentry/types';
33

44
/**
@@ -7,7 +7,7 @@ import { Breadcrumb, SentryEvent } from '@sentry/types';
77
* @param args to pass to function.
88
*/
99
function callOnHub(method: string, ...args: any[]): void {
10-
const hub = getDefaultHub();
10+
const hub = getCurrentHub();
1111
if (hub && hub[method as keyof Hub]) {
1212
(hub[method as keyof Hub] as any)(...args);
1313
}

0 commit comments

Comments
 (0)
0