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
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
Expand Up @@ -16,7 +16,6 @@
"access": "public"
},
"dependencies": {
"@sentry/hub": "7.14.2",
"@sentry/types": "7.14.2",
"@sentry/utils": "7.14.2",
"tslib": "^1.9.3"
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/baseclient.ts
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Expand Up @@ -16,6 +16,7 @@
"access": "public"
},
"dependencies": {
"@sentry/core": "7.14.2",
"@sentry/types": "7.14.2",
"@sentry/utils": "7.14.2",
"tslib": "^1.9.3"
Expand Down
175 changes: 154 additions & 21 deletions packages/hub/src/index.ts
@@ -1,21 +1,154 @@
export type { Carrier, Layer } from './hub';

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 {
addBreadcrumb,
captureException,
captureEvent,
captureMessage,
configureScope,
startTransaction,
setContext,
setExtra,
setExtras,
setTag,
setTags,
setUser,
withScope,
} from './exports';
export type { Carrier, Layer } from '@sentry/core';

import {
addBreadcrumb as addBreadcrumbCore,
addGlobalEventProcessor as addGlobalEventProcessorCore,
captureEvent as captureEventCore,
captureException as captureExceptionCore,
captureMessage as captureMessageCore,
closeSession as closeSessionCore,
configureScope as configureScopeCore,
getCurrentHub as getCurrentHubCore,
getHubFromCarrier as getHubFromCarrierCore,
getMainCarrier as getMainCarrierCore,
Hub as HubCore,
makeMain as makeMainCore,
makeSession as makeSessionCore,
Scope as ScopeCore,
SessionFlusher as SessionFlusherCore,
setContext as setContextCore,
setExtra as setExtraCore,
setExtras as setExtrasCore,
setHubOnCarrier as setHubOnCarrierCore,
setTag as setTagCore,
setTags as setTagsCore,
setUser as setUserCore,
startTransaction as startTransactionCore,
updateSession as updateSessionCore,
withScope as withScopeCore,
} from '@sentry/core';

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8
*/
export class Hub extends HubCore {}

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8
*/
export class Scope extends ScopeCore {}

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const getCurrentHub = getCurrentHubCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const addGlobalEventProcessor = addGlobalEventProcessorCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const getHubFromCarrier = getHubFromCarrierCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const getMainCarrier = getMainCarrierCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const makeMain = makeMainCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const setHubOnCarrier = setHubOnCarrierCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const SessionFlusher = SessionFlusherCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const closeSession = closeSessionCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const makeSession = makeSessionCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const updateSession = updateSessionCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const addBreadcrumb = addBreadcrumbCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const captureException = captureExceptionCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const captureEvent = captureEventCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const captureMessage = captureMessageCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const configureScope = configureScopeCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const startTransaction = startTransactionCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const setContext = setContextCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const setExtra = setExtraCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const setExtras = setExtrasCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const setTag = setTagCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const setTags = setTagsCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const setUser = setUserCore;

/**
* @deprecated This export has moved to @sentry/core. The @sentry/hub package will be removed in v8.
*/
export const withScope = withScopeCore;
8 changes: 6 additions & 2 deletions packages/hub/test/exports.test.ts
@@ -1,17 +1,21 @@
import { getCurrentHub, getHubFromCarrier, Scope } from '../src';
/* eslint-disable deprecation/deprecation */

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: 2 additions & 0 deletions packages/hub/test/global.test.ts
@@ -1,3 +1,5 @@
/* eslint-disable deprecation/deprecation */

import { getGlobalObject } from '@sentry/utils';

import { getCurrentHub, getHubFromCarrier, Hub } from '../src';
Expand Down
2 changes: 2 additions & 0 deletions packages/hub/test/hub.test.ts
@@ -1,4 +1,6 @@
/* eslint-disable @typescript-eslint/unbound-method */
/* eslint-disable deprecation/deprecation */

import { Client, Event } from '@sentry/types';

import { getCurrentHub, Hub, Scope } from '../src';
Expand Down
2 changes: 2 additions & 0 deletions packages/hub/test/scope.test.ts
@@ -1,3 +1,5 @@
/* eslint-disable deprecation/deprecation */

import { Event, EventHint, RequestSessionStatus } from '@sentry/types';
import { getGlobalObject } from '@sentry/utils';

Expand Down
4 changes: 3 additions & 1 deletion packages/hub/test/session.test.ts
@@ -1,7 +1,9 @@
/* eslint-disable deprecation/deprecation */

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
4 changes: 3 additions & 1 deletion packages/hub/test/sessionflusher.test.ts
@@ -1,6 +1,8 @@
/* eslint-disable deprecation/deprecation */

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
Expand Up @@ -19,7 +19,6 @@
"dependencies": {
"@rollup/plugin-sucrase": "4.0.4",
"@sentry/core": "7.14.2",
"@sentry/hub": "7.14.2",
"@sentry/integrations": "7.14.2",
"@sentry/node": "7.14.2",
"@sentry/react": "7.14.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/index.server.ts
@@ -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
@@ -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
@@ -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