Skip to content

Commit 037e938

Browse files
nicohrubecclaude
andauthored
feat(core)!: Remove enableMetrics option (#23321)
Removes the `enableMetrics` option for v11. Metrics are now captured whenever a metric API (`Sentry.metrics.*`) is used, with no way to disable them. `beforeSendMetric` is unaffected and stays available. Fixes #23309 Similar to [https://github.com/getsentry/sentry-javascript/pull/23319](<https://github.com/getsentry/sentry-javascript/pull/23319>) --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent beb0f34 commit 037e938

6 files changed

Lines changed: 9 additions & 75 deletions

File tree

docs/migration/v11-end-state.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ Affected SDKs: `@sentry/cloudflare`.
671671
- The `createSpanEnvelope` function and the `SpanEnvelope` / `SpanItem` types were removed. They existed only to send standalone (v1) spans as their own segment envelope, which the SDK no longer does. Standalone spans are gone; spans are sent either on their transaction or, with span streaming, as streamed spans (`StreamedSpanEnvelope`).
672672
- The `disableInstrumentationWarnings` option and the `MissingInstrumentationContext` type were removed. Now that instrumentation is channel-based, the SDK can no longer detect the "you imported a framework before `Sentry.init()`" case, so the warning it gated and the context it attached no longer exist.
673673
- The deprecated `sendDefaultPii` option was removed. Use [`dataCollection`](#senddefaultpii-is-replaced-by-datacollection) instead.
674-
- The `_experiments.enableMetrics` and `_experiments.beforeSendMetric` options were removed, use the top-level `enableMetrics` and `beforeSendMetric` options instead.
674+
- The `_experiments.enableMetrics` and top-level `enableMetrics` options were removed. Metrics are now captured whenever you use a metric API (`Sentry.metrics.*`), so you can simply omit the option. The `_experiments.beforeSendMetric` callback moved to the top-level `beforeSendMetric` option.
675675
676676
```js
677677
// before
@@ -686,7 +686,6 @@ Sentry.init({
686686

687687
// after
688688
Sentry.init({
689-
enableMetrics: true,
690689
beforeSendMetric: metric => {
691690
return metric;
692691
},

packages/core/src/client.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,14 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
291291
// Setup log flushing with weight and timeout tracking
292292
setupWeightBasedFlushing(this, 'afterCaptureLog', 'flushLogs', estimateLogSizeInBytes, _INTERNAL_flushLogsBuffer);
293293

294-
const enableMetrics = this._options.enableMetrics ?? true;
295-
296294
// Setup metric flushing with weight and timeout tracking
297-
if (enableMetrics) {
298-
setupWeightBasedFlushing(
299-
this,
300-
'afterCaptureMetric',
301-
'flushMetrics',
302-
estimateMetricSizeInBytes,
303-
_INTERNAL_flushMetricsBuffer,
304-
);
305-
}
295+
setupWeightBasedFlushing(
296+
this,
297+
'afterCaptureMetric',
298+
'flushMetrics',
299+
estimateMetricSizeInBytes,
300+
_INTERNAL_flushMetricsBuffer,
301+
);
306302
}
307303

308304
/**

packages/core/src/metrics/internal.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,7 @@ export function _INTERNAL_captureMetric(beforeMetric: Metric, options?: Internal
173173
return;
174174
}
175175

176-
const { enableMetrics, beforeSendMetric } = client.getOptions();
177-
const metricsEnabled = enableMetrics ?? true;
178-
179-
if (!metricsEnabled) {
180-
DEBUG_BUILD && debug.warn('metrics option not enabled, metric will not be captured.');
181-
return;
182-
}
176+
const { beforeSendMetric } = client.getOptions();
183177

184178
// Enrich metric with contextual attributes
185179
const { user, attributes: scopeAttributes } = getCombinedScopeData(getIsolationScope(), currentScope);

packages/core/src/types/options.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,6 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
523523
*/
524524
beforeSendLog?: (log: Log) => Log | null;
525525

526-
/**
527-
* If metrics support should be enabled.
528-
*
529-
* @default true
530-
*/
531-
enableMetrics?: boolean;
532-
533526
/**
534527
* Interval in ms for the idle flush timer used by logs and metrics.
535528
* Set to 0 to disable timer-based flushing entirely — useful for

packages/core/test/lib/metrics/internal.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,6 @@ describe('_INTERNAL_captureMetric', () => {
4141
);
4242
});
4343

44-
it('does not capture metrics when enableMetrics is not enabled', () => {
45-
const logWarnSpy = vi.spyOn(loggerModule.debug, 'warn').mockImplementation(() => undefined);
46-
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableMetrics: false });
47-
const client = new TestClient(options);
48-
const scope = new Scope();
49-
scope.setClient(client);
50-
51-
_INTERNAL_captureMetric({ type: 'counter', name: 'test.metric', value: 1 }, { scope });
52-
53-
expect(logWarnSpy).toHaveBeenCalledWith('metrics option not enabled, metric will not be captured.');
54-
expect(_INTERNAL_getMetricBuffer(client)).toBeUndefined();
55-
56-
logWarnSpy.mockRestore();
57-
});
58-
5944
it('includes trace context when available', () => {
6045
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
6146
const client = new TestClient(options);

packages/core/test/lib/metrics/public-api.test.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,6 @@ describe('Metrics Public API', () => {
112112
}),
113113
);
114114
});
115-
116-
it('does not capture counter when enableMetrics is not enabled', () => {
117-
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableMetrics: false });
118-
const client = new TestClient(options);
119-
const scope = new Scope();
120-
scope.setClient(client);
121-
122-
count('api.requests', 1, { scope });
123-
124-
expect(_INTERNAL_getMetricBuffer(client)).toBeUndefined();
125-
});
126115
});
127116

128117
describe('gauge', () => {
@@ -206,17 +195,6 @@ describe('Metrics Public API', () => {
206195
}),
207196
);
208197
});
209-
210-
it('does not capture gauge when enableMetrics is not enabled', () => {
211-
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableMetrics: false });
212-
const client = new TestClient(options);
213-
const scope = new Scope();
214-
scope.setClient(client);
215-
216-
gauge('memory.usage', 1024, { scope });
217-
218-
expect(_INTERNAL_getMetricBuffer(client)).toBeUndefined();
219-
});
220198
});
221199

222200
describe('distribution', () => {
@@ -300,17 +278,6 @@ describe('Metrics Public API', () => {
300278
}),
301279
);
302280
});
303-
304-
it('does not capture distribution when enableMetrics is not enabled', () => {
305-
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, enableMetrics: false });
306-
const client = new TestClient(options);
307-
const scope = new Scope();
308-
scope.setClient(client);
309-
310-
distribution('task.duration', 500, { scope });
311-
312-
expect(_INTERNAL_getMetricBuffer(client)).toBeUndefined();
313-
});
314281
});
315282

316283
describe('mixed metric types', () => {

0 commit comments

Comments
 (0)