Skip to content

Commit

Permalink
chore: Dedupe @sentry/core imports (#14529)
Browse files Browse the repository at this point in the history
I noticed we have a whole bunch of files that have multiple imports from
`@sentry/core`, so I went over all of those I could find and ran VSCode
auto-import-ordering to clean this up. Would be nice to have this taken
care of by eslint/biome, but somehow this does not seem to work... :(

This for sure does not capture everything, but a good amount of
duplication at least.
  • Loading branch information
mydea authored Nov 29, 2024
1 parent af773b1 commit e17bd91
Show file tree
Hide file tree
Showing 142 changed files with 473 additions and 501 deletions.
7 changes: 4 additions & 3 deletions packages/angular/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import {
breadcrumbsIntegration,
globalHandlersIntegration,
httpContextIntegration,
init as browserInit,
linkedErrorsIntegration,
setContext,
} from '@sentry/browser';
import { init as browserInit, setContext } from '@sentry/browser';
import type { Client, Integration } from '@sentry/core';
import {
applySdkMetadata,
dedupeIntegration,
functionToStringIntegration,
inboundFiltersIntegration,
logger,
} from '@sentry/core';
import { logger } from '@sentry/core';
import type { Client, Integration } from '@sentry/core';

import { IS_DEBUG_BUILD } from './flags';

Expand Down
5 changes: 1 addition & 4 deletions packages/aws-serverless/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { existsSync } from 'fs';
import { hostname } from 'os';
import { basename, resolve } from 'path';
import { types } from 'util';
import { logger } from '@sentry/core';
import type { Integration, Options, Scope, SdkMetadata, Span } from '@sentry/core';
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, logger } from '@sentry/core';
import type { NodeClient, NodeOptions } from '@sentry/node';
import {
SDK_VERSION,
Expand All @@ -19,9 +19,6 @@ import {
} from '@sentry/node';
import type { Context, Handler } from 'aws-lambda';
import { performance } from 'perf_hooks';

import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';

import { DEBUG_BUILD } from './debug-build';
import { awsIntegration } from './integration/aws';
import { awsLambdaIntegration } from './integration/awslambda';
Expand Down
1 change: 0 additions & 1 deletion packages/browser-utils/src/instrument/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { HandlerDataDom } from '@sentry/core';

import { addHandler, addNonEnumerableProperty, fill, maybeInstrument, triggerHandlers, uuid4 } from '@sentry/core';
import { WINDOW } from '../types';

Expand Down
1 change: 0 additions & 1 deletion packages/browser-utils/src/instrument/xhr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { HandlerDataXhr, SentryWrappedXMLHttpRequest } from '@sentry/core';

import { addHandler, isString, maybeInstrument, timestampInSeconds, triggerHandlers } from '@sentry/core';
import { WINDOW } from '../types';

Expand Down
17 changes: 11 additions & 6 deletions packages/browser-utils/src/metrics/browserMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/* eslint-disable max-lines */
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan } from '@sentry/core';
import { setMeasurement } from '@sentry/core';
import { browserPerformanceTimeOrigin, getComponentName, htmlTreeAsString, parseUrl } from '@sentry/core';
import type { Measurements, Span, SpanAttributes, StartSpanOptions } from '@sentry/core';

import { spanToJSON } from '@sentry/core';
import {
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
browserPerformanceTimeOrigin,
getActiveSpan,
getComponentName,
htmlTreeAsString,
parseUrl,
setMeasurement,
spanToJSON,
} from '@sentry/core';
import { WINDOW } from '../types';
import { trackClsAsStandaloneSpan } from './cls';
import {
Expand Down Expand Up @@ -228,7 +233,7 @@ export function startTrackingInteractions(): void {
});
}

export { startTrackingINP, registerInpInteractionListener } from './inp';
export { registerInpInteractionListener, startTrackingINP } from './inp';

