Skip to content

Commit 892e0ec

Browse files
committed
add enableMeasurements option to browser tracing options
1 parent 0f06193 commit 892e0ec

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/tracing/src/browser/browsertracing.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ export const DEFAULT_MAX_TRANSACTION_DURATION_SECONDS = 600;
2020

2121
/** Options for Browser Tracing integration */
2222
export interface BrowserTracingOptions extends RequestInstrumentationOptions {
23+
/**
24+
* Flag to attach measurements to transactions.
25+
*
26+
* Default: false
27+
* @hidden
28+
*/
29+
enableMeasurements: boolean;
30+
2331
/**
2432
* The time to wait in ms until the transaction will be finished. The transaction will use the end timestamp of
2533
* the last finished span as the endtime for the transaction.
@@ -95,6 +103,7 @@ export class BrowserTracing implements Integration {
95103

96104
/** Browser Tracing integration options */
97105
public options: BrowserTracingOptions = {
106+
enableMeasurements: false,
98107
beforeNavigate: defaultBeforeNavigate,
99108
idleTimeout: DEFAULT_IDLE_TIMEOUT,
100109
markBackgroundTransactions: true,
@@ -135,6 +144,8 @@ export class BrowserTracing implements Integration {
135144
..._options,
136145
tracingOrigins,
137146
};
147+
148+
this._metrics.enableMeasurements(this.options.enableMeasurements);
138149
}
139150

140151
/**

packages/tracing/src/browser/metrics.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const global = getGlobalObject<Window>();
1919
export class MetricsInstrumentation {
2020
private _lcp: Record<string, any> = {};
2121
private _measurements: Measurements = {};
22+
private _enableMeasurements: boolean = false;
2223

2324
private _performanceCursor: number = 0;
2425

@@ -33,6 +34,15 @@ export class MetricsInstrumentation {
3334
}
3435
}
3536

37+
/**
38+
* Enable or disable attachment of measurements to transactions.
39+
* @hidden
40+
*/
41+
public enableMeasurements(enable: boolean): void {
42+
this._enableMeasurements = enable;
43+
}
44+
45+
3646
/** Add performance related spans to a transaction */
3747
public addPerformanceEntries(transaction: Transaction): void {
3848
if (!global || !global.performance || !global.performance.getEntries) {
@@ -136,7 +146,7 @@ export class MetricsInstrumentation {
136146
this._performanceCursor = Math.max(performance.getEntries().length - 1, 0);
137147

138148
// Measurements are only available for pageload transactions
139-
if (transaction.op === 'pageload') {
149+
if (transaction.op === 'pageload' && this._enableMeasurements) {
140150
transaction.setMeasurements(this._measurements);
141151
}
142152
}

0 commit comments

Comments
 (0)