From 796786122314f529502a77ae53c33f54abad3bf6 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Wed, 28 Sep 2022 21:32:01 +0100 Subject: [PATCH] Move tracing to core --- packages/core/src/index.ts | 2 ++ .../src => core/src/tracing}/errors.ts | 0 .../src => core/src/tracing}/hubextensions.ts | 2 +- .../src/tracing}/idletransaction.ts | 2 +- packages/core/src/tracing/index.ts | 19 +++++++++++++++++++ .../{tracing/src => core/src/tracing}/span.ts | 0 .../src => core/src/tracing}/spanstatus.ts | 0 .../src => core/src/tracing}/transaction.ts | 2 +- .../src => core/src/tracing}/utils.ts | 3 ++- packages/tracing/src/browser/backgroundtab.ts | 5 +---- .../tracing/src/browser/browsertracing.ts | 11 +++++++---- packages/tracing/src/browser/metrics/index.ts | 4 +--- packages/tracing/src/browser/metrics/utils.ts | 3 +-- packages/tracing/src/browser/request.ts | 3 +-- packages/tracing/src/index.bundle.ts | 4 ++-- packages/tracing/src/index.ts | 17 +++++++++-------- 16 files changed, 48 insertions(+), 29 deletions(-) rename packages/{tracing/src => core/src/tracing}/errors.ts (100%) rename packages/{tracing/src => core/src/tracing}/hubextensions.ts (99%) rename packages/{tracing/src => core/src/tracing}/idletransaction.ts (99%) create mode 100644 packages/core/src/tracing/index.ts rename packages/{tracing/src => core/src/tracing}/span.ts (100%) rename packages/{tracing/src => core/src/tracing}/spanstatus.ts (100%) rename packages/{tracing/src => core/src/tracing}/transaction.ts (99%) rename packages/{tracing/src => core/src/tracing}/utils.ts (97%) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index ad1948ce84fb..9a393bf238eb 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -30,4 +30,6 @@ export { FunctionToString, InboundFilters } from './integrations'; import * as Integrations from './integrations'; +export * from './tracing'; + export { Integrations }; diff --git a/packages/tracing/src/errors.ts b/packages/core/src/tracing/errors.ts similarity index 100% rename from packages/tracing/src/errors.ts rename to packages/core/src/tracing/errors.ts diff --git a/packages/tracing/src/hubextensions.ts b/packages/core/src/tracing/hubextensions.ts similarity index 99% rename from packages/tracing/src/hubextensions.ts rename to packages/core/src/tracing/hubextensions.ts index e5a7fddbae9c..a1c8efa33eac 100644 --- a/packages/tracing/src/hubextensions.ts +++ b/packages/core/src/tracing/hubextensions.ts @@ -1,4 +1,3 @@ -import { getMainCarrier, Hub } from '@sentry/core'; import { ClientOptions, CustomSamplingContext, @@ -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'; diff --git a/packages/tracing/src/idletransaction.ts b/packages/core/src/tracing/idletransaction.ts similarity index 99% rename from packages/tracing/src/idletransaction.ts rename to packages/core/src/tracing/idletransaction.ts index c93978dc7b70..64a13f6a494f 100644 --- a/packages/tracing/src/idletransaction.ts +++ b/packages/core/src/tracing/idletransaction.ts @@ -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'; diff --git a/packages/core/src/tracing/index.ts b/packages/core/src/tracing/index.ts new file mode 100644 index 000000000000..34fe86f31511 --- /dev/null +++ b/packages/core/src/tracing/index.ts @@ -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'; diff --git a/packages/tracing/src/span.ts b/packages/core/src/tracing/span.ts similarity index 100% rename from packages/tracing/src/span.ts rename to packages/core/src/tracing/span.ts diff --git a/packages/tracing/src/spanstatus.ts b/packages/core/src/tracing/spanstatus.ts similarity index 100% rename from packages/tracing/src/spanstatus.ts rename to packages/core/src/tracing/spanstatus.ts diff --git a/packages/tracing/src/transaction.ts b/packages/core/src/tracing/transaction.ts similarity index 99% rename from packages/tracing/src/transaction.ts rename to packages/core/src/tracing/transaction.ts index 83d5d14e419f..8be233a49e95 100644 --- a/packages/tracing/src/transaction.ts +++ b/packages/core/src/tracing/transaction.ts @@ -1,4 +1,3 @@ -import { getCurrentHub, Hub } from '@sentry/core'; import { DynamicSamplingContext, Event, @@ -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 */ diff --git a/packages/tracing/src/utils.ts b/packages/core/src/tracing/utils.ts similarity index 97% rename from packages/tracing/src/utils.ts rename to packages/core/src/tracing/utils.ts index d79a4f91a2df..117b3984231b 100644 --- a/packages/tracing/src/utils.ts +++ b/packages/core/src/tracing/utils.ts @@ -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 diff --git a/packages/tracing/src/browser/backgroundtab.ts b/packages/tracing/src/browser/backgroundtab.ts index 137779e16168..3c744638e77d 100644 --- a/packages/tracing/src/browser/backgroundtab.ts +++ b/packages/tracing/src/browser/backgroundtab.ts @@ -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(); /** diff --git a/packages/tracing/src/browser/browsertracing.ts b/packages/tracing/src/browser/browsertracing.ts index 07dec0cd585f..6ed0b3f97236 100644 --- a/packages/tracing/src/browser/browsertracing.ts +++ b/packages/tracing/src/browser/browsertracing.ts @@ -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 { diff --git a/packages/tracing/src/browser/metrics/index.ts b/packages/tracing/src/browser/metrics/index.ts index d77b05fed837..48c35f21bd82 100644 --- a/packages/tracing/src/browser/metrics/index.ts +++ b/packages/tracing/src/browser/metrics/index.ts @@ -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'; diff --git a/packages/tracing/src/browser/metrics/utils.ts b/packages/tracing/src/browser/metrics/utils.ts index 4894dbd3ec8e..9a266c01fa61 100644 --- a/packages/tracing/src/browser/metrics/utils.ts +++ b/packages/tracing/src/browser/metrics/utils.ts @@ -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. */ diff --git a/packages/tracing/src/browser/request.ts b/packages/tracing/src/browser/request.ts index 4f25c787e158..4ef3e2a60a0f 100644 --- a/packages/tracing/src/browser/request.ts +++ b/packages/tracing/src/browser/request.ts @@ -1,4 +1,5 @@ /* eslint-disable max-lines */ +import { getActiveTransaction, hasTracingEnabled } from '@sentry/core'; import type { DynamicSamplingContext, Span } from '@sentry/types'; import { addInstrumentationHandler, @@ -8,8 +9,6 @@ import { isMatchingPattern, } from '@sentry/utils'; -import { getActiveTransaction, hasTracingEnabled } from '../utils'; - export const DEFAULT_TRACING_ORIGINS = ['localhost', /^\//]; /** Options for Request Instrumentation */ diff --git a/packages/tracing/src/index.bundle.ts b/packages/tracing/src/index.bundle.ts index b765cb0cca0a..7ecf8e6ca60f 100644 --- a/packages/tracing/src/index.bundle.ts +++ b/packages/tracing/src/index.bundle.ts @@ -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 = {}; diff --git a/packages/tracing/src/index.ts b/packages/tracing/src/index.ts index 14d80fb7b4cc..f47a1861598d 100644 --- a/packages/tracing/src/index.ts +++ b/packages/tracing/src/index.ts @@ -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 }; @@ -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; @@ -49,4 +50,4 @@ export { hasTracingEnabled, stripUrlQueryAndFragment, TRACEPARENT_REGEXP, -} from './utils'; +} from '@sentry/core';