/**
* Starts tracking the Cumulative Layout Shift on the current page and collects the value and last entry
Expand Down
6 changes: 4 additions & 2 deletions packages/browser-utils/src/metrics/inp.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import type { Span, SpanAttributes } from '@sentry/core';
import {
SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME,
SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT,
SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
browserPerformanceTimeOrigin,
dropUndefinedKeys,
getActiveSpan,
getCurrentScope,
getRootSpan,
htmlTreeAsString,
spanToJSON,
} from '@sentry/core';
import { browserPerformanceTimeOrigin, dropUndefinedKeys, htmlTreeAsString } from '@sentry/core';
import type { Span, SpanAttributes } from '@sentry/core';
import {
addInpInstrumentationHandler,
addPerformanceInstrumentationHandler,
Expand Down
3 changes: 1 addition & 2 deletions packages/browser-utils/src/metrics/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { SentrySpan } from '@sentry/core';
import type { Integration, SentrySpan, Span, SpanAttributes, SpanTimeInput, StartSpanOptions } from '@sentry/core';
import { getClient, getCurrentScope, spanToJSON, startInactiveSpan, withActiveSpan } from '@sentry/core';
import type { Integration, Span, SpanAttributes, SpanTimeInput, StartSpanOptions } from '@sentry/core';
import { WINDOW } from '../types';

/**
Expand Down
7 changes: 2 additions & 5 deletions packages/browser/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import type { Scope } from '@sentry/core';
import { applySdkMetadata } from '@sentry/core';
import { BaseClient } from '@sentry/core';
import { getSDKSource, logger } from '@sentry/core';
import type {
BrowserClientProfilingOptions,
BrowserClientReplayOptions,
Expand All @@ -10,10 +6,11 @@ import type {
EventHint,
Options,
ParameterizedString,
Scope,
SeverityLevel,
UserFeedback,
} from '@sentry/core';

import { BaseClient, applySdkMetadata, getSDKSource, logger } from '@sentry/core';
import { DEBUG_BUILD } from './debug-build';
import { eventFromException, eventFromMessage } from './eventbuilder';
import { WINDOW } from './helpers';
Expand Down
20 changes: 10 additions & 10 deletions packages/browser/src/eventbuilder.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { getClient } from '@sentry/core';
import type {
Event,
EventHint,
Exception,
ParameterizedString,
SeverityLevel,
StackFrame,
StackParser,
} from '@sentry/core';
import {
addExceptionMechanism,
addExceptionTypeValue,
extractExceptionKeysForMessage,
getClient,
isDOMError,
isDOMException,
isError,
Expand All @@ -13,15 +22,6 @@ import {
normalizeToSize,
resolvedSyncPromise,
} from '@sentry/core';
import type {
Event,
EventHint,
Exception,
ParameterizedString,
SeverityLevel,
StackFrame,
StackParser,
} from '@sentry/core';

type Prototype = { constructor: (...args: unknown[]) => unknown };

Expand Down
5 changes: 3 additions & 2 deletions packages/browser/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { captureException, withScope } from '@sentry/core';
import type { Mechanism, WrappedFunction } from '@sentry/core';
import {
GLOBAL_OBJ,
addExceptionMechanism,
addExceptionTypeValue,
addNonEnumerableProperty,
captureException,
getOriginalFunction,
markFunctionWrapped,
withScope,
} from '@sentry/core';
import type { Mechanism, WrappedFunction } from '@sentry/core';

export const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;

Expand Down
31 changes: 17 additions & 14 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
/* eslint-disable max-lines */

