Skip to content

Commit

Permalink
feat(tracing): Promote enableLongTask to option of BrowserTracing (
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Jan 18, 2023
1 parent 53776fc commit 21ab26b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
Expand Up @@ -5,6 +5,6 @@ window.Sentry = Sentry;

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/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
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: {},
...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
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

0 comments on commit 21ab26b

Please sign in to comment.