Skip to content

Move tracing code to core without impacting bundle size #1

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ export { FunctionToString, InboundFilters } from './integrations';

import * as Integrations from './integrations';

export * from './tracing';

export { Integrations };
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getMainCarrier, Hub } from '@sentry/core';
import {
ClientOptions,
CustomSamplingContext,
Expand All @@ -10,6 +9,7 @@ import {
} from '@sentry/types';
import { dynamicRequire, isNaN, isNodeEnv, loadModule, logger } from '@sentry/utils';

import { getMainCarrier, Hub } from '..';
import { registerErrorInstrumentation } from './errors';
import { IdleTransaction } from './idletransaction';
import { Transaction } from './transaction';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable max-lines */
import { Hub } from '@sentry/core';
import { TransactionContext } from '@sentry/types';
import { logger, timestampWithMs } from '@sentry/utils';

import { Hub } from '..';
import { Span, SpanRecorder } from './span';
import { Transaction } from './transaction';

Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/tracing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type { SpanStatusType } from './span';

export { Span, spanStatusfromHttpCode } from './span';
// eslint-disable-next-line deprecation/deprecation
export { SpanStatus } from './spanstatus';
export { Transaction } from './transaction';
export { IdleTransaction, DEFAULT_FINAL_TIMEOUT, DEFAULT_IDLE_TIMEOUT } from './idletransaction';
export { startIdleTransaction } from './hubextensions';

export { addExtensionMethods } from './hubextensions';

export {
extractTraceparentData,
getActiveTransaction,
hasTracingEnabled,
stripUrlQueryAndFragment,
TRACEPARENT_REGEXP,
msToSec,
} from './utils';
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getCurrentHub, Hub } from '@sentry/core';
import {
DynamicSamplingContext,
Event,
Expand All @@ -10,6 +9,7 @@ import {
} from '@sentry/types';
import { dropUndefinedKeys, logger, timestampInSeconds } from '@sentry/utils';

import { getCurrentHub, Hub } from '..';
import { Span as SpanClass, SpanRecorder } from './span';

/** JSDoc */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getCurrentHub, Hub } from '@sentry/core';
import { Options, Transaction } from '@sentry/types';

import { getCurrentHub, Hub } from '..';

/**
* The `extractTraceparentData` function and `TRACEPARENT_REGEXP` constant used
* to be declared in this file. It was later moved into `@sentry/utils` as part of a
Expand Down
5 changes: 1 addition & 4 deletions packages/tracing/src/browser/backgroundtab.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { getActiveTransaction, IdleTransaction, SpanStatusType } from '@sentry/core';
import { getGlobalObject, logger } from '@sentry/utils';

import { IdleTransaction } from '../idletransaction';
import { SpanStatusType } from '../span';
import { getActiveTransaction } from '../utils';

const global = getGlobalObject<Window>();

/**
Expand Down
11 changes: 7 additions & 4 deletions packages/tracing/src/browser/browsertracing.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/* eslint-disable max-lines */
import { Hub } from '@sentry/core';
import {
DEFAULT_FINAL_TIMEOUT,
DEFAULT_IDLE_TIMEOUT,
extractTraceparentData,
Hub,
startIdleTransaction,
} from '@sentry/core';
import { EventProcessor, Integration, Transaction, TransactionContext } from '@sentry/types';
import { baggageHeaderToDynamicSamplingContext, getDomElement, getGlobalObject, logger } from '@sentry/utils';

import { startIdleTransaction } from '../hubextensions';
import { DEFAULT_FINAL_TIMEOUT, DEFAULT_IDLE_TIMEOUT } from '../idletransaction';
import { extractTraceparentData } from '../utils';
import { registerBackgroundTabDetection } from './backgroundtab';
import { addPerformanceEntries, startTrackingLongTasks, startTrackingWebVitals } from './metrics';
import {
Expand Down
4 changes: 1 addition & 3 deletions packages/tracing/src/browser/metrics/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable max-lines */
import { getActiveTransaction, IdleTransaction, msToSec, Transaction } from '@sentry/core';
import { Measurements } from '@sentry/types';
import { browserPerformanceTimeOrigin, getGlobalObject, htmlTreeAsString, logger } from '@sentry/utils';

import { IdleTransaction } from '../../idletransaction';
import { Transaction } from '../../transaction';
import { getActiveTransaction, msToSec } from '../../utils';
import { getCLS, LayoutShift } from '../web-vitals/getCLS';
import { getFID } from '../web-vitals/getFID';
import { getLCP, LargestContentfulPaint } from '../web-vitals/getLCP';
Expand Down
3 changes: 1 addition & 2 deletions packages/tracing/src/browser/metrics/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Transaction } from '@sentry/core';
import { Span, SpanContext } from '@sentry/types';

import { Transaction } from '../../transaction';

/**
* Checks if a given value is a valid measurement value.
*/
Expand Down
3 changes: 1 addition & 2 deletions packages/tracing/src/browser/request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable max-lines */
import { getActiveTransaction, hasTracingEnabled } from '@sentry/core';
import type { DynamicSamplingContext, Span } from '@sentry/types';
import {
addInstrumentationHandler,
Expand All @@ -8,8 +9,6 @@ import {
isMatchingPattern,
} from '@sentry/utils';

import { getActiveTransaction, hasTracingEnabled } from '../utils';

export const DEFAULT_TRACING_ORIGINS = ['localhost', /^\//];

/** Options for Request Instrumentation */
Expand Down
4 changes: 2 additions & 2 deletions packages/tracing/src/index.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ export {
export { SDK_VERSION } from '@sentry/browser';

import { Integrations as BrowserIntegrations } from '@sentry/browser';
import { addExtensionMethods } from '@sentry/core';
import { getGlobalObject } from '@sentry/utils';

import { BrowserTracing } from './browser';
import { addExtensionMethods } from './hubextensions';

export { Span } from './span';
export { Span } from '@sentry/core';

let windowIntegrations = {};

Expand Down
17 changes: 9 additions & 8 deletions packages/tracing/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { addExtensionMethods } from './hubextensions';
import { addExtensionMethods } from '@sentry/core';

import * as Integrations from './integrations';

export type { RequestInstrumentationOptions } from './browser';
export type { SpanStatusType } from './span';
export type { SpanStatusType } from '@sentry/core';

export { Integrations };

Expand All @@ -24,13 +25,13 @@ export { Integrations };
// For an example of of the new usage of BrowserTracing, see @sentry/nextjs index.client.ts
export { BrowserTracing, BROWSER_TRACING_INTEGRATION_ID } from './browser';

export { Span, spanStatusfromHttpCode } from './span';
export { Span, spanStatusfromHttpCode } from '@sentry/core';
// eslint-disable-next-line deprecation/deprecation
export { SpanStatus } from './spanstatus';
export { Transaction } from './transaction';
export { SpanStatus } from '@sentry/core';
export { Transaction } from '@sentry/core';
export { instrumentOutgoingRequests, defaultRequestInstrumentationOptions } from './browser';
export { IdleTransaction } from './idletransaction';
export { startIdleTransaction } from './hubextensions';
export { IdleTransaction } from '@sentry/core';
export { startIdleTransaction } from '@sentry/core';

// Treeshakable guard to remove all code related to tracing
declare const __SENTRY_TRACING__: boolean;
Expand All @@ -49,4 +50,4 @@ export {
hasTracingEnabled,
stripUrlQueryAndFragment,
TRACEPARENT_REGEXP,
} from './utils';
} from '@sentry/core';