import {
SENTRY_XHR_DATA_KEY,
addClickKeypressInstrumentationHandler,
addHistoryInstrumentationHandler,
addXhrInstrumentationHandler,
} from '@sentry-internal/browser-utils';
import { addBreadcrumb, defineIntegration, getClient } from '@sentry/core';
import {
addConsoleInstrumentationHandler,
addFetchInstrumentationHandler,
getBreadcrumbLogLevelFromHttpStatusCode,
getComponentName,
getEventDescription,
htmlTreeAsString,
logger,
parseUrl,
safeJoin,
severityLevelFromString,
} from '@sentry/core';
import type {
Breadcrumb,
Client,
Expand All @@ -32,7 +21,21 @@ import type {
XhrBreadcrumbData,
XhrBreadcrumbHint,
} from '@sentry/core';

import {
addBreadcrumb,
addConsoleInstrumentationHandler,
addFetchInstrumentationHandler,
defineIntegration,
getBreadcrumbLogLevelFromHttpStatusCode,
getClient,
getComponentName,
getEventDescription,
htmlTreeAsString,
logger,
parseUrl,
safeJoin,
severityLevelFromString,
} from '@sentry/core';
import { DEBUG_BUILD } from '../debug-build';
import { WINDOW } from '../helpers';

Expand Down
3 changes: 1 addition & 2 deletions packages/browser/src/integrations/browserapierrors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineIntegration } from '@sentry/core';
import { fill, getFunctionName, getOriginalFunction } from '@sentry/core';
import type { IntegrationFn, WrappedFunction } from '@sentry/core';
import { defineIntegration, fill, getFunctionName, getOriginalFunction } from '@sentry/core';

import { WINDOW, wrap } from '../helpers';

Expand Down
3 changes: 1 addition & 2 deletions packages/browser/src/integrations/contextlines.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineIntegration } from '@sentry/core';
import { GLOBAL_OBJ, addContextToFrame, stripUrlQueryAndFragment } from '@sentry/core';
import type { Event, IntegrationFn, StackFrame } from '@sentry/core';
import { GLOBAL_OBJ, addContextToFrame, defineIntegration, stripUrlQueryAndFragment } from '@sentry/core';

const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;

Expand Down
6 changes: 4 additions & 2 deletions packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { captureEvent, defineIntegration, getClient } from '@sentry/core';
import type { Client, Event, IntegrationFn, Primitive, StackParser } from '@sentry/core';
import {
UNKNOWN_FUNCTION,
addGlobalErrorInstrumentationHandler,
addGlobalUnhandledRejectionInstrumentationHandler,
captureEvent,
defineIntegration,
getClient,
getLocationHref,
isPrimitive,
isString,
logger,
} from '@sentry/core';
import type { Client, Event, IntegrationFn, Primitive, StackParser } from '@sentry/core';

import type { BrowserClient } from '../client';
import { DEBUG_BUILD } from '../debug-build';
Expand Down
7 changes: 5 additions & 2 deletions packages/browser/src/integrations/httpclient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { SENTRY_XHR_DATA_KEY, addXhrInstrumentationHandler } from '@sentry-internal/browser-utils';
import { captureEvent, defineIntegration, getClient, isSentryRequestUrl } from '@sentry/core';
import type { Client, Event as SentryEvent, IntegrationFn, SentryWrappedXMLHttpRequest } from '@sentry/core';
import {
GLOBAL_OBJ,
addExceptionMechanism,
addFetchInstrumentationHandler,
captureEvent,
defineIntegration,
getClient,
isSentryRequestUrl,
logger,
supportsNativeFetch,
} from '@sentry/core';
import type { Client, Event as SentryEvent, IntegrationFn, SentryWrappedXMLHttpRequest } from '@sentry/core';

import { DEBUG_BUILD } from '../debug-build';

Expand Down
3 changes: 1 addition & 2 deletions packages/browser/src/integrations/linkederrors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineIntegration } from '@sentry/core';
import { applyAggregateErrorsToEvent } from '@sentry/core';
import type { IntegrationFn } from '@sentry/core';
import { applyAggregateErrorsToEvent, defineIntegration } from '@sentry/core';
import { exceptionFromError } from '../eventbuilder';

