Skip to content

Commit 8570f0d

Browse files
timfishAbhiPrasad
andauthored
ref(hub): Move @sentry/hub code to @sentry/core (#5823)
This PR: - Moves all of the `@sentry/hub` code files to `@sentry/core` - Changes `@sentry/hub` to a stub that re-exports the same types from `@sentry/core` - `@sentry/hub` now only depends on `@sentry/core` - Switches internal imports `@sentry/hub` -> `@sentry/core` - Removes `@sentry/hub` as a dependency from packages - Fixes all the mocks/spys/imports in tests - Leaves the `@sentry/hub` tests where they are for now Co-authored-by: Abhijeet Prasad <[email protected]>
1 parent e406130 commit 8570f0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+257
-123
lines changed

packages/browser/test/unit/sdk.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ function getDefaultBrowserOptions(options: Partial<BrowserOptions> = {}): Browse
2121
};
2222
}
2323

24-
jest.mock('@sentry/hub', () => {
25-
const original = jest.requireActual('@sentry/hub');
24+
jest.mock('@sentry/core', () => {
25+
const original = jest.requireActual('@sentry/core');
2626
return {
2727
...original,
2828
getCurrentHub(): {

packages/core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"access": "public"
1717
},
1818
"dependencies": {
19-
"@sentry/hub": "7.14.2",
2019
"@sentry/types": "7.14.2",
2120
"@sentry/utils": "7.14.2",
2221
"tslib": "^1.9.3"

packages/core/src/baseclient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable max-lines */
2-
import { Scope, updateSession } from '@sentry/hub';
32
import {
43
Client,
54
ClientOptions,
@@ -40,6 +39,8 @@ import {
4039
import { getEnvelopeEndpointWithUrlEncodedAuth } from './api';
4140
import { createEventEnvelope, createSessionEnvelope } from './envelope';
4241
import { IntegrationIndex, setupIntegrations } from './integration';
42+
import { Scope } from './scope';
43+
import { updateSession } from './session';
4344

4445
const ALREADY_SEEN_ERROR = "Not capturing exception because it's already been captured.";
4546

File renamed without changes.
File renamed without changes.

packages/core/src/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export type { ClientClass } from './sdk';
2+
export type { Carrier, Layer } from './hub';
23

34
export {
45
addBreadcrumb,
@@ -14,13 +15,11 @@ export {
1415
setTags,
1516
setUser,
1617
withScope,
17-
addGlobalEventProcessor,
18-
getCurrentHub,
19-
getHubFromCarrier,
20-
Hub,
21-
makeMain,
22-
Scope,
23-
} from '@sentry/hub';
18+
} from './exports';
19+
export { getCurrentHub, getHubFromCarrier, Hub, makeMain, getMainCarrier, setHubOnCarrier } from './hub';
20+
export { makeSession, closeSession, updateSession } from './session';
21+
export { SessionFlusher } from './sessionflusher';
22+
export { addGlobalEventProcessor, Scope } from './scope';
2423
export { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from './api';
2524
export { BaseClient } from './baseclient';
2625
export { initAndBind } from './sdk';

packages/core/src/integration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/hub';
21
import { Integration, Options } from '@sentry/types';
32
import { arrayify, logger } from '@sentry/utils';
43

4+
import { getCurrentHub } from './hub';
5+
import { addGlobalEventProcessor } from './scope';
6+
57
declare module '@sentry/types' {
68
interface Integration {
79
isDefaultInstance?: boolean;
File renamed without changes.

packages/core/src/sdk.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { getCurrentHub } from '@sentry/hub';
21
import { Client, ClientOptions } from '@sentry/types';
32
import { logger } from '@sentry/utils';
43

4+
import { getCurrentHub } from './hub';
5+
56
/** A class object that can instantiate Client objects. */
67
export type ClientClass<F extends Client, O extends ClientOptions> = new (options: O) => F;
78

File renamed without changes.

packages/core/test/lib/base.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Hub, makeSession, Scope } from '@sentry/hub';
21
import { Event, Span } from '@sentry/types';
32
import { dsnToString, logger, SentryError, SyncPromise } from '@sentry/utils';
43

4+
import { Hub, makeSession, Scope } from '../../src';
55
import * as integrationModule from '../../src/integration';
66
import { getDefaultTestClientOptions, TestClient } from '../mocks/client';
77
import { TestIntegration } from '../mocks/integration';

packages/core/test/lib/hint.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureEvent, configureScope } from '@sentry/hub';
1+
import { captureEvent, configureScope } from '@sentry/core';
22
import { getGlobalObject } from '@sentry/utils';
33

44
import { initAndBind } from '../../src/sdk';

packages/core/test/lib/sdk.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Scope } from '@sentry/hub';
1+
import { Scope } from '@sentry/core';
22
import { Client, Integration } from '@sentry/types';
33

44
import { installedIntegrations } from '../../src/integration';
@@ -10,8 +10,8 @@ declare var global: any;
1010

1111
const PUBLIC_DSN = 'https://username@domain/123';
1212

13-
jest.mock('@sentry/hub', () => {
14-
const original = jest.requireActual('@sentry/hub');
13+
jest.mock('@sentry/core', () => {
14+
const original = jest.requireActual('@sentry/core');
1515
return {
1616
...original,
1717
getCurrentHub(): {

packages/core/test/mocks/integration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { configureScope, getCurrentHub } from '@sentry/hub';
21
import { Event, EventProcessor, Integration } from '@sentry/types';
32

3+
import { configureScope, getCurrentHub } from '../../src';
4+
45
export class TestIntegration implements Integration {
56
public static id: string = 'TestIntegration';
67

packages/hub/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"access": "public"
1717
},
1818
"dependencies": {
19+
"@sentry/core": "7.14.2",
1920
"@sentry/types": "7.14.2",
2021
"@sentry/utils": "7.14.2",
2122
"tslib": "^1.9.3"

packages/hub/src/index.ts

Lines changed: 154 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,154 @@
1-
export type { Carrier, Layer } from './hub';
2-
3-
export { addGlobalEventProcessor, Scope } from './scope';
4-
export { closeSession, makeSession, updateSession } from './session';
5-
export { SessionFlusher } from './sessionflusher';
6-
export { getCurrentHub, getHubFromCarrier, getMainCarrier, Hub, makeMain, setHubOnCarrier } from './hub';
7-
export {
8-
addBreadcrumb,
9-
captureException,
10-
captureEvent,
11-
captureMessage,
12-
configureScope,
13-
startTransaction,
14-
setContext,
15-
setExtra,
16-
setExtras,
17-
setTag,
18-
setTags,
19-
setUser,
20-
withScope,
21-
} from './exports';
1+
export type { Carrier, Layer } from '@sentry/core';
2+
3+
import {
4+
addBreadcrumb as addBreadcrumbCore,
5+
addGlobalEventProcessor as addGlobalEventProcessorCore,
6+
captureEvent as captureEventCore,
7+
captureException as captureExceptionCore,
8+
captureMessage as captureMessageCore,
9+
closeSession as closeSessionCore,
10+
configureScope as configureScopeCore,
11+
getCurrentHub as getCurrentHubCore,
12+
getHubFromCarrier as getHubFromCarrierCore,
13+
getMainCarrier as getMainCarrierCore,
14+
Hub as HubCore,
15+
makeMain as makeMainCore,
16+
makeSession as makeSessionCore,
17+
Scope as ScopeCore,
18+
SessionFlusher as SessionFlusherCore,
19+
setContext as setContextCore,
20+
setExtra as setExtraCore,
21+
setExtras as setExtrasCore,
22+
setHubOnCarrier as setHubOnCarrierCore,
23+
setTag as setTagCore,
24+
setTags as setTagsCore,
25+
setUser as setUserCore,
26+
startTransaction as startTransactionCore,
27+
updateSession as updateSessionCore,
28+
withScope as withScopeCore,
29+
} from '@sentry/core';
30+
31+
/**
32+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8
33+
*/
34+
export class Hub extends HubCore {}
35+
36+
/**
37+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8
38+
*/
39+
export class Scope extends ScopeCore {}
40+
41+
/**
42+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
43+
*/
44+
export const getCurrentHub = getCurrentHubCore;
45+
46+
/**
47+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
48+
*/
49+
export const addGlobalEventProcessor = addGlobalEventProcessorCore;
50+
51+
/**
52+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
53+
*/
54+
export const getHubFromCarrier = getHubFromCarrierCore;
55+
56+
/**
57+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
58+
*/
59+
export const getMainCarrier = getMainCarrierCore;
60+
61+
/**
62+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
63+
*/
64+
export const makeMain = makeMainCore;
65+
66+
/**
67+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
68+
*/
69+
export const setHubOnCarrier = setHubOnCarrierCore;
70+
71+
/**
72+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
73+
*/
74+
export const SessionFlusher = SessionFlusherCore;
75+
76+
/**
77+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
78+
*/
79+
export const closeSession = closeSessionCore;
80+
81+
/**
82+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
83+
*/
84+
export const makeSession = makeSessionCore;
85+
86+
/**
87+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
88+
*/
89+
export const updateSession = updateSessionCore;
90+
91+
/**
92+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
93+
*/
94+
export const addBreadcrumb = addBreadcrumbCore;
95+
96+
/**
97+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
98+
*/
99+
export const captureException = captureExceptionCore;
100+
101+
/**
102+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
103+
*/
104+
export const captureEvent = captureEventCore;
105+
106+
/**
107+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
108+
*/
109+
export const captureMessage = captureMessageCore;
110+
111+
/**
112+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
113+
*/
114+
export const configureScope = configureScopeCore;
115+
116+
/**
117+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
118+
*/
119+
export const startTransaction = startTransactionCore;
120+
121+
/**
122+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
123+
*/
124+
export const setContext = setContextCore;
125+
126+
/**
127+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
128+
*/
129+
export const setExtra = setExtraCore;
130+
131+
/**
132+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
133+
*/
134+
export const setExtras = setExtrasCore;
135+
136+
/**
137+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
138+
*/
139+
export const setTag = setTagCore;
140+
141+
/**
142+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
143+
*/
144+
export const setTags = setTagsCore;
145+
146+
/**
147+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
148+
*/
149+
export const setUser = setUserCore;
150+
151+
/**
152+
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
153+
*/
154+
export const withScope = withScopeCore;

packages/hub/test/exports.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import { getCurrentHub, getHubFromCarrier, Scope } from '../src';
1+
/* eslint-disable deprecation/deprecation */
2+
23
import {
34
captureEvent,
45
captureException,
56
captureMessage,
67
configureScope,
8+
getCurrentHub,
9+
getHubFromCarrier,
10+
Scope,
711
setContext,
812
setExtra,
913
setExtras,
1014
setTag,
1115
setTags,
1216
setUser,
1317
withScope,
14-
} from '../src/exports';
18+
} from '../src';
1519

1620
export class TestClient {
1721
public static instance?: TestClient;

packages/hub/test/global.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable deprecation/deprecation */
2+
13
import { getGlobalObject } from '@sentry/utils';
24

35
import { getCurrentHub, getHubFromCarrier, Hub } from '../src';

packages/hub/test/hub.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/* eslint-disable @typescript-eslint/unbound-method */
2+
/* eslint-disable deprecation/deprecation */
3+
24
import { Client, Event } from '@sentry/types';
35

46
import { getCurrentHub, Hub, Scope } from '../src';

packages/hub/test/scope.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable deprecation/deprecation */
2+
13
import { Event, EventHint, RequestSessionStatus } from '@sentry/types';
24
import { getGlobalObject } from '@sentry/utils';
35

packages/hub/test/session.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
/* eslint-disable deprecation/deprecation */
2+
13
import { SessionContext } from '@sentry/types';
24
import { timestampInSeconds } from '@sentry/utils';
35

4-
import { closeSession, makeSession, updateSession } from '../src/session';
6+
import { closeSession, makeSession, updateSession } from '../src';
57

68
describe('Session', () => {
79
it('initializes with the proper defaults', () => {

packages/hub/test/sessionflusher.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
/* eslint-disable deprecation/deprecation */
2+
13
import { Client } from '@sentry/types';
24

3-
import { SessionFlusher } from '../src/sessionflusher';
5+
import { SessionFlusher } from '../src';
46

57
describe('Session Flusher', () => {
68
let sendSession: jest.Mock;

packages/nextjs/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"dependencies": {
2020
"@rollup/plugin-sucrase": "4.0.4",
2121
"@sentry/core": "7.14.2",
22-
"@sentry/hub": "7.14.2",
2322
"@sentry/integrations": "7.14.2",
2423
"@sentry/node": "7.14.2",
2524
"@sentry/react": "7.14.2",

packages/nextjs/src/index.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Carrier, getHubFromCarrier, getMainCarrier } from '@sentry/hub';
1+
import { Carrier, getHubFromCarrier, getMainCarrier } from '@sentry/core';
22
import { RewriteFrames } from '@sentry/integrations';
33
import { configureScope, getCurrentHub, init as nodeInit, Integrations } from '@sentry/node';
44
import { hasTracingEnabled } from '@sentry/tracing';

packages/nextjs/src/performance/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCurrentHub } from '@sentry/hub';
1+
import { getCurrentHub } from '@sentry/core';
22
import { Primitive, TraceparentData, Transaction, TransactionContext, TransactionSource } from '@sentry/types';
33
import {
44
baggageHeaderToDynamicSamplingContext,

packages/nextjs/src/utils/_error.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { captureException, withScope } from '@sentry/core';
2-
import { getCurrentHub } from '@sentry/hub';
1+
import { captureException, getCurrentHub, withScope } from '@sentry/core';
32
import { addExceptionMechanism } from '@sentry/utils';
43
import { NextPageContext } from 'next';
54

0 commit comments

Comments
 (0)