From 2f99bdfefcedb0320b2ba4effc9b5e4b67506f0f Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 31 Oct 2024 17:35:17 -0400 Subject: [PATCH 1/3] feat: Deprecate metrics API --- .size-limit.js | 14 ------------- packages/astro/src/index.server.ts | 1 + packages/aws-serverless/src/index.ts | 1 + packages/browser/src/metrics.ts | 20 +++++++++++++----- packages/bun/src/index.ts | 1 + packages/cloudflare/src/index.ts | 1 + packages/core/src/index.ts | 2 ++ packages/core/src/metrics/aggregator.ts | 1 + packages/core/src/metrics/exports-default.ts | 21 ++++++++++++++----- packages/core/src/metrics/exports.ts | 17 ++++++++++----- packages/core/test/lib/metrics/timing.test.ts | 1 + packages/deno/src/index.ts | 1 + packages/deno/src/sdk.ts | 1 - packages/google-cloud-serverless/src/index.ts | 1 + packages/nextjs/src/index.types.ts | 1 + packages/node/src/index.ts | 1 + packages/remix/src/index.server.ts | 1 + packages/remix/src/index.types.ts | 1 + packages/solidstart/src/index.types.ts | 1 + packages/solidstart/src/server/index.ts | 1 + packages/sveltekit/src/index.types.ts | 1 + packages/vercel-edge/src/index.ts | 1 + 22 files changed, 61 insertions(+), 30 deletions(-) diff --git a/.size-limit.js b/.size-limit.js index 75545fd89194..d26804fe2faf 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -88,20 +88,6 @@ module.exports = [ gzip: true, limit: '95 KB', }, - { - name: '@sentry/browser (incl. Tracing, Replay, Feedback, metrics)', - path: 'packages/browser/build/npm/esm/index.js', - import: createImport('init', 'browserTracingIntegration', 'replayIntegration', 'feedbackIntegration', 'metrics'), - gzip: true, - limit: '100 KB', - }, - { - name: '@sentry/browser (incl. metrics)', - path: 'packages/browser/build/npm/esm/index.js', - import: createImport('init', 'metrics'), - gzip: true, - limit: '30 KB', - }, { name: '@sentry/browser (incl. Feedback)', path: 'packages/browser/build/npm/esm/index.js', diff --git a/packages/astro/src/index.server.ts b/packages/astro/src/index.server.ts index b544b71087fc..27d83ce7980b 100644 --- a/packages/astro/src/index.server.ts +++ b/packages/astro/src/index.server.ts @@ -74,6 +74,7 @@ export { localVariablesIntegration, lruMemoizerIntegration, makeNodeTransport, + // eslint-disable-next-line deprecation/deprecation metrics, modulesIntegration, mongoIntegration, diff --git a/packages/aws-serverless/src/index.ts b/packages/aws-serverless/src/index.ts index cc7f783c40fd..faa43522f2fc 100644 --- a/packages/aws-serverless/src/index.ts +++ b/packages/aws-serverless/src/index.ts @@ -73,6 +73,7 @@ export { continueTrace, getAutoPerformanceIntegrations, cron, + // eslint-disable-next-line deprecation/deprecation metrics, parameterize, SEMANTIC_ATTRIBUTE_SENTRY_OP, diff --git a/packages/browser/src/metrics.ts b/packages/browser/src/metrics.ts index 39529af3e4a0..00d73ec33b1c 100644 --- a/packages/browser/src/metrics.ts +++ b/packages/browser/src/metrics.ts @@ -4,36 +4,40 @@ import type { DurationUnit, MetricData, Metrics } from '@sentry/types'; /** * Adds a value to a counter metric * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function increment(name: string, value: number = 1, data?: MetricData): void { + // eslint-disable-next-line deprecation/deprecation metricsCore.increment(BrowserMetricsAggregator, name, value, data); } /** * Adds a value to a distribution metric * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function distribution(name: string, value: number, data?: MetricData): void { + // eslint-disable-next-line deprecation/deprecation metricsCore.distribution(BrowserMetricsAggregator, name, value, data); } /** * Adds a value to a set metric. Value must be a string or integer. * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function set(name: string, value: number | string, data?: MetricData): void { + // eslint-disable-next-line deprecation/deprecation metricsCore.set(BrowserMetricsAggregator, name, value, data); } /** * Adds a value to a gauge metric * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function gauge(name: string, value: number, data?: MetricData): void { + // eslint-disable-next-line deprecation/deprecation metricsCore.gauge(BrowserMetricsAggregator, name, value, data); } @@ -44,7 +48,7 @@ function gauge(name: string, value: number, data?: MetricData): void { * You can either directly capture a numeric `value`, or wrap a callback function in `timing`. * In the latter case, the duration of the callback execution will be captured as a span & a metric. * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function timing(name: string, value: number, unit?: DurationUnit, data?: Omit): void; function timing(name: string, callback: () => T, unit?: DurationUnit, data?: Omit): T; @@ -54,9 +58,15 @@ function timing( unit: DurationUnit = 'second', data?: Omit, ): T | void { + // eslint-disable-next-line deprecation/deprecation return metricsCore.timing(BrowserMetricsAggregator, name, value, unit, data); } +/** + * The metrics API is used to capture custom metrics in Sentry. + * + * @deprecated The Sentry metrics beta has ended. This export will be removed in a future release. + */ export const metrics: Metrics = { increment, distribution, diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index 7ccca26a3da6..4d8e9fbb1310 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -94,6 +94,7 @@ export { continueTrace, getAutoPerformanceIntegrations, cron, + // eslint-disable-next-line deprecation/deprecation metrics, parameterize, SEMANTIC_ATTRIBUTE_SENTRY_OP, diff --git a/packages/cloudflare/src/index.ts b/packages/cloudflare/src/index.ts index 7c0aa6018313..fa0d76a54521 100644 --- a/packages/cloudflare/src/index.ts +++ b/packages/cloudflare/src/index.ts @@ -65,6 +65,7 @@ export { withActiveSpan, getSpanDescendants, continueTrace, + // eslint-disable-next-line deprecation/deprecation metrics, functionToStringIntegration, inboundFiltersIntegration, diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 24cea1bea7ca..598b0168f3ef 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -99,9 +99,11 @@ export { rewriteFramesIntegration } from './integrations/rewriteframes'; export { sessionTimingIntegration } from './integrations/sessiontiming'; export { zodErrorsIntegration } from './integrations/zoderrors'; export { thirdPartyErrorFilterIntegration } from './integrations/third-party-errors-filter'; +// eslint-disable-next-line deprecation/deprecation export { metrics } from './metrics/exports'; export { profiler } from './profiling'; export type { MetricData } from '@sentry/types'; +// eslint-disable-next-line deprecation/deprecation export { metricsDefault } from './metrics/exports-default'; export { BrowserMetricsAggregator } from './metrics/browser-aggregator'; export { getMetricSummaryJsonForSpan } from './metrics/metric-summary'; diff --git a/packages/core/src/metrics/aggregator.ts b/packages/core/src/metrics/aggregator.ts index 8752d2a10df7..c87fd14e34f9 100644 --- a/packages/core/src/metrics/aggregator.ts +++ b/packages/core/src/metrics/aggregator.ts @@ -40,6 +40,7 @@ export class MetricsAggregator implements MetricsAggregatorBase { this._buckets = new Map(); this._bucketsTotalWeight = 0; + // eslint-disable-next-line @typescript-eslint/no-explicit-any this._interval = setInterval(() => this._flush(), DEFAULT_FLUSH_INTERVAL) as any; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access if (this._interval.unref) { diff --git a/packages/core/src/metrics/exports-default.ts b/packages/core/src/metrics/exports-default.ts index 1e4a6487b9a2..7a271696f025 100644 --- a/packages/core/src/metrics/exports-default.ts +++ b/packages/core/src/metrics/exports-default.ts @@ -11,36 +11,40 @@ import { metrics as metricsCore } from './exports'; /** * Adds a value to a counter metric * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function increment(name: string, value: number = 1, data?: MetricData): void { + // eslint-disable-next-line deprecation/deprecation metricsCore.increment(MetricsAggregator, name, value, data); } /** * Adds a value to a distribution metric * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function distribution(name: string, value: number, data?: MetricData): void { + // eslint-disable-next-line deprecation/deprecation metricsCore.distribution(MetricsAggregator, name, value, data); } /** * Adds a value to a set metric. Value must be a string or integer. * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function set(name: string, value: number | string, data?: MetricData): void { + // eslint-disable-next-line deprecation/deprecation metricsCore.set(MetricsAggregator, name, value, data); } /** * Adds a value to a gauge metric * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function gauge(name: string, value: number, data?: MetricData): void { + // eslint-disable-next-line deprecation/deprecation metricsCore.gauge(MetricsAggregator, name, value, data); } @@ -51,7 +55,7 @@ function gauge(name: string, value: number, data?: MetricData): void { * You can either directly capture a numeric `value`, or wrap a callback function in `timing`. * In the latter case, the duration of the callback execution will be captured as a span & a metric. * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function timing(name: string, value: number, unit?: DurationUnit, data?: Omit): void; function timing(name: string, callback: () => T, unit?: DurationUnit, data?: Omit): T; @@ -61,6 +65,7 @@ function timing( unit: DurationUnit = 'second', data?: Omit, ): T | void { + // eslint-disable-next-line deprecation/deprecation return metricsCore.timing(MetricsAggregator, name, value, unit, data); } @@ -68,9 +73,15 @@ function timing( * Returns the metrics aggregator for a given client. */ function getMetricsAggregatorForClient(client: Client): MetricsAggregatorInterface { + // eslint-disable-next-line deprecation/deprecation return metricsCore.getMetricsAggregatorForClient(client, MetricsAggregator); } +/** + * The metrics API is used to capture custom metrics in Sentry. + * + * @deprecated The Sentry metrics beta has ended. This export will be removed in a future release. + */ export const metricsDefault: Metrics & { getMetricsAggregatorForClient: typeof getMetricsAggregatorForClient; } = { diff --git a/packages/core/src/metrics/exports.ts b/packages/core/src/metrics/exports.ts index 752471856153..2b3cdbcef8ba 100644 --- a/packages/core/src/metrics/exports.ts +++ b/packages/core/src/metrics/exports.ts @@ -78,7 +78,7 @@ function addToMetricsAggregator( /** * Adds a value to a counter metric * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function increment(aggregator: MetricsAggregatorConstructor, name: string, value: number = 1, data?: MetricData): void { addToMetricsAggregator(aggregator, COUNTER_METRIC_TYPE, name, ensureNumber(value), data); @@ -87,7 +87,7 @@ function increment(aggregator: MetricsAggregatorConstructor, name: string, value /** * Adds a value to a distribution metric * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function distribution(aggregator: MetricsAggregatorConstructor, name: string, value: number, data?: MetricData): void { addToMetricsAggregator(aggregator, DISTRIBUTION_METRIC_TYPE, name, ensureNumber(value), data); @@ -100,7 +100,7 @@ function distribution(aggregator: MetricsAggregatorConstructor, name: string, va * You can either directly capture a numeric `value`, or wrap a callback function in `timing`. * In the latter case, the duration of the callback execution will be captured as a span & a metric. * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function timing( aggregator: MetricsAggregatorConstructor, @@ -129,6 +129,7 @@ function timing( () => { const endTime = timestampInSeconds(); const timeDiff = endTime - startTime; + // eslint-disable-next-line deprecation/deprecation distribution(aggregator, name, timeDiff, { ...data, unit: 'second' }); span.end(endTime); }, @@ -138,13 +139,14 @@ function timing( } // value form + // eslint-disable-next-line deprecation/deprecation distribution(aggregator, name, value, { ...data, unit }); } /** * Adds a value to a set metric. Value must be a string or integer. * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function set(aggregator: MetricsAggregatorConstructor, name: string, value: number | string, data?: MetricData): void { addToMetricsAggregator(aggregator, SET_METRIC_TYPE, name, value, data); @@ -153,12 +155,17 @@ function set(aggregator: MetricsAggregatorConstructor, name: string, value: numb /** * Adds a value to a gauge metric * - * @experimental This API is experimental and might have breaking changes in the future. + * @deprecated The Sentry metrics beta has ended. This method will be removed in a future release. */ function gauge(aggregator: MetricsAggregatorConstructor, name: string, value: number, data?: MetricData): void { addToMetricsAggregator(aggregator, GAUGE_METRIC_TYPE, name, ensureNumber(value), data); } +/** + * The metrics API is used to capture custom metrics in Sentry. + * + * @deprecated The Sentry metrics beta has ended. This export will be removed in a future release. + */ export const metrics = { increment, distribution, diff --git a/packages/core/test/lib/metrics/timing.test.ts b/packages/core/test/lib/metrics/timing.test.ts index fa7c9f88da77..3e48047c9175 100644 --- a/packages/core/test/lib/metrics/timing.test.ts +++ b/packages/core/test/lib/metrics/timing.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable deprecation/deprecation */ import { getCurrentScope, getIsolationScope, setCurrentClient } from '../../../src'; import { MetricsAggregator } from '../../../src/metrics/aggregator'; import { metrics as metricsCore } from '../../../src/metrics/exports'; diff --git a/packages/deno/src/index.ts b/packages/deno/src/index.ts index 8a0a2a49fdcc..c7328c810f92 100644 --- a/packages/deno/src/index.ts +++ b/packages/deno/src/index.ts @@ -62,6 +62,7 @@ export { startSpanManual, startNewTrace, suppressTracing, + // eslint-disable-next-line deprecation/deprecation metricsDefault as metrics, inboundFiltersIntegration, linkedErrorsIntegration, diff --git a/packages/deno/src/sdk.ts b/packages/deno/src/sdk.ts index c2a459b4db33..4072196c721f 100644 --- a/packages/deno/src/sdk.ts +++ b/packages/deno/src/sdk.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/consistent-type-imports */ import type { ServerRuntimeClientOptions } from '@sentry/core'; import { dedupeIntegration, diff --git a/packages/google-cloud-serverless/src/index.ts b/packages/google-cloud-serverless/src/index.ts index 80dba64cef97..6bb4bbcd30a7 100644 --- a/packages/google-cloud-serverless/src/index.ts +++ b/packages/google-cloud-serverless/src/index.ts @@ -74,6 +74,7 @@ export { continueTrace, getAutoPerformanceIntegrations, cron, + // eslint-disable-next-line deprecation/deprecation metrics, parameterize, SEMANTIC_ATTRIBUTE_SENTRY_OP, diff --git a/packages/nextjs/src/index.types.ts b/packages/nextjs/src/index.types.ts index 8f09999ad738..636d6c49815a 100644 --- a/packages/nextjs/src/index.types.ts +++ b/packages/nextjs/src/index.types.ts @@ -36,6 +36,7 @@ export declare const createReduxEnhancer: typeof clientSdk.createReduxEnhancer; export declare const showReportDialog: typeof clientSdk.showReportDialog; export declare const withErrorBoundary: typeof clientSdk.withErrorBoundary; +// eslint-disable-next-line deprecation/deprecation export declare const metrics: typeof clientSdk.metrics & typeof serverSdk.metrics; export { withSentryConfig } from './config'; diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index 2e658f7abc36..4e1d1be22a8f 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -116,6 +116,7 @@ export { extraErrorDataIntegration, rewriteFramesIntegration, sessionTimingIntegration, + // eslint-disable-next-line deprecation/deprecation metricsDefault as metrics, startSession, captureSession, diff --git a/packages/remix/src/index.server.ts b/packages/remix/src/index.server.ts index 098bd1293080..ffb5cf74983f 100644 --- a/packages/remix/src/index.server.ts +++ b/packages/remix/src/index.server.ts @@ -74,6 +74,7 @@ export { linkedErrorsIntegration, localVariablesIntegration, makeNodeTransport, + // eslint-disable-next-line deprecation/deprecation metrics, modulesIntegration, mongoIntegration, diff --git a/packages/remix/src/index.types.ts b/packages/remix/src/index.types.ts index b3342ff35250..b7b7bd9d9a73 100644 --- a/packages/remix/src/index.types.ts +++ b/packages/remix/src/index.types.ts @@ -39,4 +39,5 @@ export const close = runtime === 'client' ? clientSdk.close : serverSdk.close; export const flush = runtime === 'client' ? clientSdk.flush : serverSdk.flush; export const lastEventId = runtime === 'client' ? clientSdk.lastEventId : serverSdk.lastEventId; +// eslint-disable-next-line deprecation/deprecation export declare const metrics: typeof clientSdk.metrics & typeof serverSdk.metrics; diff --git a/packages/solidstart/src/index.types.ts b/packages/solidstart/src/index.types.ts index ef3cd196651b..13ff38425a1c 100644 --- a/packages/solidstart/src/index.types.ts +++ b/packages/solidstart/src/index.types.ts @@ -27,4 +27,5 @@ export declare function lastEventId(): string | undefined; export declare const continueTrace: typeof clientSdk.continueTrace; +// eslint-disable-next-line deprecation/deprecation export declare const metrics: typeof clientSdk.metrics & typeof serverSdk.metrics; diff --git a/packages/solidstart/src/server/index.ts b/packages/solidstart/src/server/index.ts index d537ddd51e88..ccec95b916d3 100644 --- a/packages/solidstart/src/server/index.ts +++ b/packages/solidstart/src/server/index.ts @@ -65,6 +65,7 @@ export { linkedErrorsIntegration, localVariablesIntegration, makeNodeTransport, + // eslint-disable-next-line deprecation/deprecation metrics, modulesIntegration, mongoIntegration, diff --git a/packages/sveltekit/src/index.types.ts b/packages/sveltekit/src/index.types.ts index 4cccbf2a1ab7..bdd8a23c3c70 100644 --- a/packages/sveltekit/src/index.types.ts +++ b/packages/sveltekit/src/index.types.ts @@ -52,6 +52,7 @@ export declare function lastEventId(): string | undefined; export declare const continueTrace: typeof clientSdk.continueTrace; +// eslint-disable-next-line deprecation/deprecation export declare const metrics: typeof clientSdk.metrics & typeof serverSdk.metrics; export declare function trackComponent(options: clientSdk.TrackingOptions): ReturnType; diff --git a/packages/vercel-edge/src/index.ts b/packages/vercel-edge/src/index.ts index 7eb7893e974a..e222d2de1ad1 100644 --- a/packages/vercel-edge/src/index.ts +++ b/packages/vercel-edge/src/index.ts @@ -65,6 +65,7 @@ export { withActiveSpan, getSpanDescendants, continueTrace, + // eslint-disable-next-line deprecation/deprecation metrics, functionToStringIntegration, inboundFiltersIntegration, From 0fb1203ccacb9602309e00d637bb6348ffb73286 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 4 Nov 2024 12:07:53 -0500 Subject: [PATCH 2/3] fix missing eslint disables --- packages/astro/src/index.types.ts | 1 + packages/nuxt/src/index.types.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/astro/src/index.types.ts b/packages/astro/src/index.types.ts index f30357a91c4a..c05cfb4a3215 100644 --- a/packages/astro/src/index.types.ts +++ b/packages/astro/src/index.types.ts @@ -32,5 +32,6 @@ export declare const continueTrace: typeof clientSdk.continueTrace; export declare const Span: clientSdk.Span; +// eslint-disable-next-line deprecation/deprecation export declare const metrics: typeof clientSdk.metrics & typeof serverSdk; export default sentryAstro; diff --git a/packages/nuxt/src/index.types.ts b/packages/nuxt/src/index.types.ts index eca64effb5b4..ceb6c7fc207c 100644 --- a/packages/nuxt/src/index.types.ts +++ b/packages/nuxt/src/index.types.ts @@ -15,4 +15,5 @@ export declare const contextLinesIntegration: typeof clientSdk.contextLinesInteg export declare const getDefaultIntegrations: (options: Options) => Integration[]; export declare const defaultStackParser: StackParser; export declare const continueTrace: typeof clientSdk.continueTrace; +// eslint-disable-next-line deprecation/deprecation export declare const metrics: typeof clientSdk.metrics & typeof serverSdk.metrics; From cbb02a190c51fcecd42689f9016dc08b0a101497 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 4 Nov 2024 13:15:49 -0500 Subject: [PATCH 3/3] forgot about sveltekit --- packages/sveltekit/src/server/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/sveltekit/src/server/index.ts b/packages/sveltekit/src/server/index.ts index 72b459e2fde3..728616945286 100644 --- a/packages/sveltekit/src/server/index.ts +++ b/packages/sveltekit/src/server/index.ts @@ -67,6 +67,7 @@ export { linkedErrorsIntegration, localVariablesIntegration, makeNodeTransport, + // eslint-disable-next-line deprecation/deprecation metrics, modulesIntegration, mongoIntegration,