interface LinkedErrorsOptions {
Expand Down
10 changes: 8 additions & 2 deletions packages/browser/src/integrations/reportingobserver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { captureMessage, defineIntegration, getClient, withScope } from '@sentry/core';
import { GLOBAL_OBJ, supportsReportingObserver } from '@sentry/core';
import type { Client, IntegrationFn } from '@sentry/core';
import {
GLOBAL_OBJ,
captureMessage,
defineIntegration,
getClient,
supportsReportingObserver,
withScope,
} from '@sentry/core';

const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;

Expand Down
6 changes: 2 additions & 4 deletions packages/browser/src/integrations/spotlight.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { getNativeImplementation } from '@sentry-internal/browser-utils';
import { defineIntegration } from '@sentry/core';
import { logger, serializeEnvelope } from '@sentry/core';
import type { Client, Envelope, Event, IntegrationFn } from '@sentry/core';
import type { WINDOW } from '../helpers';

import { defineIntegration, logger, serializeEnvelope } from '@sentry/core';
import { DEBUG_BUILD } from '../debug-build';
import type { WINDOW } from '../helpers';

export type SpotlightConnectionOptions = {
/**
Expand Down
8 changes: 4 additions & 4 deletions packages/browser/src/profiling/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable max-lines */

import { DEFAULT_ENVIRONMENT, getClient, spanToJSON } from '@sentry/core';
import type { DebugImage, Envelope, Event, EventEnvelope, Profile, Span, ThreadCpuProfile } from '@sentry/core';
import {
DEFAULT_ENVIRONMENT,
browserPerformanceTimeOrigin,
forEachEnvelopeItem,
getClient,
getDebugImagesForResources,
logger,
spanToJSON,
timestampInSeconds,
uuid4,
} from '@sentry/core';
import type { DebugImage, Envelope, Event, EventEnvelope, Profile, Span, ThreadCpuProfile } from '@sentry/core';

import { DEBUG_BUILD } from '../debug-build';
import { WINDOW } from '../helpers';
import type { JSSelfProfile, JSSelfProfileStack, JSSelfProfiler, JSSelfProfilerConstructor } from './jsSelfProfiling';
Expand Down
15 changes: 9 additions & 6 deletions packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { getCurrentScope } from '@sentry/core';
import { functionToStringIntegration, inboundFiltersIntegration } from '@sentry/core';
import { addHistoryInstrumentationHandler } from '@sentry-internal/browser-utils';
import {
captureSession,
consoleSandbox,
dedupeIntegration,
functionToStringIntegration,
getClient,
getCurrentScope,
getIntegrationsToSetup,
getReportDialogEndpoint,
inboundFiltersIntegration,
initAndBind,
lastEventId,
logger,
stackParserFromStackParserOptions,
startSession,
supportsFetch,
} from '@sentry/core';
import { consoleSandbox, logger, stackParserFromStackParserOptions, supportsFetch } from '@sentry/core';
import type { Client, DsnLike, Integration, Options, UserFeedback } from '@sentry/core';

import { addHistoryInstrumentationHandler } from '@sentry-internal/browser-utils';
import { dedupeIntegration } from '@sentry/core';
import type { BrowserClientOptions, BrowserOptions } from './client';
import { BrowserClient } from './client';
import { DEBUG_BUILD } from './debug-build';
Expand Down
5 changes: 1 addition & 4 deletions packages/browser/src/tracing/backgroundtab.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { SPAN_STATUS_ERROR, getActiveSpan, getRootSpan } from '@sentry/core';
import { spanToJSON } from '@sentry/core';
import { logger } from '@sentry/core';

import { SPAN_STATUS_ERROR, getActiveSpan, getRootSpan, logger, spanToJSON } from '@sentry/core';
import { DEBUG_BUILD } from '../debug-build';
import { WINDOW } from '../helpers';

Expand Down
Loading

0 comments on commit e17bd91

Please sign in to comment.