Skip to content

Commit 21ab26b

Browse files
authored
feat(tracing): Promote enableLongTask to option of BrowserTracing (#6837)
1 parent 53776fc commit 21ab26b

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

packages/integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ window.Sentry = Sentry;
55

66
Sentry.init({
77
dsn: 'https://[email protected]/1337',
8-
integrations: [new Integrations.BrowserTracing({ _experiments: { enableLongTasks: false }, idleTimeout: 9000 })],
8+
integrations: [new Integrations.BrowserTracing({ enableLongTask: false, idleTimeout: 9000 })],
99
tracesSampleRate: 1,
1010
});

packages/tracing/src/browser/browsertracing.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
7171
*/
7272
markBackgroundTransactions: boolean;
7373

74+
/**
75+
* If true, Sentry will capture long tasks and add them to the corresponding transaction.
76+
*
77+
* Default: true
78+
*/
79+
enableLongTask: boolean;
80+
7481
/**
7582
* _metricOptions allows the user to send options to change how metrics are collected.
7683
*
@@ -87,6 +94,9 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
8794

8895
/**
8996
* _experiments allows the user to send options to define how this integration works.
97+
* Note that the `enableLongTask` options is deprecated in favor of the option at the top level, and will be removed in v8.
98+
*
99+
* TODO (v8): Remove enableLongTask
90100
*
91101
* Default: undefined
92102
*/
@@ -124,7 +134,8 @@ const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = {
124134
routingInstrumentation: instrumentRoutingWithDefaults,
125135
startTransactionOnLocationChange: true,
126136
startTransactionOnPageLoad: true,
127-
_experiments: { enableLongTask: true, enableInteractions: false },
137+
enableLongTask: true,
138+
_experiments: {},
128139
...defaultRequestInstrumentationOptions,
129140
};
130141

@@ -160,6 +171,12 @@ export class BrowserTracing implements Integration {
160171
..._options,
161172
};
162173

174+
// Special case: enableLongTask can be set in _experiments
175+
// TODO (v8): Remove this in v8
176+
if (this.options._experiments.enableLongTask !== undefined) {
177+
this.options.enableLongTask = this.options._experiments.enableLongTask;
178+
}
179+
163180
// TODO (v8): remove this block after tracingOrigins is removed
164181
// Set tracePropagationTargets to tracingOrigins if specified by the user
165182
// In case both are specified, tracePropagationTargets takes precedence
@@ -170,7 +187,7 @@ export class BrowserTracing implements Integration {
170187
}
171188

172189
startTrackingWebVitals();
173-
if (this.options._experiments.enableLongTask) {
190+
if (this.options.enableLongTask) {
174191
startTrackingLongTasks();
175192
}
176193
}

packages/tracing/test/browser/browsertracing.test.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,51 @@ describe('BrowserTracing', () => {
8383
it('is created with default settings', () => {
8484
const browserTracing = createBrowserTracing();
8585

86+
expect(browserTracing.options).toEqual({
87+
_experiments: {},
88+
enableLongTask: true,
89+
idleTimeout: DEFAULT_IDLE_TIMEOUT,
90+
finalTimeout: DEFAULT_FINAL_TIMEOUT,
91+
heartbeatInterval: DEFAULT_HEARTBEAT_INTERVAL,
92+
markBackgroundTransactions: true,
93+
routingInstrumentation: instrumentRoutingWithDefaults,
94+
startTransactionOnLocationChange: true,
95+
startTransactionOnPageLoad: true,
96+
...defaultRequestInstrumentationOptions,
97+
});
98+
});
99+
100+
it('is allows to disable enableLongTask via _experiments', () => {
101+
const browserTracing = createBrowserTracing(false, {
102+
_experiments: {
103+
enableLongTask: false,
104+
},
105+
});
106+
86107
expect(browserTracing.options).toEqual({
87108
_experiments: {
88-
enableLongTask: true,
89-
enableInteractions: false,
109+
enableLongTask: false,
90110
},
111+
enableLongTask: false,
112+
idleTimeout: DEFAULT_IDLE_TIMEOUT,
113+
finalTimeout: DEFAULT_FINAL_TIMEOUT,
114+
heartbeatInterval: DEFAULT_HEARTBEAT_INTERVAL,
115+
markBackgroundTransactions: true,
116+
routingInstrumentation: instrumentRoutingWithDefaults,
117+
startTransactionOnLocationChange: true,
118+
startTransactionOnPageLoad: true,
119+
...defaultRequestInstrumentationOptions,
120+
});
121+
});
122+
123+
it('is allows to disable enableLongTask', () => {
124+
const browserTracing = createBrowserTracing(false, {
125+
enableLongTask: false,
126+
});
127+
128+
expect(browserTracing.options).toEqual({
129+
_experiments: {},
130+
enableLongTask: false,
91131
idleTimeout: DEFAULT_IDLE_TIMEOUT,
92132
finalTimeout: DEFAULT_FINAL_TIMEOUT,
93133
heartbeatInterval: DEFAULT_HEARTBEAT_INTERVAL,

0 commit comments

Comments
 (0)