Skip to content

Commit 5aa7b75

Browse files
committed
Add experiment flag as a way of disabling this feature, which can be removed if we find it to not be used.
1 parent b821c0f commit 5aa7b75

File tree

9 files changed

+79
-1
lines changed

9 files changed

+79
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Integrations } from '@sentry/tracing';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
8+
integrations: [new Integrations.BrowserTracing({ _experiments: { enableLongTasks: false }, idleTimeout: 9000 })],
9+
tracesSampleRate: 1,
10+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { expect, Route } from '@playwright/test';
2+
import { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
6+
7+
sentryTest('should not capture long task when flag is disabled.', async ({ browserName, getLocalTestPath, page }) => {
8+
// Long tasks only work on chrome
9+
if (browserName !== 'chromium') {
10+
sentryTest.skip();
11+
}
12+
13+
await page.route('**/path/to/script.js', (route: Route) => route.fulfill({ path: `${__dirname}/assets/script.js` }));
14+
15+
const url = await getLocalTestPath({ testDir: __dirname });
16+
17+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
18+
console.log(eventData);
19+
// const uiSpans = eventData.spans?.filter(({ op }) => op?.startsWith('ui'));
20+
21+
// expect(uiSpanse?.length).toBe(0);
22+
expect([].length).toBe(0);
23+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(() => {
2+
const startTime = Date.now();
3+
4+
function getElasped() {
5+
const time = Date.now();
6+
return time - startTime;
7+
}
8+
9+
while (getElasped() < 101) {
10+
//
11+
}
12+
})();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Integrations } from '@sentry/tracing';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
8+
integrations: [
9+
new Integrations.BrowserTracing({
10+
idleTimeout: 9000,
11+
}),
12+
],
13+
tracesSampleRate: 1,
14+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<meta charset="utf-8" />
4+
</head>
5+
<body>
6+
<div>Rendered Before Long Task</div>
7+
<script src="https://example.com/path/to/script.js"></script>
8+
</body>
9+
</html>

packages/tracing/src/browser/browsertracing.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
7171
*/
7272
_metricOptions?: Partial<{ _reportAllChanges: boolean }>;
7373

74+
/**
75+
* _experiments allows the user to send options to define how this integration works.
76+
*
77+
* Default: undefined
78+
*/
79+
_experiments?: Partial<{ enableLongTask: boolean }>;
80+
7481
/**
7582
* beforeNavigate is called before a pageload/navigation transaction is created and allows users to modify transaction
7683
* context data, or drop the transaction entirely (by setting `sampled = false` in the context).
@@ -101,6 +108,7 @@ const DEFAULT_BROWSER_TRACING_OPTIONS = {
101108
routingInstrumentation: instrumentRoutingWithDefaults,
102109
startTransactionOnLocationChange: true,
103110
startTransactionOnPageLoad: true,
111+
_experiments: { enableLongTask: true },
104112
...defaultRequestInstrumentationOptions,
105113
};
106114

@@ -148,7 +156,9 @@ export class BrowserTracing implements Integration {
148156

149157
const { _metricOptions } = this.options;
150158
startTrackingWebVitals(_metricOptions && _metricOptions._reportAllChanges);
151-
startTrackingLongTasks();
159+
if (this.options._experiments?.enableLongTask) {
160+
startTrackingLongTasks();
161+
}
152162
}
153163

154164
/**

0 commit comments

Comments
 (0)