diff --git a/packages/angular/src/errorhandler.ts b/packages/angular/src/errorhandler.ts index d9b4db07ff9d..ea6dea85d04c 100644 --- a/packages/angular/src/errorhandler.ts +++ b/packages/angular/src/errorhandler.ts @@ -83,9 +83,11 @@ class SentryErrorHandler implements AngularErrorHandler { protected readonly _options: ErrorHandlerOptions; /* indicates if we already registered our the afterSendEvent handler */ - private _registeredAfterSendEventHandler = false; + private _registeredAfterSendEventHandler; public constructor(@Inject('errorHandlerOptions') options?: ErrorHandlerOptions) { + this._registeredAfterSendEventHandler = false; + this._options = { logErrors: true, ...options, diff --git a/packages/angular/src/tracing.ts b/packages/angular/src/tracing.ts index f2e79adfe9b0..5378208a3404 100644 --- a/packages/angular/src/tracing.ts +++ b/packages/angular/src/tracing.ts @@ -145,11 +145,14 @@ export class TraceService implements OnDestroy { }), ); - private _routingSpan: Span | null = null; + private _routingSpan: Span | null; - private _subscription: Subscription = new Subscription(); + private _subscription: Subscription; public constructor(private readonly _router: Router) { + this._routingSpan = null; + this._subscription = new Subscription(); + this._subscription.add(this.navStart$.subscribe()); this._subscription.add(this.resEnd$.subscribe()); this._subscription.add(this.navEnd$.subscribe()); diff --git a/packages/browser/src/integrations/breadcrumbs.ts b/packages/browser/src/integrations/breadcrumbs.ts index b5f734ce939c..a7330d1fb23e 100644 --- a/packages/browser/src/integrations/breadcrumbs.ts +++ b/packages/browser/src/integrations/breadcrumbs.ts @@ -56,7 +56,7 @@ export class Breadcrumbs implements Integration { /** * @inheritDoc */ - public name: string = Breadcrumbs.id; + public name: string; /** * Options of the breadcrumbs integration. @@ -68,6 +68,7 @@ export class Breadcrumbs implements Integration { * @inheritDoc */ public constructor(options?: Partial) { + this.name = Breadcrumbs.id; this.options = { console: true, dom: true, diff --git a/packages/browser/src/integrations/dedupe.ts b/packages/browser/src/integrations/dedupe.ts index c9903eaadf92..05bd88a8c786 100644 --- a/packages/browser/src/integrations/dedupe.ts +++ b/packages/browser/src/integrations/dedupe.ts @@ -11,13 +11,17 @@ export class Dedupe implements Integration { /** * @inheritDoc */ - public name: string = Dedupe.id; + public name: string; /** * @inheritDoc */ private _previousEvent?: Event; + public constructor() { + this.name = Dedupe.id; + } + /** * @inheritDoc */ diff --git a/packages/browser/src/integrations/globalhandlers.ts b/packages/browser/src/integrations/globalhandlers.ts index 5bfdc126a712..3a6ca996ef01 100644 --- a/packages/browser/src/integrations/globalhandlers.ts +++ b/packages/browser/src/integrations/globalhandlers.ts @@ -30,7 +30,7 @@ export class GlobalHandlers implements Integration { /** * @inheritDoc */ - public name: string = GlobalHandlers.id; + public name: string; /** JSDoc */ private readonly _options: GlobalHandlersIntegrations; @@ -39,18 +39,21 @@ export class GlobalHandlers implements Integration { * Stores references functions to installing handlers. Will set to undefined * after they have been run so that they are not used twice. */ - private _installFunc: Record void) | undefined> = { - onerror: _installGlobalOnErrorHandler, - onunhandledrejection: _installGlobalOnUnhandledRejectionHandler, - }; + private _installFunc: Record void) | undefined>; /** JSDoc */ public constructor(options?: GlobalHandlersIntegrations) { + this.name = GlobalHandlers.id; this._options = { onerror: true, onunhandledrejection: true, ...options, }; + + this._installFunc = { + onerror: _installGlobalOnErrorHandler, + onunhandledrejection: _installGlobalOnUnhandledRejectionHandler, + }; } /** * @inheritDoc diff --git a/packages/browser/src/integrations/httpcontext.ts b/packages/browser/src/integrations/httpcontext.ts index 24b6df24312a..f37963b46619 100644 --- a/packages/browser/src/integrations/httpcontext.ts +++ b/packages/browser/src/integrations/httpcontext.ts @@ -13,7 +13,11 @@ export class HttpContext implements Integration { /** * @inheritDoc */ - public name: string = HttpContext.id; + public name: string; + + public constructor() { + this.name = HttpContext.id; + } /** * @inheritDoc diff --git a/packages/browser/src/integrations/linkederrors.ts b/packages/browser/src/integrations/linkederrors.ts index 709ba8228107..a30a7dc82c34 100644 --- a/packages/browser/src/integrations/linkederrors.ts +++ b/packages/browser/src/integrations/linkederrors.ts @@ -21,7 +21,7 @@ export class LinkedErrors implements Integration { /** * @inheritDoc */ - public readonly name: string = LinkedErrors.id; + public readonly name: string; /** * @inheritDoc @@ -37,6 +37,7 @@ export class LinkedErrors implements Integration { * @inheritDoc */ public constructor(options: Partial = {}) { + this.name = LinkedErrors.id; this._key = options.key || DEFAULT_KEY; this._limit = options.limit || DEFAULT_LIMIT; } diff --git a/packages/browser/src/integrations/trycatch.ts b/packages/browser/src/integrations/trycatch.ts index d29be09a6a0b..cb3e42cfd107 100644 --- a/packages/browser/src/integrations/trycatch.ts +++ b/packages/browser/src/integrations/trycatch.ts @@ -56,7 +56,7 @@ export class TryCatch implements Integration { /** * @inheritDoc */ - public name: string = TryCatch.id; + public name: string; /** JSDoc */ private readonly _options: TryCatchOptions; @@ -65,6 +65,7 @@ export class TryCatch implements Integration { * @inheritDoc */ public constructor(options?: Partial) { + this.name = TryCatch.id; this._options = { XMLHttpRequest: true, eventTarget: true, diff --git a/packages/browser/src/profiling/integration.ts b/packages/browser/src/profiling/integration.ts index 36fb6432e6df..0d506b7493cd 100644 --- a/packages/browser/src/profiling/integration.ts +++ b/packages/browser/src/profiling/integration.ts @@ -22,8 +22,15 @@ import { * @experimental */ export class BrowserProfilingIntegration implements Integration { - public readonly name: string = 'BrowserProfilingIntegration'; - public getCurrentHub?: () => Hub = undefined; + public static id: string = 'BrowserProfilingIntegration'; + + public readonly name: string; + + public getCurrentHub?: () => Hub; + + public constructor() { + this.name = BrowserProfilingIntegration.id; + } /** * @inheritDoc diff --git a/packages/core/src/baseclient.ts b/packages/core/src/baseclient.ts index e2afccdb0d97..354417351d1b 100644 --- a/packages/core/src/baseclient.ts +++ b/packages/core/src/baseclient.ts @@ -93,19 +93,19 @@ export abstract class BaseClient implements Client { protected readonly _transport?: Transport; /** Array of set up integrations. */ - protected _integrations: IntegrationIndex = {}; + protected _integrations: IntegrationIndex; /** Indicates whether this client's integrations have been set up. */ - protected _integrationsInitialized: boolean = false; + protected _integrationsInitialized: boolean; /** Number of calls being processed */ - protected _numProcessing: number = 0; + protected _numProcessing: number; /** Holds flushable */ - private _outcomes: { [key: string]: number } = {}; + private _outcomes: { [key: string]: number }; // eslint-disable-next-line @typescript-eslint/ban-types - private _hooks: Record = {}; + private _hooks: Record; /** * Initializes this client instance. @@ -114,6 +114,11 @@ export abstract class BaseClient implements Client { */ protected constructor(options: O) { this._options = options; + this._integrations = {}; + this._integrationsInitialized = false; + this._numProcessing = 0; + this._outcomes = {}; + this._hooks = {}; if (options.dsn) { this._dsn = makeDsn(options.dsn); diff --git a/packages/core/src/integrations/functiontostring.ts b/packages/core/src/integrations/functiontostring.ts index ca287390a818..b1db3224bc64 100644 --- a/packages/core/src/integrations/functiontostring.ts +++ b/packages/core/src/integrations/functiontostring.ts @@ -13,7 +13,11 @@ export class FunctionToString implements Integration { /** * @inheritDoc */ - public name: string = FunctionToString.id; + public name: string; + + public constructor() { + this.name = FunctionToString.id; + } /** * @inheritDoc diff --git a/packages/core/src/integrations/inboundfilters.ts b/packages/core/src/integrations/inboundfilters.ts index 3b6b2e8933de..abe7948f2547 100644 --- a/packages/core/src/integrations/inboundfilters.ts +++ b/packages/core/src/integrations/inboundfilters.ts @@ -36,9 +36,14 @@ export class InboundFilters implements Integration { /** * @inheritDoc */ - public name: string = InboundFilters.id; + public name: string; - public constructor(private readonly _options: Partial = {}) {} + private readonly _options: Partial; + + public constructor(options: Partial = {}) { + this.name = InboundFilters.id; + this._options = options; + } /** * @inheritDoc diff --git a/packages/core/src/integrations/metadata.ts b/packages/core/src/integrations/metadata.ts index 05af1d88ebe9..caa9ad972e7d 100644 --- a/packages/core/src/integrations/metadata.ts +++ b/packages/core/src/integrations/metadata.ts @@ -21,7 +21,11 @@ export class ModuleMetadata implements Integration { /** * @inheritDoc */ - public name: string = ModuleMetadata.id; + public name: string; + + public constructor() { + this.name = ModuleMetadata.id; + } /** * @inheritDoc diff --git a/packages/core/src/sessionflusher.ts b/packages/core/src/sessionflusher.ts index 4ef196819504..0b0bc8455480 100644 --- a/packages/core/src/sessionflusher.ts +++ b/packages/core/src/sessionflusher.ts @@ -18,15 +18,19 @@ type ReleaseHealthAttributes = { * @inheritdoc */ export class SessionFlusher implements SessionFlusherLike { - public readonly flushTimeout: number = 60; - private _pendingAggregates: Record = {}; + public readonly flushTimeout: number; + private _pendingAggregates: Record; private _sessionAttrs: ReleaseHealthAttributes; private _intervalId: ReturnType; - private _isEnabled: boolean = true; + private _isEnabled: boolean; private _client: Client; public constructor(client: Client, attrs: ReleaseHealthAttributes) { this._client = client; + this.flushTimeout = 60; + this._pendingAggregates = {}; + this._isEnabled = true; + // Call to setInterval, so that flush is called every 60 seconds this._intervalId = setInterval(() => this.flush(), this.flushTimeout * 1000); this._sessionAttrs = attrs; diff --git a/packages/core/src/tracing/idletransaction.ts b/packages/core/src/tracing/idletransaction.ts index 6b72113097fc..1c4086ceecb7 100644 --- a/packages/core/src/tracing/idletransaction.ts +++ b/packages/core/src/tracing/idletransaction.ts @@ -69,28 +69,27 @@ export type BeforeFinishCallback = (transactionSpan: IdleTransaction, endTimesta */ export class IdleTransaction extends Transaction { // Activities store a list of active spans - public activities: Record = {}; - + public activities: Record; // Track state of activities in previous heartbeat private _prevHeartbeatString: string | undefined; // Amount of times heartbeat has counted. Will cause transaction to finish after 3 beats. - private _heartbeatCounter: number = 0; + private _heartbeatCounter: number; // We should not use heartbeat if we finished a transaction - private _finished: boolean = false; + private _finished: boolean; // Idle timeout was canceled and we should finish the transaction with the last span end. - private _idleTimeoutCanceledPermanently: boolean = false; + private _idleTimeoutCanceledPermanently: boolean; - private readonly _beforeFinishCallbacks: BeforeFinishCallback[] = []; + private readonly _beforeFinishCallbacks: BeforeFinishCallback[]; /** * Timer that tracks Transaction idleTimeout */ private _idleTimeoutID: ReturnType | undefined; - private _finishReason: (typeof IDLE_TRANSACTION_FINISH_REASONS)[number] = IDLE_TRANSACTION_FINISH_REASONS[4]; + private _finishReason: (typeof IDLE_TRANSACTION_FINISH_REASONS)[number]; public constructor( transactionContext: TransactionContext, @@ -110,6 +109,13 @@ export class IdleTransaction extends Transaction { ) { super(transactionContext, _idleHub); + this.activities = {}; + this._heartbeatCounter = 0; + this._finished = false; + this._idleTimeoutCanceledPermanently = false; + this._beforeFinishCallbacks = []; + this._finishReason = IDLE_TRANSACTION_FINISH_REASONS[4]; + if (_onScope) { // We set the transaction here on the scope so error events pick up the trace // context and attach it to the error. diff --git a/packages/core/src/tracing/span.ts b/packages/core/src/tracing/span.ts index 617dc7eaa52c..1340ea3db55c 100644 --- a/packages/core/src/tracing/span.ts +++ b/packages/core/src/tracing/span.ts @@ -16,12 +16,13 @@ import { dropUndefinedKeys, generateSentryTraceHeader, logger, timestampInSecond * @hidden */ export class SpanRecorder { - public spans: Span[] = []; + public spans: Span[]; private readonly _maxlen: number; public constructor(maxlen: number = 1000) { this._maxlen = maxlen; + this.spans = []; } /** @@ -46,12 +47,12 @@ export class Span implements SpanInterface { /** * @inheritDoc */ - public traceId: string = uuid4(); + public traceId: string; /** * @inheritDoc */ - public spanId: string = uuid4().substring(16); + public spanId: string; /** * @inheritDoc @@ -71,7 +72,7 @@ export class Span implements SpanInterface { /** * Timestamp in seconds when the span was created. */ - public startTimestamp: number = timestampInSeconds(); + public startTimestamp: number; /** * Timestamp in seconds when the span ended. @@ -91,13 +92,13 @@ export class Span implements SpanInterface { /** * @inheritDoc */ - public tags: { [key: string]: Primitive } = {}; + public tags: { [key: string]: Primitive }; /** * @inheritDoc */ // eslint-disable-next-line @typescript-eslint/no-explicit-any - public data: { [key: string]: any } = {}; + public data: { [key: string]: any }; /** * List of spans that were finalized @@ -112,7 +113,7 @@ export class Span implements SpanInterface { /** * The instrumenter that created this span. */ - public instrumenter: Instrumenter = 'sentry'; + public instrumenter: Instrumenter; /** * You should never call the constructor manually, always use `Sentry.startTransaction()` @@ -122,6 +123,13 @@ export class Span implements SpanInterface { * @hidden */ public constructor(spanContext?: SpanContext) { + this.traceId = uuid4(); + this.spanId = uuid4().substring(16); + this.startTimestamp = timestampInSeconds(); + this.tags = {}; + this.data = {}; + this.instrumenter = 'sentry'; + if (!spanContext) { return this; } diff --git a/packages/core/src/tracing/transaction.ts b/packages/core/src/tracing/transaction.ts index 71e6279eab80..9a901df3d316 100644 --- a/packages/core/src/tracing/transaction.ts +++ b/packages/core/src/tracing/transaction.ts @@ -27,13 +27,13 @@ export class Transaction extends SpanClass implements TransactionInterface { private _name: string; - private _measurements: Measurements = {}; + private _measurements: Measurements; - private _contexts: Contexts = {}; + private _contexts: Contexts; private _trimEnd?: boolean; - private _frozenDynamicSamplingContext: Readonly> | undefined = undefined; + private _frozenDynamicSamplingContext: Readonly> | undefined; /** * This constructor should never be called manually. Those instrumenting tracing should use @@ -45,6 +45,9 @@ export class Transaction extends SpanClass implements TransactionInterface { public constructor(transactionContext: TransactionContext, hub?: Hub) { super(transactionContext); + this._measurements = {}; + this._contexts = {}; + this._hub = hub || getCurrentHub(); this._name = transactionContext.name || ''; diff --git a/packages/eslint-config-sdk/src/index.js b/packages/eslint-config-sdk/src/index.js index ffdc8b8ba0af..2d60f44f05f7 100644 --- a/packages/eslint-config-sdk/src/index.js +++ b/packages/eslint-config-sdk/src/index.js @@ -164,6 +164,9 @@ module.exports = { // Do not allow usage of functions we do not polyfill for ES5 '@sentry-internal/sdk/no-unsupported-es6-methods': 'error', + + // Do not allow usage of class field initializers + '@sentry-internal/sdk/no-class-field-initializers': 'error', }, }, { diff --git a/packages/eslint-plugin-sdk/src/index.js b/packages/eslint-plugin-sdk/src/index.js index 31d8e932d904..2798a005c277 100644 --- a/packages/eslint-plugin-sdk/src/index.js +++ b/packages/eslint-plugin-sdk/src/index.js @@ -14,5 +14,6 @@ module.exports = { 'no-nullish-coalescing': require('./rules/no-nullish-coalescing'), 'no-eq-empty': require('./rules/no-eq-empty'), 'no-unsupported-es6-methods': require('./rules/no-unsupported-es6-methods'), + 'no-class-field-initializers': require('./rules/no-class-field-initializers'), }, }; diff --git a/packages/eslint-plugin-sdk/src/rules/no-class-field-initializers.js b/packages/eslint-plugin-sdk/src/rules/no-class-field-initializers.js new file mode 100644 index 000000000000..cb7b63edb896 --- /dev/null +++ b/packages/eslint-plugin-sdk/src/rules/no-class-field-initializers.js @@ -0,0 +1,48 @@ +/** + * @fileoverview Rule to disallow using class field initializers. + * @author Francesco Novy + * + * Based on https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/state-in-constructor.js + */ +'use strict'; + +// ------------------------------------------------------------------------------ +// Rule Definition +// ------------------------------------------------------------------------------ + +/** @type {import('eslint').Rule.RuleModule} */ +module.exports = { + meta: { + type: 'problem', + docs: { + description: 'disallow usage of class field initializers, because they producer larger bundle size.', + category: 'Best Practices', + recommended: true, + }, + messages: { + forbidden: 'Avoid using class field initializers', + }, + fixable: null, + schema: [], + }, + + create(context) { + return { + 'ClassProperty, PropertyDefinition'(node) { + // We do allow arrow functions being initialized directly + if ( + !node.static && + node.value !== null && + node.value.type !== 'ArrowFunctionExpression' && + node.value.type !== 'FunctionExpression' && + node.value.type !== 'CallExpression' + ) { + context.report({ + node, + message: `Avoid class field initializers. Property "${node.key.name}" should be initialized in the constructor.`, + }); + } + }, + }; + }, +}; diff --git a/packages/integration-shims/src/BrowserTracing.ts b/packages/integration-shims/src/BrowserTracing.ts index 5aa1f809b492..4b2d90d029b6 100644 --- a/packages/integration-shims/src/BrowserTracing.ts +++ b/packages/integration-shims/src/BrowserTracing.ts @@ -14,10 +14,12 @@ class BrowserTracingShim implements Integration { /** * @inheritDoc */ - public name: string = BrowserTracingShim.id; + public name: string; // eslint-disable-next-line @typescript-eslint/no-explicit-any public constructor(_options: any) { + this.name = BrowserTracingShim.id; + // eslint-disable-next-line no-console console.error('You are using new BrowserTracing() even though this bundle does not include tracing.'); } diff --git a/packages/integration-shims/src/Replay.ts b/packages/integration-shims/src/Replay.ts index 3b81addb404d..a6983344ce6f 100644 --- a/packages/integration-shims/src/Replay.ts +++ b/packages/integration-shims/src/Replay.ts @@ -14,10 +14,12 @@ class ReplayShim implements Integration { /** * @inheritDoc */ - public name: string = ReplayShim.id; + public name: string; // eslint-disable-next-line @typescript-eslint/no-explicit-any public constructor(_options: any) { + this.name = ReplayShim.id; + // eslint-disable-next-line no-console console.error('You are using new Replay() even though this bundle does not include replay.'); } diff --git a/packages/integrations/src/captureconsole.ts b/packages/integrations/src/captureconsole.ts index bca9e6a2e410..d72da5f2b5c4 100644 --- a/packages/integrations/src/captureconsole.ts +++ b/packages/integrations/src/captureconsole.ts @@ -11,20 +11,19 @@ export class CaptureConsole implements Integration { /** * @inheritDoc */ - public name: string = CaptureConsole.id; + public name: string; /** * @inheritDoc */ - private readonly _levels: readonly string[] = CONSOLE_LEVELS; + private readonly _levels: readonly string[]; /** * @inheritDoc */ public constructor(options: { levels?: string[] } = {}) { - if (options.levels) { - this._levels = options.levels; - } + this.name = CaptureConsole.id; + this._levels = options.levels || CONSOLE_LEVELS; } /** diff --git a/packages/integrations/src/debug.ts b/packages/integrations/src/debug.ts index 950610e531a0..1deb1f8dec17 100644 --- a/packages/integrations/src/debug.ts +++ b/packages/integrations/src/debug.ts @@ -21,11 +21,13 @@ export class Debug implements Integration { /** * @inheritDoc */ - public name: string = Debug.id; + public name: string; private readonly _options: DebugOptions; public constructor(options?: DebugOptions) { + this.name = Debug.id; + this._options = { debugger: false, stringify: false, diff --git a/packages/integrations/src/dedupe.ts b/packages/integrations/src/dedupe.ts index 8cb52295abc8..9467e7f6b6e1 100644 --- a/packages/integrations/src/dedupe.ts +++ b/packages/integrations/src/dedupe.ts @@ -11,13 +11,17 @@ export class Dedupe implements Integration { /** * @inheritDoc */ - public name: string = Dedupe.id; + public name: string; /** * @inheritDoc */ private _previousEvent?: Event; + public constructor() { + this.name = Dedupe.id; + } + /** * @inheritDoc */ diff --git a/packages/integrations/src/extraerrordata.ts b/packages/integrations/src/extraerrordata.ts index 8e694b20f2c1..86d9343ef5e3 100644 --- a/packages/integrations/src/extraerrordata.ts +++ b/packages/integrations/src/extraerrordata.ts @@ -16,7 +16,7 @@ export class ExtraErrorData implements Integration { /** * @inheritDoc */ - public name: string = ExtraErrorData.id; + public name: string; /** JSDoc */ private readonly _options: ExtraErrorDataOptions; @@ -25,6 +25,8 @@ export class ExtraErrorData implements Integration { * @inheritDoc */ public constructor(options?: ExtraErrorDataOptions) { + this.name = ExtraErrorData.id; + this._options = { depth: 3, ...options, diff --git a/packages/integrations/src/httpclient.ts b/packages/integrations/src/httpclient.ts index 92ef392b872b..98da9d46d3af 100644 --- a/packages/integrations/src/httpclient.ts +++ b/packages/integrations/src/httpclient.ts @@ -49,7 +49,7 @@ export class HttpClient implements Integration { /** * @inheritDoc */ - public name: string = HttpClient.id; + public name: string; private readonly _options: HttpClientOptions; @@ -64,6 +64,7 @@ export class HttpClient implements Integration { * @param options */ public constructor(options?: Partial) { + this.name = HttpClient.id; this._options = { failedRequestStatusCodes: [[500, 599]], failedRequestTargets: [/.*/], diff --git a/packages/integrations/src/offline.ts b/packages/integrations/src/offline.ts index f48856023848..bdb3d8324333 100644 --- a/packages/integrations/src/offline.ts +++ b/packages/integrations/src/offline.ts @@ -34,7 +34,7 @@ export class Offline implements Integration { /** * @inheritDoc */ - public readonly name: string = Offline.id; + public readonly name: string; /** * the current hub instance @@ -55,6 +55,8 @@ export class Offline implements Integration { * @inheritDoc */ public constructor(options: { maxStoredEvents?: number } = {}) { + this.name = Offline.id; + this.maxStoredEvents = options.maxStoredEvents || 30; // set a reasonable default // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access this.offlineEventStore = localForage.createInstance({ diff --git a/packages/integrations/src/reportingobserver.ts b/packages/integrations/src/reportingobserver.ts index 87f8763cb28a..65d3996963b1 100644 --- a/packages/integrations/src/reportingobserver.ts +++ b/packages/integrations/src/reportingobserver.ts @@ -49,23 +49,27 @@ export class ReportingObserver implements Integration { /** * @inheritDoc */ - public readonly name: string = ReportingObserver.id; + public readonly name: string; /** * Returns current hub. */ private _getCurrentHub?: () => Hub; + private readonly _types: ReportTypes[]; + /** * @inheritDoc */ public constructor( - private readonly _options: { + options: { types?: ReportTypes[]; - } = { - types: ['crash', 'deprecation', 'intervention'], - }, - ) {} + } = {}, + ) { + this.name = ReportingObserver.id; + + this._types = options.types || ['crash', 'deprecation', 'intervention']; + } /** * @inheritDoc @@ -80,7 +84,7 @@ export class ReportingObserver implements Integration { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any const observer = new (WINDOW as any).ReportingObserver(this.handler.bind(this), { buffered: true, - types: this._options.types, + types: this._types, }); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access diff --git a/packages/integrations/src/rewriteframes.ts b/packages/integrations/src/rewriteframes.ts index 62fd230a6f3b..1564d54a4970 100644 --- a/packages/integrations/src/rewriteframes.ts +++ b/packages/integrations/src/rewriteframes.ts @@ -13,7 +13,7 @@ export class RewriteFrames implements Integration { /** * @inheritDoc */ - public name: string = RewriteFrames.id; + public name: string; /** * @inheritDoc @@ -23,18 +23,18 @@ export class RewriteFrames implements Integration { /** * @inheritDoc */ - private readonly _prefix: string = 'app:///'; + private readonly _prefix: string; /** * @inheritDoc */ public constructor(options: { root?: string; prefix?: string; iteratee?: StackFrameIteratee } = {}) { + this.name = RewriteFrames.id; + if (options.root) { this._root = options.root; } - if (options.prefix) { - this._prefix = options.prefix; - } + this._prefix = options.prefix || 'app:///'; if (options.iteratee) { this._iteratee = options.iteratee; } diff --git a/packages/integrations/src/sessiontiming.ts b/packages/integrations/src/sessiontiming.ts index 269ca4148ac2..584163ce008e 100644 --- a/packages/integrations/src/sessiontiming.ts +++ b/packages/integrations/src/sessiontiming.ts @@ -10,10 +10,15 @@ export class SessionTiming implements Integration { /** * @inheritDoc */ - public name: string = SessionTiming.id; + public name: string; /** Exact time Client was initialized expressed in milliseconds since Unix Epoch. */ - protected readonly _startTime: number = Date.now(); + protected readonly _startTime: number; + + public constructor() { + this.name = SessionTiming.id; + this._startTime = Date.now(); + } /** * @inheritDoc diff --git a/packages/integrations/src/transaction.ts b/packages/integrations/src/transaction.ts index 8fbd52a8a871..1bb3ebfa816d 100644 --- a/packages/integrations/src/transaction.ts +++ b/packages/integrations/src/transaction.ts @@ -10,7 +10,11 @@ export class Transaction implements Integration { /** * @inheritDoc */ - public name: string = Transaction.id; + public name: string; + + public constructor() { + this.name = Transaction.id; + } /** * @inheritDoc diff --git a/packages/nextjs/src/edge/transport.ts b/packages/nextjs/src/edge/transport.ts index de8c20af20f9..9c41ddf149c1 100644 --- a/packages/nextjs/src/edge/transport.ts +++ b/packages/nextjs/src/edge/transport.ts @@ -22,11 +22,17 @@ const DEFAULT_TRANSPORT_BUFFER_SIZE = 30; export class IsolatedPromiseBuffer { // We just have this field because the promise buffer interface requires it. // If we ever remove it from the interface we should also remove it here. - public $: Array> = []; + public $: Array>; - private _taskProducers: (() => PromiseLike)[] = []; + private _taskProducers: (() => PromiseLike)[]; - public constructor(private readonly _bufferSize: number = DEFAULT_TRANSPORT_BUFFER_SIZE) {} + private readonly _bufferSize: number; + + public constructor(_bufferSize = DEFAULT_TRANSPORT_BUFFER_SIZE) { + this.$ = []; + this._taskProducers = []; + this._bufferSize = _bufferSize; + } /** * @inheritdoc diff --git a/packages/node-experimental/src/integrations/express.ts b/packages/node-experimental/src/integrations/express.ts index 33eed0182107..84e3f698a179 100644 --- a/packages/node-experimental/src/integrations/express.ts +++ b/packages/node-experimental/src/integrations/express.ts @@ -18,7 +18,12 @@ export class Express extends NodePerformanceIntegration implements Integra /** * @inheritDoc */ - public name: string = Express.id; + public name: string; + + public constructor() { + super(); + this.name = Express.id; + } /** @inheritDoc */ public setupInstrumentation(): void | Instrumentation[] { diff --git a/packages/node-experimental/src/integrations/fastify.ts b/packages/node-experimental/src/integrations/fastify.ts index 17bae20d0ed3..31ed6e3067bd 100644 --- a/packages/node-experimental/src/integrations/fastify.ts +++ b/packages/node-experimental/src/integrations/fastify.ts @@ -18,7 +18,12 @@ export class Fastify extends NodePerformanceIntegration implements Integra /** * @inheritDoc */ - public name: string = Fastify.id; + public name: string; + + public constructor() { + super(); + this.name = Fastify.id; + } /** @inheritDoc */ public setupInstrumentation(): void | Instrumentation[] { diff --git a/packages/node-experimental/src/integrations/graphql.ts b/packages/node-experimental/src/integrations/graphql.ts index dad877cdbb1a..409e2b2d3cff 100644 --- a/packages/node-experimental/src/integrations/graphql.ts +++ b/packages/node-experimental/src/integrations/graphql.ts @@ -18,7 +18,12 @@ export class GraphQL extends NodePerformanceIntegration implements Integra /** * @inheritDoc */ - public name: string = GraphQL.id; + public name: string; + + public constructor() { + super(); + this.name = GraphQL.id; + } /** @inheritDoc */ public setupInstrumentation(): void | Instrumentation[] { diff --git a/packages/node-experimental/src/integrations/http.ts b/packages/node-experimental/src/integrations/http.ts index 1a01c782053c..b0f9555a60be 100644 --- a/packages/node-experimental/src/integrations/http.ts +++ b/packages/node-experimental/src/integrations/http.ts @@ -53,21 +53,23 @@ export class Http implements Integration { /** * @inheritDoc */ - public name: string = Http.id; + public name: string; private _unload?: () => void; private readonly _breadcrumbs: boolean; // undefined: default behavior based on tracing settings private readonly _tracing: boolean | undefined; - private _shouldCreateSpans: boolean = false; + private _shouldCreateSpans: boolean; private _shouldCreateSpanForRequest?: (url: string) => boolean; /** * @inheritDoc */ public constructor(options: HttpOptions = {}) { + this.name = Http.id; this._breadcrumbs = typeof options.breadcrumbs === 'undefined' ? true : options.breadcrumbs; this._tracing = typeof options.tracing === 'undefined' ? undefined : !!options.tracing; + this._shouldCreateSpans = false; if (options.tracing && typeof options.tracing === 'object') { this._shouldCreateSpanForRequest = options.tracing.shouldCreateSpanForRequest; diff --git a/packages/node-experimental/src/integrations/mongo.ts b/packages/node-experimental/src/integrations/mongo.ts index befa3bbf6365..96375a6202e5 100644 --- a/packages/node-experimental/src/integrations/mongo.ts +++ b/packages/node-experimental/src/integrations/mongo.ts @@ -18,7 +18,12 @@ export class Mongo extends NodePerformanceIntegration implements Integrati /** * @inheritDoc */ - public name: string = Mongo.id; + public name: string; + + public constructor() { + super(); + this.name = Mongo.id; + } /** @inheritDoc */ public setupInstrumentation(): void | Instrumentation[] { diff --git a/packages/node-experimental/src/integrations/mongoose.ts b/packages/node-experimental/src/integrations/mongoose.ts index 0b48f4bd2e6c..de08f600a3a7 100644 --- a/packages/node-experimental/src/integrations/mongoose.ts +++ b/packages/node-experimental/src/integrations/mongoose.ts @@ -18,7 +18,12 @@ export class Mongoose extends NodePerformanceIntegration implements Integr /** * @inheritDoc */ - public name: string = Mongoose.id; + public name: string; + + public constructor() { + super(); + this.name = Mongoose.id; + } /** @inheritDoc */ public setupInstrumentation(): void | Instrumentation[] { diff --git a/packages/node-experimental/src/integrations/mysql.ts b/packages/node-experimental/src/integrations/mysql.ts index cbfe46c6aadb..4308234b7410 100644 --- a/packages/node-experimental/src/integrations/mysql.ts +++ b/packages/node-experimental/src/integrations/mysql.ts @@ -16,9 +16,14 @@ export class Mysql extends NodePerformanceIntegration implements Integrati public static id: string = 'Mysql'; /** - * @inheritDoc` + * @inheritDoc */ - public name: string = Mysql.id; + public name: string; + + public constructor() { + super(); + this.name = Mysql.id; + } /** @inheritDoc */ public setupInstrumentation(): void | Instrumentation[] { diff --git a/packages/node-experimental/src/integrations/mysql2.ts b/packages/node-experimental/src/integrations/mysql2.ts index 30b47d298716..278eeee4870f 100644 --- a/packages/node-experimental/src/integrations/mysql2.ts +++ b/packages/node-experimental/src/integrations/mysql2.ts @@ -16,9 +16,14 @@ export class Mysql2 extends NodePerformanceIntegration implements Integrat public static id: string = 'Mysql2'; /** - * @inheritDoc` + * @inheritDoc */ - public name: string = Mysql2.id; + public name: string; + + public constructor() { + super(); + this.name = Mysql2.id; + } /** @inheritDoc */ public setupInstrumentation(): void | Instrumentation[] { diff --git a/packages/node-experimental/src/integrations/nest.ts b/packages/node-experimental/src/integrations/nest.ts index f847f3201771..a358500b1fdd 100644 --- a/packages/node-experimental/src/integrations/nest.ts +++ b/packages/node-experimental/src/integrations/nest.ts @@ -16,9 +16,14 @@ export class Nest extends NodePerformanceIntegration implements Integratio public static id: string = 'Nest'; /** - * @inheritDoc` + * @inheritDoc */ - public name: string = Nest.id; + public name: string; + + public constructor() { + super(); + this.name = Nest.id; + } /** @inheritDoc */ public setupInstrumentation(): void | Instrumentation[] { diff --git a/packages/node-experimental/src/integrations/postgres.ts b/packages/node-experimental/src/integrations/postgres.ts index ab8c17ea61e7..aacb679a906c 100644 --- a/packages/node-experimental/src/integrations/postgres.ts +++ b/packages/node-experimental/src/integrations/postgres.ts @@ -16,9 +16,14 @@ export class Postgres extends NodePerformanceIntegration implements Integr public static id: string = 'Postgres'; /** - * @inheritDoc` + * @inheritDoc */ - public name: string = Postgres.id; + public name: string; + + public constructor() { + super(); + this.name = Postgres.id; + } /** @inheritDoc */ public setupInstrumentation(): void | Instrumentation[] { diff --git a/packages/node-experimental/src/integrations/prisma.ts b/packages/node-experimental/src/integrations/prisma.ts index 4609c98ae71f..d29c44560e29 100644 --- a/packages/node-experimental/src/integrations/prisma.ts +++ b/packages/node-experimental/src/integrations/prisma.ts @@ -20,9 +20,14 @@ export class Prisma extends NodePerformanceIntegration implements Integrat public static id: string = 'Prisma'; /** - * @inheritDoc` + * @inheritDoc */ - public name: string = Prisma.id; + public name: string; + + public constructor() { + super(); + this.name = Prisma.id; + } /** @inheritDoc */ public setupInstrumentation(): void | Instrumentation[] { diff --git a/packages/node/.eslintrc.js b/packages/node/.eslintrc.js index 8e4b96002ae0..bec6469d0e28 100644 --- a/packages/node/.eslintrc.js +++ b/packages/node/.eslintrc.js @@ -7,5 +7,6 @@ module.exports = { '@sentry-internal/sdk/no-optional-chaining': 'off', '@sentry-internal/sdk/no-nullish-coalescing': 'off', '@sentry-internal/sdk/no-unsupported-es6-methods': 'off', + '@sentry-internal/sdk/no-class-field-initializers': 'off', }, }; diff --git a/packages/overhead-metrics/.eslintrc.cjs b/packages/overhead-metrics/.eslintrc.cjs index 8046df7df92c..281d09c16ab2 100644 --- a/packages/overhead-metrics/.eslintrc.cjs +++ b/packages/overhead-metrics/.eslintrc.cjs @@ -11,6 +11,7 @@ module.exports = { '@sentry-internal/sdk/no-optional-chaining': 'off', '@sentry-internal/sdk/no-nullish-coalescing': 'off', '@sentry-internal/sdk/no-unsupported-es6-methods': 'off', + '@sentry-internal/sdk/no-class-field-initializers': 'off', 'jsdoc/require-jsdoc': 'off', }, }, diff --git a/packages/react/src/errorboundary.tsx b/packages/react/src/errorboundary.tsx index 9a01ae110a64..d3c831e24357 100644 --- a/packages/react/src/errorboundary.tsx +++ b/packages/react/src/errorboundary.tsx @@ -92,15 +92,18 @@ function setCause(error: Error & { cause?: Error }, cause: Error): void { * is expected behavior and NOT indicative of a bug with the Sentry React SDK. */ class ErrorBoundary extends React.Component { - public state: ErrorBoundaryState = INITIAL_STATE; + public state: ErrorBoundaryState; - private readonly _openFallbackReportDialog: boolean = true; + private readonly _openFallbackReportDialog: boolean; private _lastEventId?: string; public constructor(props: ErrorBoundaryProps) { super(props); + this.state = INITIAL_STATE; + this._openFallbackReportDialog = true; + const client = getCurrentHub().getClient(); if (client && client.on && props.showDialog) { this._openFallbackReportDialog = false; diff --git a/packages/react/src/profiler.tsx b/packages/react/src/profiler.tsx index 1c6056aad68b..4ada66266f26 100644 --- a/packages/react/src/profiler.tsx +++ b/packages/react/src/profiler.tsx @@ -36,11 +36,11 @@ class Profiler extends React.Component { * The span of the mount activity * Made protected for the React Native SDK to access */ - protected _mountSpan: Span | undefined = undefined; + protected _mountSpan: Span | undefined; /** * The span that represents the duration of time between shouldComponentUpdate and componentDidUpdate */ - protected _updateSpan: Span | undefined = undefined; + protected _updateSpan: Span | undefined; // eslint-disable-next-line @typescript-eslint/member-ordering public static defaultProps: Partial = { diff --git a/packages/react/src/reactrouter.tsx b/packages/react/src/reactrouter.tsx index bfe89afd0890..95c507e3d07b 100644 --- a/packages/react/src/reactrouter.tsx +++ b/packages/react/src/reactrouter.tsx @@ -7,24 +7,22 @@ import type { Action, Location, ReactRouterInstrumentation } from './types'; // We need to disable eslint no-explict-any because any is required for the // react-router typings. -/* eslint-disable @typescript-eslint/no-explicit-any */ -type Match = { path: string; url: string; params: Record; isExact: boolean }; +type Match = { path: string; url: string; params: Record; isExact: boolean }; // eslint-disable-line @typescript-eslint/no-explicit-any export type RouterHistory = { location?: Location; listen?(cb: (location: Location, action: Action) => void): void; -} & Record; +} & Record; // eslint-disable-line @typescript-eslint/no-explicit-any export type RouteConfig = { - [propName: string]: any; + [propName: string]: unknown; path?: string | string[]; exact?: boolean; component?: JSX.Element; routes?: RouteConfig[]; }; -type MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null; -/* eslint-enable @typescript-eslint/no-explicit-any */ +type MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null; // eslint-disable-line @typescript-eslint/no-explicit-any let activeTransaction: Transaction | undefined; diff --git a/packages/replay/src/coreHandlers/handleClick.ts b/packages/replay/src/coreHandlers/handleClick.ts index ddb7de8d237c..cc1d816c5435 100644 --- a/packages/replay/src/coreHandlers/handleClick.ts +++ b/packages/replay/src/coreHandlers/handleClick.ts @@ -28,10 +28,10 @@ export function handleClick(clickDetector: ReplayClickDetector, clickBreadcrumb: /** A click detector class that can be used to detect slow or rage clicks on elements. */ export class ClickDetector implements ReplayClickDetector { // protected for testing - protected _lastMutation = 0; - protected _lastScroll = 0; + protected _lastMutation: number; + protected _lastScroll: number; - private _clicks: Click[] = []; + private _clicks: Click[]; private _teardown: undefined | (() => void); private _threshold: number; @@ -49,6 +49,10 @@ export class ClickDetector implements ReplayClickDetector { // Just for easier testing _addBreadcrumbEvent = addBreadcrumbEvent, ) { + this._lastMutation = 0; + this._lastScroll = 0; + this._clicks = []; + // We want everything in s, but options are in ms this._timeout = slowClickConfig.timeout / 1000; this._threshold = slowClickConfig.threshold / 1000; diff --git a/packages/replay/src/eventBuffer/EventBufferArray.ts b/packages/replay/src/eventBuffer/EventBufferArray.ts index c2fb7aa4c7f5..c9915e7c8b05 100644 --- a/packages/replay/src/eventBuffer/EventBufferArray.ts +++ b/packages/replay/src/eventBuffer/EventBufferArray.ts @@ -10,10 +10,11 @@ import { EventBufferSizeExceededError } from './error'; export class EventBufferArray implements EventBuffer { /** All the events that are buffered to be sent. */ public events: RecordingEvent[]; - private _totalSize = 0; + private _totalSize: number; public constructor() { this.events = []; + this._totalSize = 0; } /** @inheritdoc */ diff --git a/packages/replay/src/eventBuffer/EventBufferCompressionWorker.ts b/packages/replay/src/eventBuffer/EventBufferCompressionWorker.ts index 42b26f58a927..8c40c5d289cf 100644 --- a/packages/replay/src/eventBuffer/EventBufferCompressionWorker.ts +++ b/packages/replay/src/eventBuffer/EventBufferCompressionWorker.ts @@ -13,11 +13,12 @@ import { WorkerHandler } from './WorkerHandler'; export class EventBufferCompressionWorker implements EventBuffer { private _worker: WorkerHandler; private _earliestTimestamp: number | null; - private _totalSize = 0; + private _totalSize; public constructor(worker: Worker) { this._worker = new WorkerHandler(worker); this._earliestTimestamp = null; + this._totalSize = 0; } /** @inheritdoc */ diff --git a/packages/replay/src/integration.ts b/packages/replay/src/integration.ts index 9afe7c9716a8..15a39391636c 100644 --- a/packages/replay/src/integration.ts +++ b/packages/replay/src/integration.ts @@ -35,7 +35,7 @@ export class Replay implements Integration { /** * @inheritDoc */ - public name: string = Replay.id; + public name: string; /** * Options to pass to `rrweb.record()` @@ -100,6 +100,8 @@ export class Replay implements Integration { // eslint-disable-next-line deprecation/deprecation ignoreClass, }: ReplayConfiguration = {}) { + this.name = Replay.id; + this._recordingOptions = { maskAllInputs, maskAllText, diff --git a/packages/replay/src/replay.ts b/packages/replay/src/replay.ts index cf0e72ffcc34..a46554266653 100644 --- a/packages/replay/src/replay.ts +++ b/packages/replay/src/replay.ts @@ -55,12 +55,12 @@ import { throttle, THROTTLED } from './util/throttle'; * The main replay container class, which holds all the state and methods for recording and sending replays. */ export class ReplayContainer implements ReplayContainerInterface { - public eventBuffer: EventBuffer | null = null; + public eventBuffer: EventBuffer | null; /** * List of PerformanceEntry from PerformanceObserver */ - public performanceEvents: AllPerformanceEntry[] = []; + public performanceEvents: AllPerformanceEntry[]; public session: Session | undefined; @@ -73,7 +73,7 @@ export class ReplayContainer implements ReplayContainerInterface { * - having replaysOnErrorSampleRate > 0 to capture replay when an error occurs * - or calling `flush()` to send the replay */ - public recordingMode: ReplayRecordingMode = 'session'; + public recordingMode: ReplayRecordingMode; /** * The current or last active transcation. @@ -85,11 +85,7 @@ export class ReplayContainer implements ReplayContainerInterface { * These are here so we can overwrite them in tests etc. * @hidden */ - public readonly timeouts: Timeouts = { - sessionIdlePause: SESSION_IDLE_PAUSE_DURATION, - sessionIdleExpire: SESSION_IDLE_EXPIRE_DURATION, - maxSessionLife: MAX_SESSION_LIFE, - } as const; + public readonly timeouts: Timeouts; private _throttledAddEvent: ( event: RecordingEvent, @@ -103,46 +99,40 @@ export class ReplayContainer implements ReplayContainerInterface { private readonly _options: ReplayPluginOptions; - private _performanceObserver: PerformanceObserver | null = null; + private _performanceObserver: PerformanceObserver | undefined; private _debouncedFlush: ReturnType; - private _flushLock: Promise | null = null; + private _flushLock: Promise | undefined; /** * Timestamp of the last user activity. This lives across sessions. */ - private _lastActivity: number = Date.now(); + private _lastActivity: number; /** * Is the integration currently active? */ - private _isEnabled: boolean = false; + private _isEnabled: boolean; /** * Paused is a state where: * - DOM Recording is not listening at all * - Nothing will be added to event buffer (e.g. core SDK events) */ - private _isPaused: boolean = false; + private _isPaused: boolean; /** * Have we attached listeners to the core SDK? * Note we have to track this as there is no way to remove instrumentation handlers. */ - private _hasInitializedCoreListeners: boolean = false; + private _hasInitializedCoreListeners: boolean; /** * Function to stop recording */ - private _stopRecording: ReturnType | null = null; - - private _context: InternalEventContext = { - errorIds: new Set(), - traceIds: new Set(), - urls: [], - initialTimestamp: Date.now(), - initialUrl: '', - }; + private _stopRecording: ReturnType | undefined; + + private _context: InternalEventContext; public constructor({ options, @@ -151,6 +141,26 @@ export class ReplayContainer implements ReplayContainerInterface { options: ReplayPluginOptions; recordingOptions: RecordingOptions; }) { + this.eventBuffer = null; + this.performanceEvents = []; + this.recordingMode = 'session'; + this.timeouts = { + sessionIdlePause: SESSION_IDLE_PAUSE_DURATION, + sessionIdleExpire: SESSION_IDLE_EXPIRE_DURATION, + maxSessionLife: MAX_SESSION_LIFE, + } as const; + this._lastActivity = Date.now(); + this._isEnabled = false; + this._isPaused = false; + this._hasInitializedCoreListeners = false; + this._context = { + errorIds: new Set(), + traceIds: new Set(), + urls: [], + initialTimestamp: Date.now(), + initialUrl: '', + }; + this._recordingOptions = recordingOptions; this._options = options; @@ -808,7 +818,7 @@ export class ReplayContainer implements ReplayContainerInterface { if (this._performanceObserver) { this._performanceObserver.disconnect(); - this._performanceObserver = null; + this._performanceObserver = undefined; } } catch (err) { this._handleException(err); @@ -1129,7 +1139,7 @@ export class ReplayContainer implements ReplayContainerInterface { if (!this._flushLock) { this._flushLock = this._runFlush(); await this._flushLock; - this._flushLock = null; + this._flushLock = undefined; return; } diff --git a/packages/serverless/src/awsservices.ts b/packages/serverless/src/awsservices.ts index 431d0653ee69..55c6741ffb69 100644 --- a/packages/serverless/src/awsservices.ts +++ b/packages/serverless/src/awsservices.ts @@ -25,11 +25,13 @@ export class AWSServices implements Integration { /** * @inheritDoc */ - public name: string = AWSServices.id; + public name: string; private readonly _optional: boolean; public constructor(options: { optional?: boolean } = {}) { + this.name = AWSServices.id; + this._optional = options.optional || false; } diff --git a/packages/serverless/src/google-cloud-grpc.ts b/packages/serverless/src/google-cloud-grpc.ts index f18aee42e002..a16e77d164bd 100644 --- a/packages/serverless/src/google-cloud-grpc.ts +++ b/packages/serverless/src/google-cloud-grpc.ts @@ -35,11 +35,13 @@ export class GoogleCloudGrpc implements Integration { /** * @inheritDoc */ - public name: string = GoogleCloudGrpc.id; + public name: string; private readonly _optional: boolean; public constructor(options: { optional?: boolean } = {}) { + this.name = GoogleCloudGrpc.id; + this._optional = options.optional || false; } diff --git a/packages/serverless/src/google-cloud-http.ts b/packages/serverless/src/google-cloud-http.ts index 04dec4bbe134..0dd4f1f60ccb 100644 --- a/packages/serverless/src/google-cloud-http.ts +++ b/packages/serverless/src/google-cloud-http.ts @@ -22,11 +22,13 @@ export class GoogleCloudHttp implements Integration { /** * @inheritDoc */ - public name: string = GoogleCloudHttp.id; + public name: string; private readonly _optional: boolean; public constructor(options: { optional?: boolean } = {}) { + this.name = GoogleCloudHttp.id; + this._optional = options.optional || false; } diff --git a/packages/tracing-internal/src/browser/browsertracing.ts b/packages/tracing-internal/src/browser/browsertracing.ts index 13cde107074f..aae66bee3358 100644 --- a/packages/tracing-internal/src/browser/browsertracing.ts +++ b/packages/tracing-internal/src/browser/browsertracing.ts @@ -162,7 +162,7 @@ export class BrowserTracing implements Integration { /** * @inheritDoc */ - public name: string = BROWSER_TRACING_INTEGRATION_ID; + public name: string; private _getCurrentHub?: () => Hub; @@ -171,9 +171,12 @@ export class BrowserTracing implements Integration { private _collectWebVitals: () => void; - private _hasSetTracePropagationTargets: boolean = false; + private _hasSetTracePropagationTargets: boolean; public constructor(_options?: Partial) { + this.name = BROWSER_TRACING_INTEGRATION_ID; + this._hasSetTracePropagationTargets = false; + addTracingExtensions(); if (__DEBUG_BUILD__) { diff --git a/packages/tracing-internal/src/node/integrations/apollo.ts b/packages/tracing-internal/src/node/integrations/apollo.ts index 5a9c0219a00c..f004d6533c61 100644 --- a/packages/tracing-internal/src/node/integrations/apollo.ts +++ b/packages/tracing-internal/src/node/integrations/apollo.ts @@ -43,7 +43,7 @@ export class Apollo implements LazyLoadedIntegration { /** * @inheritDoc */ - public name: string = GraphQL.id; + public name: string; private _module?: GraphQLModule; + public constructor() { + this.name = GraphQL.id; + } + /** @inheritdoc */ public loadDependency(): GraphQLModule | undefined { return (this._module = this._module || loadModule('graphql/execution/execute.js')); diff --git a/packages/tracing-internal/src/node/integrations/mongo.ts b/packages/tracing-internal/src/node/integrations/mongo.ts index e7118378cb4c..637b7d124b33 100644 --- a/packages/tracing-internal/src/node/integrations/mongo.ts +++ b/packages/tracing-internal/src/node/integrations/mongo.ts @@ -111,7 +111,7 @@ export class Mongo implements LazyLoadedIntegration { /** * @inheritDoc */ - public name: string = Mongo.id; + public name: string; private _operations: Operation[]; private _describeOperations?: boolean | Operation[]; @@ -123,6 +123,7 @@ export class Mongo implements LazyLoadedIntegration { * @inheritDoc */ public constructor(options: MongoOptions = {}) { + this.name = Mongo.id; this._operations = Array.isArray(options.operations) ? options.operations : (OPERATIONS as unknown as Operation[]); this._describeOperations = 'describeOperations' in options ? options.describeOperations : true; this._useMongoose = !!options.useMongoose; diff --git a/packages/tracing-internal/src/node/integrations/mysql.ts b/packages/tracing-internal/src/node/integrations/mysql.ts index e907b30e379a..8f85de1c9a8f 100644 --- a/packages/tracing-internal/src/node/integrations/mysql.ts +++ b/packages/tracing-internal/src/node/integrations/mysql.ts @@ -19,10 +19,14 @@ export class Mysql implements LazyLoadedIntegration { /** * @inheritDoc */ - public name: string = Mysql.id; + public name: string; private _module?: MysqlConnection; + public constructor() { + this.name = Mysql.id; + } + /** @inheritdoc */ public loadDependency(): MysqlConnection | undefined { return (this._module = this._module || loadModule('mysql/lib/Connection.js')); diff --git a/packages/tracing-internal/src/node/integrations/postgres.ts b/packages/tracing-internal/src/node/integrations/postgres.ts index 3c33099eabf0..85c021c4f24b 100644 --- a/packages/tracing-internal/src/node/integrations/postgres.ts +++ b/packages/tracing-internal/src/node/integrations/postgres.ts @@ -27,13 +27,14 @@ export class Postgres implements LazyLoadedIntegration { /** * @inheritDoc */ - public name: string = Postgres.id; + public name: string; private _usePgNative: boolean; private _module?: PGModule; public constructor(options: PgOptions = {}) { + this.name = Postgres.id; this._usePgNative = !!options.usePgNative; } diff --git a/packages/tracing-internal/src/node/integrations/prisma.ts b/packages/tracing-internal/src/node/integrations/prisma.ts index 359ff887b024..fad8672c89a2 100644 --- a/packages/tracing-internal/src/node/integrations/prisma.ts +++ b/packages/tracing-internal/src/node/integrations/prisma.ts @@ -53,12 +53,14 @@ export class Prisma implements Integration { /** * @inheritDoc */ - public name: string = Prisma.id; + public name: string; /** * @inheritDoc */ public constructor(options: { client?: unknown } = {}) { + this.name = Prisma.id; + // We instrument the PrismaClient inside the constructor and not inside `setupOnce` because in some cases of server-side // bundling (Next.js) multiple Prisma clients can be instantiated, even though users don't intend to. When instrumenting // in setupOnce we can only ever instrument one client. diff --git a/packages/utils/src/syncpromise.ts b/packages/utils/src/syncpromise.ts index ec5cd9e9faee..e4ebda979300 100644 --- a/packages/utils/src/syncpromise.ts +++ b/packages/utils/src/syncpromise.ts @@ -47,13 +47,16 @@ export function rejectedSyncPromise(reason?: any): PromiseLike { * but is not async internally */ class SyncPromise implements PromiseLike { - private _state: States = States.PENDING; - private _handlers: Array<[boolean, (value: T) => void, (reason: any) => any]> = []; + private _state: States; + private _handlers: Array<[boolean, (value: T) => void, (reason: any) => any]>; private _value: any; public constructor( executor: (resolve: (value?: T | PromiseLike | null) => void, reject: (reason?: any) => void) => void, ) { + this._state = States.PENDING; + this._handlers = []; + try { executor(this._resolve, this._reject); } catch (e) { diff --git a/packages/wasm/src/index.ts b/packages/wasm/src/index.ts index 8d79586eb1d3..c07f9cd7ca16 100644 --- a/packages/wasm/src/index.ts +++ b/packages/wasm/src/index.ts @@ -40,7 +40,11 @@ export class Wasm implements Integration { /** * @inheritDoc */ - public name: string = Wasm.id; + public name: string; + + public constructor() { + this.name = Wasm.id; + } /** * @inheritDoc