Skip to content

feat(tracing): Promote enableLongTask to option of BrowserTracing #6837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ window.Sentry = Sentry;

Sentry.init({
dsn: 'https://[email protected]/1337',
integrations: [new Integrations.BrowserTracing({ _experiments: { enableLongTasks: false }, idleTimeout: 9000 })],
integrations: [new Integrations.BrowserTracing({ enableLongTask: false, idleTimeout: 9000 })],
tracesSampleRate: 1,
});
21 changes: 19 additions & 2 deletions packages/tracing/src/browser/browsertracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
*/
markBackgroundTransactions: boolean;

/**
* If true, Sentry will capture long tasks and add them to the corresponding transaction.
*
* Default: true
*/
enableLongTask: boolean;

/**
* _metricOptions allows the user to send options to change how metrics are collected.
*
Expand All @@ -87,6 +94,9 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {

/**
* _experiments allows the user to send options to define how this integration works.
* Note that the `enableLongTask` options is deprecated in favor of the option at the top level, and will be removed in v8.
*
* TODO (v8): Remove enableLongTask
*
* Default: undefined
*/
Expand Down Expand Up @@ -124,7 +134,8 @@ const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = {
routingInstrumentation: instrumentRoutingWithDefaults,
startTransactionOnLocationChange: true,
startTransactionOnPageLoad: true,
_experiments: { enableLongTask: true, enableInteractions: false },
enableLongTask: true,
_experiments: {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: Did we want to remove enableInteractions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is false by default, so should be the same as not having it at all, I figured?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good point, save some bytes!

...defaultRequestInstrumentationOptions,
};

Expand Down Expand Up @@ -160,6 +171,12 @@ export class BrowserTracing implements Integration {
..._options,
};

// Special case: enableLongTask can be set in _experiments
// TODO (v8): Remove this in v8
if (this.options._experiments.enableLongTask !== undefined) {
this.options.enableLongTask = this.options._experiments.enableLongTask;
}

// TODO (v8): remove this block after tracingOrigins is removed
// Set tracePropagationTargets to tracingOrigins if specified by the user
// In case both are specified, tracePropagationTargets takes precedence
Expand All @@ -170,7 +187,7 @@ export class BrowserTracing implements Integration {
}

startTrackingWebVitals();
if (this.options._experiments.enableLongTask) {
if (this.options.enableLongTask) {
startTrackingLongTasks();
}
}
Expand Down
44 changes: 42 additions & 2 deletions packages/tracing/test/browser/browsertracing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,51 @@ describe('BrowserTracing', () => {
it('is created with default settings', () => {
const browserTracing = createBrowserTracing();

expect(browserTracing.options).toEqual({
_experiments: {},
enableLongTask: true,
idleTimeout: DEFAULT_IDLE_TIMEOUT,
finalTimeout: DEFAULT_FINAL_TIMEOUT,
heartbeatInterval: DEFAULT_HEARTBEAT_INTERVAL,
markBackgroundTransactions: true,
routingInstrumentation: instrumentRoutingWithDefaults,
startTransactionOnLocationChange: true,
startTransactionOnPageLoad: true,
...defaultRequestInstrumentationOptions,
});
});

it('is allows to disable enableLongTask via _experiments', () => {
const browserTracing = createBrowserTracing(false, {
_experiments: {
enableLongTask: false,
},
});

expect(browserTracing.options).toEqual({
_experiments: {
enableLongTask: true,
enableInteractions: false,
enableLongTask: false,
},
enableLongTask: false,
idleTimeout: DEFAULT_IDLE_TIMEOUT,
finalTimeout: DEFAULT_FINAL_TIMEOUT,
heartbeatInterval: DEFAULT_HEARTBEAT_INTERVAL,
markBackgroundTransactions: true,
routingInstrumentation: instrumentRoutingWithDefaults,
startTransactionOnLocationChange: true,
startTransactionOnPageLoad: true,
...defaultRequestInstrumentationOptions,
});
});

it('is allows to disable enableLongTask', () => {
const browserTracing = createBrowserTracing(false, {
enableLongTask: false,
});

expect(browserTracing.options).toEqual({
_experiments: {},
enableLongTask: false,
idleTimeout: DEFAULT_IDLE_TIMEOUT,
finalTimeout: DEFAULT_FINAL_TIMEOUT,
heartbeatInterval: DEFAULT_HEARTBEAT_INTERVAL,
Expand Down