Skip to content

Commit bb0c67a

Browse files
committed
ref: Use explicit defaults
1 parent e69c3ea commit bb0c67a

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

packages/tracing/src/browser/browsertracing.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { DEFAULT_IDLE_TIMEOUT, IdleTransaction } from '../idletransaction';
77
import { SpanStatus } from '../spanstatus';
88
import { extractTraceparentData, secToMs } from '../utils';
99
import { registerBackgroundTabDetection } from './backgroundtab';
10-
import { MetricsInstrumentation } from './metrics';
10+
import { MetricsInstrumentation, MetricsInstrumentationOptions } from './metrics';
1111
import {
1212
defaultRequestInstrumentationOptions,
1313
instrumentOutgoingRequests,
@@ -67,7 +67,7 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
6767
*
6868
* Default: undefined
6969
*/
70-
_metricOptions?: BrowserMetricOptions;
70+
_metricOptions?: Partial<MetricsInstrumentationOptions>;
7171

7272
/**
7373
* beforeNavigate is called before a pageload/navigation transaction is created and allows users to modify transaction
@@ -92,13 +92,6 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
9292
): void;
9393
}
9494

95-
/**
96-
* Exports a way to add options to our metric collection. Currently experimental.
97-
*/
98-
export interface BrowserMetricOptions {
99-
_reportAllChanges?: boolean;
100-
}
101-
10295
const DEFAULT_BROWSER_TRACING_OPTIONS = {
10396
idleTimeout: DEFAULT_IDLE_TIMEOUT,
10497
markBackgroundTransactions: true,

packages/tracing/src/browser/metrics.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { browserPerformanceTimeOrigin, getGlobalObject, htmlTreeAsString, isNode
66
import { Span } from '../span';
77
import { Transaction } from '../transaction';
88
import { msToSec } from '../utils';
9-
import { BrowserMetricOptions } from './browsertracing';
109
import { getCLS, LayoutShift } from './web-vitals/getCLS';
1110
import { getFID } from './web-vitals/getFID';
1211
import { getLCP, LargestContentfulPaint } from './web-vitals/getLCP';
@@ -15,6 +14,17 @@ import { NavigatorDeviceMemory, NavigatorNetworkInformation } from './web-vitals
1514

1615
const global = getGlobalObject<Window>();
1716

17+
/**
18+
* Exports a way to add options to our metric collection. Currently experimental.
19+
*/
20+
export interface MetricsInstrumentationOptions {
21+
_reportAllChanges: boolean;
22+
}
23+
24+
const DEFAULT_METRICS_INSTR_OPTIONS: MetricsInstrumentationOptions = {
25+
_reportAllChanges: false,
26+
};
27+
1828
/** Class tracking metrics */
1929
export class MetricsInstrumentation {
2030
private _measurements: Measurements = {};
@@ -23,15 +33,15 @@ export class MetricsInstrumentation {
2333
private _lcpEntry: LargestContentfulPaint | undefined;
2434
private _clsEntry: LayoutShift | undefined;
2535

26-
public constructor(_options?: BrowserMetricOptions) {
36+
public constructor(_options: MetricsInstrumentationOptions = DEFAULT_METRICS_INSTR_OPTIONS) {
2737
if (!isNodeEnv() && global?.performance) {
2838
if (global.performance.mark) {
2939
global.performance.mark('sentry-tracing-init');
3040
}
3141

32-
this._trackCLS(_options);
33-
this._trackLCP(_options);
34-
this._trackFID(_options);
42+
this._trackCLS();
43+
this._trackLCP(_options._reportAllChanges);
44+
this._trackFID();
3545
}
3646
}
3747

@@ -231,7 +241,7 @@ export class MetricsInstrumentation {
231241
}
232242

233243
/** Starts tracking the Cumulative Layout Shift on the current page. */
234-
private _trackCLS(_options?: BrowserMetricOptions): void {
244+
private _trackCLS(): void {
235245
// See:
236246
// https://web.dev/evolving-cls/
237247
// https://web.dev/cls-web-tooling/
@@ -286,7 +296,7 @@ export class MetricsInstrumentation {
286296
}
287297

288298
/** Starts tracking the Largest Contentful Paint on the current page. */
289-
private _trackLCP(_options?: BrowserMetricOptions): void {
299+
private _trackLCP(reportAllChanges: boolean): void {
290300
getLCP(metric => {
291301
const entry = metric.entries.pop();
292302

@@ -300,11 +310,11 @@ export class MetricsInstrumentation {
300310
this._measurements['lcp'] = { value: metric.value };
301311
this._measurements['mark.lcp'] = { value: timeOrigin + startTime };
302312
this._lcpEntry = entry as LargestContentfulPaint;
303-
}, _options?._reportAllChanges);
313+
}, reportAllChanges);
304314
}
305315

306316
/** Starts tracking the First Input Delay on the current page. */
307-
private _trackFID(_options?: BrowserMetricOptions): void {
317+
private _trackFID(): void {
308318
getFID(metric => {
309319
const entry = metric.entries.pop();
310320

0 commit comments

Comments
 (0)