Skip to content

Commit 6b15512

Browse files
committed
Move @sentry/hub code to @sentry/core
1 parent a5bfa80 commit 6b15512

Some content is hidden

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

69 files changed

+104
-110
lines changed

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

+2-2
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

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

packages/core/src/baseclient.ts

+2-1
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

+6-7
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

+3-1
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

+2-1
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

+1-1
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

+1-1
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

+3-3
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { configureScope, getCurrentHub } from '@sentry/hub';
1+
import { configureScope, getCurrentHub } from '../../src';
22
import { Event, EventProcessor, Integration } from '@sentry/types';
33

44
export class TestIntegration implements Integration {

packages/hub/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"access": "public"
1717
},
1818
"dependencies": {
19-
"@sentry/types": "7.13.0",
20-
"@sentry/utils": "7.13.0",
19+
"@sentry/core": "7.13.0",
2120
"tslib": "^1.9.3"
2221
},
2322
"scripts": {

packages/hub/src/index.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
export type { Carrier, Layer } from './hub';
1+
export type { Carrier, Layer } from '@sentry/core';
22

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';
73
export {
4+
getCurrentHub,
5+
addGlobalEventProcessor,
6+
Scope,
7+
getHubFromCarrier,
8+
getMainCarrier,
9+
Hub,
10+
makeMain,
11+
setHubOnCarrier,
12+
SessionFlusher,
13+
closeSession,
14+
makeSession,
15+
updateSession,
816
addBreadcrumb,
917
captureException,
1018
captureEvent,
@@ -18,4 +26,4 @@ export {
1826
setTags,
1927
setUser,
2028
withScope,
21-
} from './exports';
29+
} from '@sentry/core';

packages/hub/test/exports.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { getCurrentHub, getHubFromCarrier, Scope } from '../src';
21
import {
2+
getCurrentHub,
3+
getHubFromCarrier,
4+
Scope,
35
captureEvent,
46
captureException,
57
captureMessage,
@@ -11,7 +13,7 @@ import {
1113
setTags,
1214
setUser,
1315
withScope,
14-
} from '../src/exports';
16+
} from '../src';
1517

1618
export class TestClient {
1719
public static instance?: TestClient;

packages/hub/test/session.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SessionContext } from '@sentry/types';
22
import { timestampInSeconds } from '@sentry/utils';
33

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

66
describe('Session', () => {
77
it('initializes with the proper defaults', () => {

packages/hub/test/sessionflusher.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Client } from '@sentry/types';
22

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

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

packages/nextjs/package.json

-1
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.13.0",
22-
"@sentry/hub": "7.13.0",
2322
"@sentry/integrations": "7.13.0",
2423
"@sentry/node": "7.13.0",
2524
"@sentry/react": "7.13.0",

packages/nextjs/src/index.server.ts

+1-1
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

+1-1
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

+1-2
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

packages/nextjs/test/config/withSentry.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as hub from '@sentry/hub';
1+
import * as hub from '@sentry/core';
22
import * as Sentry from '@sentry/node';
33
import { Client, ClientOptions } from '@sentry/types';
44
import * as utils from '@sentry/utils';

packages/nextjs/test/index.client.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { BaseClient } from '@sentry/core';
2-
import { getCurrentHub } from '@sentry/hub';
1+
import { BaseClient, getCurrentHub } from '@sentry/core';
32
import * as SentryReact from '@sentry/react';
43
import { Integrations as TracingIntegrations } from '@sentry/tracing';
54
import { Integration } from '@sentry/types';

packages/nextjs/test/integration/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"resolutions": {
2727
"@sentry/browser": "file:../../../browser",
2828
"@sentry/core": "file:../../../core",
29-
"@sentry/hub": "file:../../../hub",
3029
"@sentry/integrations": "file:../../../integrations",
3130
"@sentry/node": "file:../../../node",
3231
"@sentry/react": "file:../../../react",

packages/node/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
},
1818
"dependencies": {
1919
"@sentry/core": "7.13.0",
20-
"@sentry/hub": "7.13.0",
2120
"@sentry/types": "7.13.0",
2221
"@sentry/utils": "7.13.0",
2322
"cookie": "^0.4.1",

packages/node/src/client.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
2-
import { SessionFlusher } from '@sentry/hub';
1+
import { BaseClient, Scope, SDK_VERSION, SessionFlusher } from '@sentry/core';
32
import { Event, EventHint, Severity, SeverityLevel } from '@sentry/types';
43
import { logger, resolvedSyncPromise } from '@sentry/utils';
54
import * as os from 'os';

packages/node/src/eventbuilder.ts

+1-1
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 {
33
Event,
44
EventHint,

packages/node/src/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ export { defaultIntegrations, init, defaultStackParser, lastEventId, flush, clos
5151
export { addRequestDataToEvent, DEFAULT_USER_INCLUDES, extractRequestData } from './requestdata';
5252
export { deepReadDirSync } from './utils';
5353

54-
import { Integrations as CoreIntegrations } from '@sentry/core';
55-
import { getMainCarrier } from '@sentry/hub';
54+
import { getMainCarrier, Integrations as CoreIntegrations } from '@sentry/core';
5655
import * as domain from 'domain';
5756

5857
import * as Handlers from './handlers';
@@ -66,7 +65,7 @@ const INTEGRATIONS = {
6665
export { INTEGRATIONS as Integrations, Handlers };
6766

6867
// We need to patch domain on the global __SENTRY__ object to make it work for node in cross-platform packages like
69-
// @sentry/hub. If we don't do this, browser bundlers will have troubles resolving `require('domain')`.
68+
// @sentry/core. If we don't do this, browser bundlers will have troubles resolving `require('domain')`.
7069
const carrier = getMainCarrier();
7170
if (carrier.__SENTRY__) {
7271
carrier.__SENTRY__.extensions = carrier.__SENTRY__.extensions || {};

packages/node/src/sdk.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/* eslint-disable max-lines */
2-
import { getCurrentHub, getIntegrationsToSetup, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
3-
import { getMainCarrier, setHubOnCarrier } from '@sentry/hub';
2+
import {
3+
getCurrentHub,
4+
getIntegrationsToSetup,
5+
getMainCarrier,
6+
initAndBind,
7+
Integrations as CoreIntegrations,
8+
setHubOnCarrier,
9+
} from '@sentry/core';
410
import { SessionStatus, StackParser } from '@sentry/types';
511
import {
612
createStackParser,

packages/node/test/client.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Scope, SessionFlusher } from '@sentry/hub';
1+
import { Scope, SessionFlusher } from '@sentry/core';
22
import { Event, EventHint } from '@sentry/types';
33
import * as os from 'os';
44

packages/node/test/eventbuilders.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { eventFromUnknownInput } from '../src/eventbuilder';
55

66
const testScope = new Scope();
77

8-
jest.mock('@sentry/hub', () => {
9-
const original = jest.requireActual('@sentry/hub');
8+
jest.mock('@sentry/core', () => {
9+
const original = jest.requireActual('@sentry/core');
1010
return {
1111
...original,
1212
getCurrentHub(): {

packages/node/test/handlers.test.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as sentryCore from '@sentry/core';
2-
import * as sentryHub from '@sentry/hub';
3-
import { Hub } from '@sentry/hub';
2+
import { Hub, Scope } from '@sentry/core';
43
import { Transaction } from '@sentry/tracing';
54
import { Event } from '@sentry/types';
65
import { SentryError } from '@sentry/utils';
@@ -277,10 +276,8 @@ describe('tracingHandler', () => {
277276
it('puts its transaction on the scope', () => {
278277
const options = getDefaultNodeClientOptions({ tracesSampleRate: 1.0 });
279278
const hub = new Hub(new NodeClient(options));
280-
// we need to mock both of these because the tracing handler relies on `@sentry/core` while the sampler relies on
281-
// `@sentry/hub`, and mocking breaks the link between the two
279+
282280
jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub);
283-
jest.spyOn(sentryHub, 'getCurrentHub').mockReturnValue(hub);
284281

285282
sentryTracingMiddleware(req, res, next);
286283

@@ -443,7 +440,6 @@ describe('errorHandler()', () => {
443440

444441
jest.spyOn<any, any>(client, '_captureRequestSession');
445442
jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub);
446-
jest.spyOn(sentryHub, 'getCurrentHub').mockReturnValue(hub);
447443

448444
scope?.setRequestSession({ status: 'ok' });
449445
sentryErrorMiddleware({ name: 'error', message: 'this is an error' }, req, res, next);
@@ -460,7 +456,6 @@ describe('errorHandler()', () => {
460456

461457
jest.spyOn<any, any>(client, '_captureRequestSession');
462458
jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub);
463-
jest.spyOn(sentryHub, 'getCurrentHub').mockReturnValue(hub);
464459

465460
scope?.setRequestSession({ status: 'ok' });
466461
sentryErrorMiddleware({ name: 'error', message: 'this is an error' }, req, res, next);
@@ -474,7 +469,7 @@ describe('errorHandler()', () => {
474469
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
475470
// by the`requestHandler`)
476471
client.initSessionFlusher();
477-
const scope = new sentryHub.Scope();
472+
const scope = new Scope();
478473
const hub = new Hub(client, scope);
479474

480475
jest.spyOn<any, any>(client, '_captureRequestSession');
@@ -493,12 +488,11 @@ describe('errorHandler()', () => {
493488
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
494489
// by the`requestHandler`)
495490
client.initSessionFlusher();
496-
const scope = new sentryHub.Scope();
491+
const scope = new Scope();
497492
const hub = new Hub(client, scope);
498493

499494
jest.spyOn<any, any>(client, '_captureRequestSession');
500495
jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub);
501-
jest.spyOn(sentryHub, 'getCurrentHub').mockReturnValue(hub);
502496

503497
sentryErrorMiddleware({ name: 'error', message: 'this is an error' }, req, res, next);
504498
const requestSession = scope?.getRequestSession();

packages/node/test/index.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { initAndBind, SDK_VERSION } from '@sentry/core';
2-
import { getMainCarrier } from '@sentry/hub';
1+
import { initAndBind, SDK_VERSION, getMainCarrier } from '@sentry/core';
32
import { EventHint, Integration } from '@sentry/types';
43
import * as domain from 'domain';
54

0 commit comments

Comments
 (0)