Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(hub): Move @sentry/hub code to @sentry/core #5823

Merged
merged 9 commits into from
Oct 7, 2022
4 changes: 2 additions & 2 deletions packages/browser/test/unit/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function getDefaultBrowserOptions(options: Partial<BrowserOptions> = {}): Browse
};
}

jest.mock('@sentry/hub', () => {
const original = jest.requireActual('@sentry/hub');
jest.mock('@sentry/core', () => {
const original = jest.requireActual('@sentry/core');
return {
...original,
getCurrentHub(): {
Expand Down
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"access": "public"
},
"dependencies": {
"@sentry/hub": "7.14.1",
"@sentry/types": "7.14.1",
"@sentry/utils": "7.14.1",
"tslib": "^1.9.3"
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable max-lines */
import { Scope, updateSession } from '@sentry/hub';
import {
Client,
ClientOptions,
Expand Down Expand Up @@ -40,6 +39,8 @@ import {
import { getEnvelopeEndpointWithUrlEncodedAuth } from './api';
import { createEventEnvelope, createSessionEnvelope } from './envelope';
import { IntegrationIndex, setupIntegrations } from './integration';
import { Scope } from './scope';
import { updateSession } from './session';

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

Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 6 additions & 7 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type { ClientClass } from './sdk';
export type { Carrier, Layer } from './hub';

export {
addBreadcrumb,
Expand All @@ -14,13 +15,11 @@ export {
setTags,
setUser,
withScope,
addGlobalEventProcessor,
getCurrentHub,
getHubFromCarrier,
Hub,
makeMain,
Scope,
} from '@sentry/hub';
} from './exports';
export { getCurrentHub, getHubFromCarrier, Hub, makeMain, getMainCarrier, setHubOnCarrier } from './hub';
export { makeSession, closeSession, updateSession } from './session';
export { SessionFlusher } from './sessionflusher';
export { addGlobalEventProcessor, Scope } from './scope';
export { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from './api';
export { BaseClient } from './baseclient';
export { initAndBind } from './sdk';
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/hub';
import { Integration, Options } from '@sentry/types';
import { arrayify, logger } from '@sentry/utils';

import { getCurrentHub } from './hub';
import { addGlobalEventProcessor } from './scope';

declare module '@sentry/types' {
interface Integration {
isDefaultInstance?: boolean;
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion packages/core/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getCurrentHub } from '@sentry/hub';
import { Client, ClientOptions } from '@sentry/types';
import { logger } from '@sentry/utils';

import { getCurrentHub } from './hub';

/** A class object that can instantiate Client objects. */
export type ClientClass<F extends Client, O extends ClientOptions> = new (options: O) => F;

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/core/test/lib/base.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Hub, makeSession, Scope } from '@sentry/hub';
import { Event, Span } from '@sentry/types';
import { dsnToString, logger, SentryError, SyncPromise } from '@sentry/utils';

import { Hub, makeSession, Scope } from '../../src';
import * as integrationModule from '../../src/integration';
import { getDefaultTestClientOptions, TestClient } from '../mocks/client';
import { TestIntegration } from '../mocks/integration';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/lib/hint.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { captureEvent, configureScope } from '@sentry/hub';
import { captureEvent, configureScope } from '@sentry/core';
import { getGlobalObject } from '@sentry/utils';

import { initAndBind } from '../../src/sdk';
Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/lib/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Scope } from '@sentry/hub';
import { Scope } from '@sentry/core';
import { Client, Integration } from '@sentry/types';

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

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

jest.mock('@sentry/hub', () => {
const original = jest.requireActual('@sentry/hub');
jest.mock('@sentry/core', () => {
const original = jest.requireActual('@sentry/core');
return {
...original,
getCurrentHub(): {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/test/mocks/integration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { configureScope, getCurrentHub } from '@sentry/hub';
import { Event, EventProcessor, Integration } from '@sentry/types';

import { configureScope, getCurrentHub } from '../../src';

export class TestIntegration implements Integration {
public static id: string = 'TestIntegration';

Expand Down
1 change: 1 addition & 0 deletions packages/hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"access": "public"
},
"dependencies": {
"@sentry/core": "7.14.1",
"@sentry/types": "7.14.1",
"@sentry/utils": "7.14.1",
"tslib": "^1.9.3"
Expand Down
20 changes: 14 additions & 6 deletions packages/hub/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
export type { Carrier, Layer } from './hub';
export type { Carrier, Layer } from '@sentry/core';

export { addGlobalEventProcessor, Scope } from './scope';
export { closeSession, makeSession, updateSession } from './session';
export { SessionFlusher } from './sessionflusher';
export { getCurrentHub, getHubFromCarrier, getMainCarrier, Hub, makeMain, setHubOnCarrier } from './hub';
export {
getCurrentHub,
addGlobalEventProcessor,
Scope,
getHubFromCarrier,
getMainCarrier,
Hub,
makeMain,
setHubOnCarrier,
SessionFlusher,
closeSession,
makeSession,
updateSession,
addBreadcrumb,
captureException,
captureEvent,
Expand All @@ -18,4 +26,4 @@ export {
setTags,
setUser,
withScope,
} from './exports';
} from '@sentry/core';
6 changes: 4 additions & 2 deletions packages/hub/test/exports.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { getCurrentHub, getHubFromCarrier, Scope } from '../src';
import {
captureEvent,
captureException,
captureMessage,
configureScope,
getCurrentHub,
getHubFromCarrier,
Scope,
setContext,
setExtra,
setExtras,
setTag,
setTags,
setUser,
withScope,
} from '../src/exports';
} from '../src';

export class TestClient {
public static instance?: TestClient;
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/test/session.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SessionContext } from '@sentry/types';
import { timestampInSeconds } from '@sentry/utils';

import { closeSession, makeSession, updateSession } from '../src/session';
import { closeSession, makeSession, updateSession } from '../src';

describe('Session', () => {
it('initializes with the proper defaults', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/hub/test/sessionflusher.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Client } from '@sentry/types';

import { SessionFlusher } from '../src/sessionflusher';
import { SessionFlusher } from '../src';

describe('Session Flusher', () => {
let sendSession: jest.Mock;
Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"dependencies": {
"@rollup/plugin-sucrase": "4.0.4",
"@sentry/core": "7.14.1",
"@sentry/hub": "7.14.1",
"@sentry/integrations": "7.14.1",
"@sentry/node": "7.14.1",
"@sentry/react": "7.14.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/index.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Carrier, getHubFromCarrier, getMainCarrier } from '@sentry/hub';
import { Carrier, getHubFromCarrier, getMainCarrier } from '@sentry/core';
import { RewriteFrames } from '@sentry/integrations';
import { configureScope, getCurrentHub, init as nodeInit, Integrations } from '@sentry/node';
import { hasTracingEnabled } from '@sentry/tracing';
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/performance/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentHub } from '@sentry/hub';
import { getCurrentHub } from '@sentry/core';
import { Primitive, TraceparentData, Transaction, TransactionContext, TransactionSource } from '@sentry/types';
import {
baggageHeaderToDynamicSamplingContext,
Expand Down
3 changes: 1 addition & 2 deletions packages/nextjs/src/utils/_error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { captureException, withScope } from '@sentry/core';
import { getCurrentHub } from '@sentry/hub';
import { captureException, getCurrentHub, withScope } from '@sentry/core';
import { addExceptionMechanism } from '@sentry/utils';
import { NextPageContext } from 'next';

Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/test/config/withSentry.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as hub from '@sentry/hub';
import * as hub from '@sentry/core';
import * as Sentry from '@sentry/node';
import { Client, ClientOptions } from '@sentry/types';
import * as utils from '@sentry/utils';
Expand Down
3 changes: 1 addition & 2 deletions packages/nextjs/test/index.client.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BaseClient } from '@sentry/core';
import { getCurrentHub } from '@sentry/hub';
import { BaseClient, getCurrentHub } from '@sentry/core';
import * as SentryReact from '@sentry/react';
import { Integrations as TracingIntegrations } from '@sentry/tracing';
import { Integration } from '@sentry/types';
Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/test/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"resolutions": {
"@sentry/browser": "file:../../../browser",
"@sentry/core": "file:../../../core",
"@sentry/hub": "file:../../../hub",
"@sentry/integrations": "file:../../../integrations",
"@sentry/node": "file:../../../node",
"@sentry/react": "file:../../../react",
Expand Down
1 change: 0 additions & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
},
"dependencies": {
"@sentry/core": "7.14.1",
"@sentry/hub": "7.14.1",
"@sentry/types": "7.14.1",
"@sentry/utils": "7.14.1",
"cookie": "^0.4.1",
Expand Down
3 changes: 1 addition & 2 deletions packages/node/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
import { SessionFlusher } from '@sentry/hub';
import { BaseClient, Scope, SDK_VERSION, SessionFlusher } from '@sentry/core';
import { Event, EventHint, Severity, SeverityLevel } from '@sentry/types';
import { logger, resolvedSyncPromise } from '@sentry/utils';
import * as os from 'os';
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/eventbuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentHub } from '@sentry/hub';
import { getCurrentHub } from '@sentry/core';
import {
Event,
EventHint,
Expand Down
5 changes: 2 additions & 3 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ export { defaultIntegrations, init, defaultStackParser, lastEventId, flush, clos
export { addRequestDataToEvent, DEFAULT_USER_INCLUDES, extractRequestData } from './requestdata';
export { deepReadDirSync } from './utils';

import { Integrations as CoreIntegrations } from '@sentry/core';
import { getMainCarrier } from '@sentry/hub';
import { getMainCarrier, Integrations as CoreIntegrations } from '@sentry/core';
import * as domain from 'domain';

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

// We need to patch domain on the global __SENTRY__ object to make it work for node in cross-platform packages like
// @sentry/hub. If we don't do this, browser bundlers will have troubles resolving `require('domain')`.
// @sentry/core. If we don't do this, browser bundlers will have troubles resolving `require('domain')`.
const carrier = getMainCarrier();
if (carrier.__SENTRY__) {
carrier.__SENTRY__.extensions = carrier.__SENTRY__.extensions || {};
Expand Down
10 changes: 8 additions & 2 deletions packages/node/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/* eslint-disable max-lines */
import { getCurrentHub, getIntegrationsToSetup, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
import { getMainCarrier, setHubOnCarrier } from '@sentry/hub';
import {
getCurrentHub,
getIntegrationsToSetup,
getMainCarrier,
initAndBind,
Integrations as CoreIntegrations,
setHubOnCarrier,
} from '@sentry/core';
import { SessionStatus, StackParser } from '@sentry/types';
import {
createStackParser,
Expand Down
2 changes: 1 addition & 1 deletion packages/node/test/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Scope, SessionFlusher } from '@sentry/hub';
import { Scope, SessionFlusher } from '@sentry/core';
import { Event, EventHint } from '@sentry/types';
import * as os from 'os';

Expand Down
4 changes: 2 additions & 2 deletions packages/node/test/eventbuilders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { eventFromUnknownInput } from '../src/eventbuilder';

const testScope = new Scope();

jest.mock('@sentry/hub', () => {
const original = jest.requireActual('@sentry/hub');
jest.mock('@sentry/core', () => {
const original = jest.requireActual('@sentry/core');
return {
...original,
getCurrentHub(): {
Expand Down
14 changes: 4 additions & 10 deletions packages/node/test/handlers.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as sentryCore from '@sentry/core';
import * as sentryHub from '@sentry/hub';
import { Hub } from '@sentry/hub';
import { Hub, Scope } from '@sentry/core';
import { Transaction } from '@sentry/tracing';
import { Event } from '@sentry/types';
import { SentryError } from '@sentry/utils';
Expand Down Expand Up @@ -277,10 +276,8 @@ describe('tracingHandler', () => {
it('puts its transaction on the scope', () => {
const options = getDefaultNodeClientOptions({ tracesSampleRate: 1.0 });
const hub = new Hub(new NodeClient(options));
// we need to mock both of these because the tracing handler relies on `@sentry/core` while the sampler relies on
// `@sentry/hub`, and mocking breaks the link between the two

jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub);
jest.spyOn(sentryHub, 'getCurrentHub').mockReturnValue(hub);

sentryTracingMiddleware(req, res, next);

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

jest.spyOn<any, any>(client, '_captureRequestSession');
jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub);
jest.spyOn(sentryHub, 'getCurrentHub').mockReturnValue(hub);

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

jest.spyOn<any, any>(client, '_captureRequestSession');
jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub);
jest.spyOn(sentryHub, 'getCurrentHub').mockReturnValue(hub);

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

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

jest.spyOn<any, any>(client, '_captureRequestSession');
jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub);
jest.spyOn(sentryHub, 'getCurrentHub').mockReturnValue(hub);

sentryErrorMiddleware({ name: 'error', message: 'this is an error' }, req, res, next);
const requestSession = scope?.getRequestSession();
Expand Down
3 changes: 1 addition & 2 deletions packages/node/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { initAndBind, SDK_VERSION } from '@sentry/core';
import { getMainCarrier } from '@sentry/hub';
import { getMainCarrier, initAndBind, SDK_VERSION } from '@sentry/core';
import { EventHint, Integration } from '@sentry/types';
import * as domain from 'domain';

Expand Down
Loading