diff --git a/.size-limit.js b/.size-limit.js index cada598de81b..da5cbd75ac46 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -190,7 +190,7 @@ module.exports = [ path: createCDNPath('bundle.tracing.min.js'), gzip: false, brotli: false, - limit: '124.1 KB', + limit: '125 KB', }, { name: 'CDN Bundle (incl. Tracing, Replay) - uncompressed', diff --git a/dev-packages/browser-integration-tests/suites/public-api/metrics/init.js b/dev-packages/browser-integration-tests/suites/public-api/metrics/init.js index df4fda70e4c7..73c6e63ed335 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/metrics/init.js +++ b/dev-packages/browser-integration-tests/suites/public-api/metrics/init.js @@ -4,9 +4,6 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - _experiments: { - enableMetrics: true, - }, release: '1.0.0', environment: 'test', integrations: integrations => { diff --git a/dev-packages/node-core-integration-tests/suites/public-api/metrics/scenario.ts b/dev-packages/node-core-integration-tests/suites/public-api/metrics/scenario.ts index 9ab9fed7d22b..77adfae79802 100644 --- a/dev-packages/node-core-integration-tests/suites/public-api/metrics/scenario.ts +++ b/dev-packages/node-core-integration-tests/suites/public-api/metrics/scenario.ts @@ -6,9 +6,6 @@ const client = Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', release: '1.0.0', environment: 'test', - _experiments: { - enableMetrics: true, - }, transport: loggingTransport, }); diff --git a/dev-packages/node-integration-tests/suites/public-api/metrics/scenario.ts b/dev-packages/node-integration-tests/suites/public-api/metrics/scenario.ts index 9c776eb14d59..8d02a1fcd17c 100644 --- a/dev-packages/node-integration-tests/suites/public-api/metrics/scenario.ts +++ b/dev-packages/node-integration-tests/suites/public-api/metrics/scenario.ts @@ -5,9 +5,6 @@ Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', release: '1.0.0', environment: 'test', - _experiments: { - enableMetrics: true, - }, transport: loggingTransport, }); diff --git a/packages/browser/src/client.ts b/packages/browser/src/client.ts index 1b4289d66992..dddaa440b198 100644 --- a/packages/browser/src/client.ts +++ b/packages/browser/src/client.ts @@ -104,10 +104,22 @@ export class BrowserClient extends Client { super(opts); - const { sendDefaultPii, sendClientReports, enableLogs, _experiments } = this._options; + const { + sendDefaultPii, + sendClientReports, + enableLogs, + _experiments, + enableMetrics: enableMetricsOption, + } = this._options; + + // todo(v11): Remove the experimental flag + // eslint-disable-next-line deprecation/deprecation + const enableMetrics = enableMetricsOption ?? _experiments?.enableMetrics ?? true; // Flush logs and metrics when page becomes hidden (e.g., tab switch, navigation) - if (WINDOW.document && (sendClientReports || enableLogs || _experiments?.enableMetrics)) { + // todo(v11): Remove the experimental flag + // eslint-disable-next-line deprecation/deprecation + if (WINDOW.document && (sendClientReports || enableLogs || enableMetrics)) { WINDOW.document.addEventListener('visibilitychange', () => { if (WINDOW.document.visibilityState === 'hidden') { if (sendClientReports) { @@ -116,7 +128,8 @@ export class BrowserClient extends Client { if (enableLogs) { _INTERNAL_flushLogsBuffer(this); } - if (_experiments?.enableMetrics) { + + if (enableMetrics) { _INTERNAL_flushMetricsBuffer(this); } } diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 6a269a969c8d..44c55094a1d1 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -232,8 +232,12 @@ export abstract class Client { setupWeightBasedFlushing(this, 'afterCaptureLog', 'flushLogs', estimateLogSizeInBytes, _INTERNAL_flushLogsBuffer); } + // todo(v11): Remove the experimental flag + // eslint-disable-next-line deprecation/deprecation + const enableMetrics = this._options.enableMetrics ?? this._options._experiments?.enableMetrics ?? true; + // Setup metric flushing with weight and timeout tracking - if (this._options._experiments?.enableMetrics) { + if (enableMetrics) { setupWeightBasedFlushing( this, 'afterCaptureMetric', diff --git a/packages/core/src/metrics/internal.ts b/packages/core/src/metrics/internal.ts index efa204cac5a3..505ab28a0020 100644 --- a/packages/core/src/metrics/internal.ts +++ b/packages/core/src/metrics/internal.ts @@ -116,35 +116,16 @@ export interface InternalCaptureMetricOptions { } /** - * Captures a metric event and sends it to Sentry. - * - * @param metric - The metric event to capture. - * @param options - Options for capturing the metric. - * - * @experimental This method will experience breaking changes. This is not yet part of - * the stable Sentry SDK API and can be changed or removed without warning. + * Enriches metric with all contextual attributes (user, SDK metadata, replay, etc.) */ -export function _INTERNAL_captureMetric(beforeMetric: Metric, options?: InternalCaptureMetricOptions): void { - const currentScope = options?.scope ?? getCurrentScope(); - const captureSerializedMetric = options?.captureSerializedMetric ?? _INTERNAL_captureSerializedMetric; - const client = currentScope?.getClient() ?? getClient(); - if (!client) { - DEBUG_BUILD && debug.warn('No client available to capture metric.'); - return; - } - - const { release, environment, _experiments } = client.getOptions(); - if (!_experiments?.enableMetrics) { - DEBUG_BUILD && debug.warn('metrics option not enabled, metric will not be captured.'); - return; - } - - const [, traceContext] = _getTraceInfoFromScope(client, currentScope); +function _enrichMetricAttributes(beforeMetric: Metric, client: Client, currentScope: Scope): Metric { + const { release, environment } = client.getOptions(); const processedMetricAttributes = { ...beforeMetric.attributes, }; + // Add user attributes const { user: { id, email, username }, } = getMergedScopeData(currentScope); @@ -152,13 +133,16 @@ export function _INTERNAL_captureMetric(beforeMetric: Metric, options?: Internal setMetricAttribute(processedMetricAttributes, 'user.email', email, false); setMetricAttribute(processedMetricAttributes, 'user.name', username, false); + // Add Sentry metadata setMetricAttribute(processedMetricAttributes, 'sentry.release', release); setMetricAttribute(processedMetricAttributes, 'sentry.environment', environment); + // Add SDK metadata const { name, version } = client.getSdkMetadata()?.sdk ?? {}; setMetricAttribute(processedMetricAttributes, 'sentry.sdk.name', name); setMetricAttribute(processedMetricAttributes, 'sentry.sdk.version', version); + // Add replay metadata const replay = client.getIntegrationByName< Integration & { getReplayId: (onlyIfSampled?: boolean) => string; @@ -167,54 +151,97 @@ export function _INTERNAL_captureMetric(beforeMetric: Metric, options?: Internal >('Replay'); const replayId = replay?.getReplayId(true); - setMetricAttribute(processedMetricAttributes, 'sentry.replay_id', replayId); if (replayId && replay?.getRecordingMode() === 'buffer') { - // We send this so we can identify cases where the replayId is attached but the replay itself might not have been sent to Sentry setMetricAttribute(processedMetricAttributes, 'sentry._internal.replay_is_buffering', true); } - const metric: Metric = { + return { ...beforeMetric, attributes: processedMetricAttributes, }; +} - // Run beforeSendMetric callback - const processedMetric = _experiments?.beforeSendMetric ? _experiments.beforeSendMetric(metric) : metric; - - if (!processedMetric) { - DEBUG_BUILD && debug.log('`beforeSendMetric` returned `null`, will not send metric.'); - return; - } - +/** + * Creates a serialized metric ready to be sent to Sentry. + */ +function _buildSerializedMetric(metric: Metric, client: Client, currentScope: Scope): SerializedMetric { + // Serialize attributes const serializedAttributes: Record = {}; - for (const key in processedMetric.attributes) { - if (processedMetric.attributes[key] !== undefined) { - serializedAttributes[key] = metricAttributeToSerializedMetricAttribute(processedMetric.attributes[key]); + for (const key in metric.attributes) { + if (metric.attributes[key] !== undefined) { + serializedAttributes[key] = metricAttributeToSerializedMetricAttribute(metric.attributes[key]); } } + // Get trace context + const [, traceContext] = _getTraceInfoFromScope(client, currentScope); const span = _getSpanForScope(currentScope); const traceId = span ? span.spanContext().traceId : traceContext?.trace_id; const spanId = span ? span.spanContext().spanId : undefined; - const serializedMetric: SerializedMetric = { + return { timestamp: timestampInSeconds(), trace_id: traceId, span_id: spanId, - name: processedMetric.name, - type: processedMetric.type, - unit: processedMetric.unit, - value: processedMetric.value, + name: metric.name, + type: metric.type, + unit: metric.unit, + value: metric.value, attributes: serializedAttributes, }; +} + +/** + * Captures a metric event and sends it to Sentry. + * + * @param metric - The metric event to capture. + * @param options - Options for capturing the metric. + * + * @experimental This method will experience breaking changes. This is not yet part of + * the stable Sentry SDK API and can be changed or removed without warning. + */ +export function _INTERNAL_captureMetric(beforeMetric: Metric, options?: InternalCaptureMetricOptions): void { + const currentScope = options?.scope ?? getCurrentScope(); + const captureSerializedMetric = options?.captureSerializedMetric ?? _INTERNAL_captureSerializedMetric; + const client = currentScope?.getClient() ?? getClient(); + if (!client) { + DEBUG_BUILD && debug.warn('No client available to capture metric.'); + return; + } + + const { _experiments, enableMetrics, beforeSendMetric } = client.getOptions(); + + // todo(v11): Remove the experimental flag + // eslint-disable-next-line deprecation/deprecation + const metricsEnabled = enableMetrics ?? _experiments?.enableMetrics ?? true; + + if (!metricsEnabled) { + DEBUG_BUILD && debug.warn('metrics option not enabled, metric will not be captured.'); + return; + } + + // Enrich metric with contextual attributes + const enrichedMetric = _enrichMetricAttributes(beforeMetric, client, currentScope); + + // todo(v11): Remove the experimental `beforeSendMetric` + // eslint-disable-next-line deprecation/deprecation + const beforeSendCallback = beforeSendMetric || _experiments?.beforeSendMetric; + const processedMetric = beforeSendCallback ? beforeSendCallback(enrichedMetric) : enrichedMetric; + + if (!processedMetric) { + DEBUG_BUILD && debug.log('`beforeSendMetric` returned `null`, will not send metric.'); + return; + } + + const serializedMetric = _buildSerializedMetric(processedMetric, client, currentScope); DEBUG_BUILD && debug.log('[Metric]', serializedMetric); captureSerializedMetric(client, serializedMetric); - client.emit('afterCaptureMetric', metric); + client.emit('afterCaptureMetric', enrichedMetric); } /** diff --git a/packages/core/src/types-hoist/options.ts b/packages/core/src/types-hoist/options.ts index 2d4c0e6b43a4..ccdc3b180e15 100644 --- a/packages/core/src/types-hoist/options.ts +++ b/packages/core/src/types-hoist/options.ts @@ -287,6 +287,7 @@ export interface ClientOptions Metric | null; }; @@ -401,6 +403,27 @@ export interface ClientOptions Log | null; + /** + * If metrics support should be enabled. + * + * @default true + */ + enableMetrics?: boolean; + + /** + * An event-processing callback for metrics, guaranteed to be invoked after all other metric + * processors. This allows a metric to be modified or dropped before it's sent. + * + * Note that you must return a valid metric from this callback. If you do not wish to modify the metric, simply return + * it at the end. Returning `null` will cause the metric to be dropped. + * + * @default undefined + * + * @param metric The metric generated by the SDK. + * @returns A new metric that will be sent. + */ + beforeSendMetric?: (metric: Metric) => Metric; + /** * Function to compute tracing sample rate dynamically and filter unwanted traces. * diff --git a/packages/core/test/lib/client.test.ts b/packages/core/test/lib/client.test.ts index ae324aa40f9f..e678e73a9ad8 100644 --- a/packages/core/test/lib/client.test.ts +++ b/packages/core/test/lib/client.test.ts @@ -2753,7 +2753,6 @@ describe('Client', () => { it('flushes metrics when weight exceeds 800KB', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, }); const client = new TestClient(options); const scope = new Scope(); @@ -2771,7 +2770,6 @@ describe('Client', () => { it('accumulates metric weight without flushing when under threshold', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, }); const client = new TestClient(options); const scope = new Scope(); @@ -2788,7 +2786,6 @@ describe('Client', () => { it('flushes metrics on flush event', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, }); const client = new TestClient(options); const scope = new Scope(); diff --git a/packages/core/test/lib/metrics/internal.test.ts b/packages/core/test/lib/metrics/internal.test.ts index c0279c9a270b..d9d123b63e99 100644 --- a/packages/core/test/lib/metrics/internal.test.ts +++ b/packages/core/test/lib/metrics/internal.test.ts @@ -82,7 +82,7 @@ describe('metricAttributeToSerializedMetricAttribute', () => { describe('_INTERNAL_captureMetric', () => { it('captures and sends metrics', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -103,7 +103,7 @@ describe('_INTERNAL_captureMetric', () => { it('does not capture metrics when enableMetrics is not enabled', () => { const logWarnSpy = vi.spyOn(loggerModule.debug, 'warn').mockImplementation(() => undefined); - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableMetrics: false }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -117,7 +117,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('includes trace context when available', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -138,7 +138,6 @@ describe('_INTERNAL_captureMetric', () => { it('includes release and environment in metric attributes when available', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, release: '1.0.0', environment: 'test', }); @@ -164,7 +163,6 @@ describe('_INTERNAL_captureMetric', () => { it('includes SDK metadata in metric attributes when available', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, }); const client = new TestClient(options); const scope = new Scope(); @@ -195,7 +193,6 @@ describe('_INTERNAL_captureMetric', () => { it('does not include SDK metadata in metric attributes when not available', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, }); const client = new TestClient(options); const scope = new Scope(); @@ -215,7 +212,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('includes custom attributes in metric', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -244,7 +241,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('flushes metrics buffer when it reaches max size', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -263,7 +260,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('does not flush metrics buffer when it is empty', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const mockSendEnvelope = vi.spyOn(client as any, 'sendEnvelope').mockImplementation(() => {}); @@ -280,7 +277,7 @@ describe('_INTERNAL_captureMetric', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true, beforeSendMetric }, + beforeSendMetric, }); const client = new TestClient(options); const scope = new Scope(); @@ -328,7 +325,7 @@ describe('_INTERNAL_captureMetric', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true, beforeSendMetric }, + beforeSendMetric, }); const client = new TestClient(options); const scope = new Scope(); @@ -352,7 +349,7 @@ describe('_INTERNAL_captureMetric', () => { it('emits afterCaptureMetric event', () => { const afterCaptureMetricSpy = vi.spyOn(TestClient.prototype, 'emit'); - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -372,7 +369,7 @@ describe('_INTERNAL_captureMetric', () => { describe('replay integration with onlyIfSampled', () => { it('includes replay ID for sampled sessions', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -401,7 +398,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('excludes replay ID for unsampled sessions when onlyIfSampled=true', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -424,7 +421,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('includes replay ID for buffer mode sessions', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -457,7 +454,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('handles missing replay integration gracefully', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -474,7 +471,7 @@ describe('_INTERNAL_captureMetric', () => { it('combines replay ID with other metric attributes', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, + release: '1.0.0', environment: 'test', }); @@ -526,7 +523,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('does not set replay ID attribute when getReplayId returns null or undefined', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -552,7 +549,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('sets replay_is_buffering attribute when replay is in buffer mode', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -584,7 +581,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('does not set replay_is_buffering attribute when replay is in session mode', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -613,7 +610,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('does not set replay_is_buffering attribute when replay is undefined mode', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -642,7 +639,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('does not set replay_is_buffering attribute when no replay ID is available', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -668,7 +665,7 @@ describe('_INTERNAL_captureMetric', () => { }); it('does not set replay_is_buffering attribute when replay integration is missing', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -687,7 +684,7 @@ describe('_INTERNAL_captureMetric', () => { it('combines replay_is_buffering with other replay attributes', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, + release: '1.0.0', environment: 'test', }); @@ -747,7 +744,6 @@ describe('_INTERNAL_captureMetric', () => { it('includes user data in metric attributes', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, }); const client = new TestClient(options); const scope = new Scope(); @@ -780,7 +776,6 @@ describe('_INTERNAL_captureMetric', () => { it('includes partial user data when only some fields are available', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, }); const client = new TestClient(options); const scope = new Scope(); @@ -804,7 +799,6 @@ describe('_INTERNAL_captureMetric', () => { it('includes user email and username without id', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, }); const client = new TestClient(options); const scope = new Scope(); @@ -833,7 +827,6 @@ describe('_INTERNAL_captureMetric', () => { it('does not include user data when user object is empty', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, }); const client = new TestClient(options); const scope = new Scope(); @@ -849,7 +842,7 @@ describe('_INTERNAL_captureMetric', () => { it('combines user data with other metric attributes', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, + release: '1.0.0', environment: 'test', }); @@ -903,7 +896,6 @@ describe('_INTERNAL_captureMetric', () => { it('handles user data with non-string values', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, }); const client = new TestClient(options); const scope = new Scope(); @@ -932,7 +924,6 @@ describe('_INTERNAL_captureMetric', () => { it('preserves existing user attributes in metric and does not override them', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, }); const client = new TestClient(options); const scope = new Scope(); @@ -975,7 +966,6 @@ describe('_INTERNAL_captureMetric', () => { it('only adds scope user data for attributes that do not already exist', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, }); const client = new TestClient(options); const scope = new Scope(); @@ -1024,7 +1014,7 @@ describe('_INTERNAL_captureMetric', () => { it('overrides user-provided system attributes with SDK values', () => { const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, - _experiments: { enableMetrics: true }, + release: 'sdk-release-1.0.0', environment: 'sdk-environment', }); diff --git a/packages/core/test/lib/metrics/public-api.test.ts b/packages/core/test/lib/metrics/public-api.test.ts index 42fe7c41ae4a..df8ff49c5553 100644 --- a/packages/core/test/lib/metrics/public-api.test.ts +++ b/packages/core/test/lib/metrics/public-api.test.ts @@ -9,7 +9,7 @@ const PUBLIC_DSN = 'https://username@domain/123'; describe('Metrics Public API', () => { describe('count', () => { it('captures a counter metric with default value of 1', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -28,7 +28,7 @@ describe('Metrics Public API', () => { }); it('captures a counter metric with custom value', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -47,7 +47,7 @@ describe('Metrics Public API', () => { }); it('captures a counter metric with attributes', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -87,7 +87,7 @@ describe('Metrics Public API', () => { }); it('captures a counter metric with unit', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -110,7 +110,7 @@ describe('Metrics Public API', () => { }); it('does not capture counter when enableMetrics is not enabled', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableMetrics: false }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -123,7 +123,7 @@ describe('Metrics Public API', () => { describe('gauge', () => { it('captures a gauge metric', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -142,7 +142,7 @@ describe('Metrics Public API', () => { }); it('captures a gauge metric with unit', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -165,7 +165,7 @@ describe('Metrics Public API', () => { }); it('captures a gauge metric with attributes', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -200,7 +200,7 @@ describe('Metrics Public API', () => { }); it('does not capture gauge when enableMetrics is not enabled', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableMetrics: false }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -213,7 +213,7 @@ describe('Metrics Public API', () => { describe('distribution', () => { it('captures a distribution metric', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -232,7 +232,7 @@ describe('Metrics Public API', () => { }); it('captures a distribution metric with unit', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -255,7 +255,7 @@ describe('Metrics Public API', () => { }); it('captures a distribution metric with attributes', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -290,7 +290,7 @@ describe('Metrics Public API', () => { }); it('does not capture distribution when enableMetrics is not enabled', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableMetrics: false }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client); @@ -303,7 +303,7 @@ describe('Metrics Public API', () => { describe('mixed metric types', () => { it('captures multiple different metric types', () => { - const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, _experiments: { enableMetrics: true } }); + const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN }); const client = new TestClient(options); const scope = new Scope(); scope.setClient(client);