From 02d4501d887889f890f80ec74a7391d207483818 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 18 Jan 2023 11:43:47 +0100 Subject: [PATCH] feat(tracing): Promote `enableLongTask` to option of `BrowserTracing` --- .../long-tasks-disabled/init.js | 2 +- .../tracing/src/browser/browsertracing.ts | 21 ++++++++- .../test/browser/browsertracing.test.ts | 44 ++++++++++++++++++- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/packages/integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js b/packages/integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js index acf98f9a3821..c1d5e8a8a7ae 100644 --- a/packages/integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js +++ b/packages/integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js @@ -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, }); diff --git a/packages/tracing/src/browser/browsertracing.ts b/packages/tracing/src/browser/browsertracing.ts index 8502e5d1b13f..9030e8a11400 100644 --- a/packages/tracing/src/browser/browsertracing.ts +++ b/packages/tracing/src/browser/browsertracing.ts @@ -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. * @@ -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 */ @@ -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, }; @@ -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 @@ -170,7 +187,7 @@ export class BrowserTracing implements Integration { } startTrackingWebVitals(); - if (this.options._experiments.enableLongTask) { + if (this.options.enableLongTask) { startTrackingLongTasks(); } } diff --git a/packages/tracing/test/browser/browsertracing.test.ts b/packages/tracing/test/browser/browsertracing.test.ts index a00025811874..1bb0c631e6ec 100644 --- a/packages/tracing/test/browser/browsertracing.test.ts +++ b/packages/tracing/test/browser/browsertracing.test.ts @@ -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,