diff --git a/MIGRATION.md b/MIGRATION.md index 856df6f01f99..c38572523fab 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -1,5 +1,11 @@ # Upgrading from 7.x to 8.x +## Removal of the `tracingOrigins` option + +After its deprecation in v7 the `tracingOrigins` option is now removed in favor of the `tracePropagationTargets` option. +The `tracePropagationTargets` option should be set in the `Sentry.init()` options, or in your custom `Client`s option if +you create them. The `tracePropagationTargets` option can no longer be set in the `browserTracingIntegration()` options. + ## Dropping Support for React 15 Sentry will no longer officially support React 15 in version 8. This means that React 15.x will be removed diff --git a/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customBrowserTracing/init.js b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customBrowserTracing/init.js index 269593b620f1..0bf51bde157e 100644 --- a/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customBrowserTracing/init.js +++ b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customBrowserTracing/init.js @@ -4,9 +4,8 @@ Sentry.onLoad(function () { Sentry.init({ integrations: [ // Without this syntax, this will be re-written by the test framework - new window['Sentry'].BrowserTracing({ - tracePropagationTargets: ['http://localhost:1234'], - }), + window['Sentry'].browserTracingIntegration(), ], + tracePropagationTargets: ['http://localhost:1234'], }); }); diff --git a/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customBrowserTracing/test.ts b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customBrowserTracing/test.ts index f22efba3f663..64b7fb800533 100644 --- a/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customBrowserTracing/test.ts +++ b/dev-packages/browser-integration-tests/loader-suites/loader/onLoad/customBrowserTracing/test.ts @@ -25,11 +25,4 @@ sentryTest('should handle custom added BrowserTracing integration', async ({ get expect(eventData.contexts?.trace?.op).toBe('pageload'); expect(eventData.spans?.length).toBeGreaterThan(0); expect(eventData.transaction_info?.source).toEqual('url'); - - const tracePropagationTargets = await page.evaluate(() => { - const browserTracing = (window as any).Sentry.getClient().getIntegrationByName('BrowserTracing'); - return browserTracing.options.tracePropagationTargets; - }); - - expect(tracePropagationTargets).toEqual(['http://localhost:1234']); }); diff --git a/dev-packages/browser-integration-tests/suites/replay/dsc/init.js b/dev-packages/browser-integration-tests/suites/replay/dsc/init.js index c3c2f62f2c14..a686fdc78205 100644 --- a/dev-packages/browser-integration-tests/suites/replay/dsc/init.js +++ b/dev-packages/browser-integration-tests/suites/replay/dsc/init.js @@ -1,5 +1,4 @@ import * as Sentry from '@sentry/browser'; -import { Integrations } from '@sentry/tracing'; window.Sentry = Sentry; window.Replay = new Sentry.Replay({ @@ -11,7 +10,8 @@ window.Replay = new Sentry.Replay({ Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new Integrations.BrowserTracing({ tracingOrigins: [/.*/] }), window.Replay], + integrations: [Sentry.browserTracingIntegration(), window.Replay], + tracePropagationTargets: [/.*/], environment: 'production', tracesSampleRate: 1, // Needs manual start! diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargets/init.js b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargets/init.js index ad48a291386e..7cd076a052e5 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargets/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargets/init.js @@ -4,6 +4,7 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [Sentry.browserTracingIntegration({ tracePropagationTargets: ['http://example.com'] })], + integrations: [Sentry.browserTracingIntegration()], + tracePropagationTargets: ['http://example.com'], tracesSampleRate: 1, }); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargetsAndOrigins/init.js b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargetsAndOrigins/init.js deleted file mode 100644 index 572b8c69d4dc..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargetsAndOrigins/init.js +++ /dev/null @@ -1,11 +0,0 @@ -import * as Sentry from '@sentry/browser'; - -window.Sentry = Sentry; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [ - Sentry.browserTracingIntegration({ tracePropagationTargets: [], tracingOrigins: ['http://example.com'] }), - ], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargetsAndOrigins/subject.js b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargetsAndOrigins/subject.js deleted file mode 100644 index f62499b1e9c5..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargetsAndOrigins/subject.js +++ /dev/null @@ -1 +0,0 @@ -fetch('http://example.com/0').then(fetch('http://example.com/1').then(fetch('http://example.com/2'))); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargetsAndOrigins/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargetsAndOrigins/test.ts deleted file mode 100644 index a6cc58ca46ff..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTargetsAndOrigins/test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { expect } from '@playwright/test'; - -import { sentryTest } from '../../../../../utils/fixtures'; -import { shouldSkipTracingTest } from '../../../../../utils/helpers'; - -sentryTest( - '[pre-v8] should prefer custom tracePropagationTargets over tracingOrigins', - async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestPath({ testDir: __dirname }); - - const requests = ( - await Promise.all([ - page.goto(url), - Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))), - ]) - )[1]; - - expect(requests).toHaveLength(3); - - for (const request of requests) { - const requestHeaders = request.headers(); - expect(requestHeaders).not.toMatchObject({ - 'sentry-trace': expect.any(String), - baggage: expect.any(String), - }); - } - }, -); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTracingOrigins/init.js b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTracingOrigins/init.js deleted file mode 100644 index 45e5237e4c24..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTracingOrigins/init.js +++ /dev/null @@ -1,9 +0,0 @@ -import * as Sentry from '@sentry/browser'; - -window.Sentry = Sentry; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [Sentry.browserTracingIntegration({ tracingOrigins: ['http://example.com'] })], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTracingOrigins/subject.js b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTracingOrigins/subject.js deleted file mode 100644 index f62499b1e9c5..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTracingOrigins/subject.js +++ /dev/null @@ -1 +0,0 @@ -fetch('http://example.com/0').then(fetch('http://example.com/1').then(fetch('http://example.com/2'))); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTracingOrigins/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTracingOrigins/test.ts deleted file mode 100644 index 9f32b7b1ad28..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/tracePropagationTargets/customTracingOrigins/test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { expect } from '@playwright/test'; - -import { sentryTest } from '../../../../../utils/fixtures'; -import { shouldSkipTracingTest } from '../../../../../utils/helpers'; - -sentryTest( - '[pre-v8] should attach `sentry-trace` and `baggage` header to request matching tracingOrigins', - async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestPath({ testDir: __dirname }); - - const requests = ( - await Promise.all([ - page.goto(url), - Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))), - ]) - )[1]; - - expect(requests).toHaveLength(3); - - for (const request of requests) { - const requestHeaders = request.headers(); - expect(requestHeaders).toMatchObject({ - 'sentry-trace': expect.any(String), - baggage: expect.any(String), - }); - } - }, -); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/init.js index eaa53ad8b0a8..7cd076a052e5 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/init.js @@ -1,10 +1,10 @@ import * as Sentry from '@sentry/browser'; -import { Integrations } from '@sentry/tracing'; window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new Integrations.BrowserTracing({ tracePropagationTargets: ['http://example.com'] })], + integrations: [Sentry.browserTracingIntegration()], + tracePropagationTargets: ['http://example.com'], tracesSampleRate: 1, }); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargetsAndOrigins/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargetsAndOrigins/init.js deleted file mode 100644 index f98812f56e8f..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargetsAndOrigins/init.js +++ /dev/null @@ -1,12 +0,0 @@ -import * as Sentry from '@sentry/browser'; -import { Integrations } from '@sentry/tracing'; - -window.Sentry = Sentry; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [ - new Integrations.BrowserTracing({ tracePropagationTargets: [], tracingOrigins: ['http://example.com'] }), - ], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargetsAndOrigins/subject.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargetsAndOrigins/subject.js deleted file mode 100644 index f62499b1e9c5..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargetsAndOrigins/subject.js +++ /dev/null @@ -1 +0,0 @@ -fetch('http://example.com/0').then(fetch('http://example.com/1').then(fetch('http://example.com/2'))); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargetsAndOrigins/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargetsAndOrigins/test.ts deleted file mode 100644 index a6cc58ca46ff..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargetsAndOrigins/test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { expect } from '@playwright/test'; - -import { sentryTest } from '../../../../../utils/fixtures'; -import { shouldSkipTracingTest } from '../../../../../utils/helpers'; - -sentryTest( - '[pre-v8] should prefer custom tracePropagationTargets over tracingOrigins', - async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestPath({ testDir: __dirname }); - - const requests = ( - await Promise.all([ - page.goto(url), - Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))), - ]) - )[1]; - - expect(requests).toHaveLength(3); - - for (const request of requests) { - const requestHeaders = request.headers(); - expect(requestHeaders).not.toMatchObject({ - 'sentry-trace': expect.any(String), - baggage: expect.any(String), - }); - } - }, -); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTracingOrigins/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTracingOrigins/init.js deleted file mode 100644 index 505fab06b330..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTracingOrigins/init.js +++ /dev/null @@ -1,10 +0,0 @@ -import * as Sentry from '@sentry/browser'; -import { Integrations } from '@sentry/tracing'; - -window.Sentry = Sentry; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new Integrations.BrowserTracing({ tracingOrigins: ['http://example.com'] })], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTracingOrigins/subject.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTracingOrigins/subject.js deleted file mode 100644 index f62499b1e9c5..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTracingOrigins/subject.js +++ /dev/null @@ -1 +0,0 @@ -fetch('http://example.com/0').then(fetch('http://example.com/1').then(fetch('http://example.com/2'))); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTracingOrigins/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTracingOrigins/test.ts deleted file mode 100644 index 9f32b7b1ad28..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTracingOrigins/test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { expect } from '@playwright/test'; - -import { sentryTest } from '../../../../../utils/fixtures'; -import { shouldSkipTracingTest } from '../../../../../utils/helpers'; - -sentryTest( - '[pre-v8] should attach `sentry-trace` and `baggage` header to request matching tracingOrigins', - async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestPath({ testDir: __dirname }); - - const requests = ( - await Promise.all([ - page.goto(url), - Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))), - ]) - )[1]; - - expect(requests).toHaveLength(3); - - for (const request of requests) { - const requestHeaders = request.headers(); - expect(requestHeaders).toMatchObject({ - 'sentry-trace': expect.any(String), - baggage: expect.any(String), - }); - } - }, -); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/init.js index ce4e0c4ad7f7..83076460599f 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/init.js @@ -1,10 +1,9 @@ import * as Sentry from '@sentry/browser'; -import { Integrations } from '@sentry/tracing'; window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new Integrations.BrowserTracing()], + integrations: [Sentry.browserTracingIntegration()], tracesSampleRate: 1, }); diff --git a/dev-packages/browser-integration-tests/suites/tracing/envelope-header/init.js b/dev-packages/browser-integration-tests/suites/tracing/envelope-header/init.js index 1ecbb8351cb9..51f27f9122df 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/envelope-header/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/envelope-header/init.js @@ -1,11 +1,11 @@ import * as Sentry from '@sentry/browser'; -import { Integrations } from '@sentry/tracing'; window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new Integrations.BrowserTracing({ tracingOrigins: [/.*/] })], + integrations: [Sentry.browserTracingIntegration()], + tracePropagationTargets: [/.*/], environment: 'production', tracesSampleRate: 1, debug: true, diff --git a/dev-packages/browser-integration-tests/suites/tracing/request/fetch-with-no-active-span/init.js b/dev-packages/browser-integration-tests/suites/tracing/request/fetch-with-no-active-span/init.js index 92152554ea57..a8d8c03d1f25 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/request/fetch-with-no-active-span/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/request/fetch-with-no-active-span/init.js @@ -5,6 +5,7 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', // disable pageload transaction - integrations: [Sentry.BrowserTracing({ tracingOrigins: ['http://example.com'], startTransactionOnPageLoad: false })], + integrations: [Sentry.browserTracingIntegration({ instrumentPageLoad: false })], + tracePropagationTargets: ['http://example.com'], tracesSampleRate: 1, }); diff --git a/dev-packages/browser-integration-tests/suites/tracing/request/fetch-with-request/init.js b/dev-packages/browser-integration-tests/suites/tracing/request/fetch-with-request/init.js index 505fab06b330..7cd076a052e5 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/request/fetch-with-request/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/request/fetch-with-request/init.js @@ -1,10 +1,10 @@ import * as Sentry from '@sentry/browser'; -import { Integrations } from '@sentry/tracing'; window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new Integrations.BrowserTracing({ tracingOrigins: ['http://example.com'] })], + integrations: [Sentry.browserTracingIntegration()], + tracePropagationTargets: ['http://example.com'], tracesSampleRate: 1, }); diff --git a/dev-packages/browser-integration-tests/suites/tracing/request/init.js b/dev-packages/browser-integration-tests/suites/tracing/request/init.js index 505fab06b330..7cd076a052e5 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/request/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/request/init.js @@ -1,10 +1,10 @@ import * as Sentry from '@sentry/browser'; -import { Integrations } from '@sentry/tracing'; window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new Integrations.BrowserTracing({ tracingOrigins: ['http://example.com'] })], + integrations: [Sentry.browserTracingIntegration()], + tracePropagationTargets: ['http://example.com'], tracesSampleRate: 1, }); diff --git a/dev-packages/browser-integration-tests/suites/tracing/request/xhr-with-no-active-span/init.js b/dev-packages/browser-integration-tests/suites/tracing/request/xhr-with-no-active-span/init.js index 92152554ea57..a8d8c03d1f25 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/request/xhr-with-no-active-span/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/request/xhr-with-no-active-span/init.js @@ -5,6 +5,7 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', // disable pageload transaction - integrations: [Sentry.BrowserTracing({ tracingOrigins: ['http://example.com'], startTransactionOnPageLoad: false })], + integrations: [Sentry.browserTracingIntegration({ instrumentPageLoad: false })], + tracePropagationTargets: ['http://example.com'], tracesSampleRate: 1, }); diff --git a/packages/ember/tests/dummy/config/environment.js b/packages/ember/tests/dummy/config/environment.js index 70c45d17ff0c..144a6aebe1fa 100644 --- a/packages/ember/tests/dummy/config/environment.js +++ b/packages/ember/tests/dummy/config/environment.js @@ -24,8 +24,8 @@ module.exports = function (environment) { tracesSampleRate: 1, // Include fake dsn so that instrumentation is enabled when running from cli dsn: process.env.SENTRY_DSN || 'https://0@0.ingest.sentry.io/0', + tracePropagationTargets: ['localhost', 'doesntexist.example'], browserTracingOptions: { - tracingOrigins: ['localhost', 'doesntexist.example'], _experiments: { // This lead to some flaky tests, as that is sometimes logged enableLongTask: false, diff --git a/packages/sveltekit/test/client/browserTracingIntegration.test.ts b/packages/sveltekit/test/client/browserTracingIntegration.test.ts index 0fcd8f3f1e46..415637c05560 100644 --- a/packages/sveltekit/test/client/browserTracingIntegration.test.ts +++ b/packages/sveltekit/test/client/browserTracingIntegration.test.ts @@ -58,7 +58,7 @@ describe('browserTracingIntegration', () => { }; }); - const fakeClient = { getOptions: () => undefined, on: () => {} }; + const fakeClient = { getOptions: () => ({}), on: () => {} }; const mockedRoutingSpan = { end: () => {}, diff --git a/packages/tracing-internal/src/browser/browserTracingIntegration.ts b/packages/tracing-internal/src/browser/browserTracingIntegration.ts index a521933c420e..c90b199ac8ad 100644 --- a/packages/tracing-internal/src/browser/browserTracingIntegration.ts +++ b/packages/tracing-internal/src/browser/browserTracingIntegration.ts @@ -34,14 +34,13 @@ import { startTrackingLongTasks, startTrackingWebVitals, } from './metrics'; -import type { RequestInstrumentationOptions } from './request'; import { defaultRequestInstrumentationOptions, instrumentOutgoingRequests } from './request'; import { WINDOW } from './types'; export const BROWSER_TRACING_INTEGRATION_ID = 'BrowserTracing'; /** Options for Browser Tracing integration */ -export interface BrowserTracingOptions extends RequestInstrumentationOptions { +export interface BrowserTracingOptions { /** * The time to wait in ms until the transaction will be finished during an idle state. An idle state is defined * by a moment where there are no in-progress spans. @@ -102,6 +101,27 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions { */ enableLongTask: boolean; + /** + * Flag to disable patching all together for fetch requests. + * + * Default: true + */ + traceFetch: boolean; + + /** + * Flag to disable patching all together for xhr requests. + * + * Default: true + */ + traceXHR: boolean; + + /** + * If true, Sentry will capture http timings and add them to the corresponding http spans. + * + * Default: true + */ + enableHTTPTimings: boolean; + /** * _metricOptions allows the user to send options to change how metrics are collected. * @@ -118,9 +138,6 @@ 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 */ @@ -133,6 +150,14 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions { * It receives the options passed to `startSpan`, and expects to return an updated options object. */ beforeStartSpan?: (options: StartSpanOptions) => StartSpanOptions; + + /** + * This function will be called before creating a span for a request with the given url. + * Return false if you don't want a span for the given url. + * + * Default: (url: string) => true + */ + shouldCreateSpanForRequest?(this: void, url: string): boolean; } const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = { @@ -155,24 +180,8 @@ const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = { * We explicitly export the proper type here, as this has to be extended in some cases. */ export const browserTracingIntegration = ((_options: Partial = {}) => { - const _hasSetTracePropagationTargets = DEBUG_BUILD - ? !!( - // eslint-disable-next-line deprecation/deprecation - (_options.tracePropagationTargets || _options.tracingOrigins) - ) - : false; - addTracingExtensions(); - // 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 - // eslint-disable-next-line deprecation/deprecation - if (!_options.tracePropagationTargets && _options.tracingOrigins) { - // eslint-disable-next-line deprecation/deprecation - _options.tracePropagationTargets = _options.tracingOrigins; - } - const options = { ...DEFAULT_BROWSER_TRACING_OPTIONS, ..._options, @@ -282,30 +291,9 @@ export const browserTracingIntegration = ((_options: Partial {}, afterAllSetup(client) { - const clientOptions = client.getOptions(); - const { markBackgroundSpan, traceFetch, traceXHR, shouldCreateSpanForRequest, enableHTTPTimings, _experiments } = options; - const clientOptionsTracePropagationTargets = clientOptions && clientOptions.tracePropagationTargets; - // There are three ways to configure tracePropagationTargets: - // 1. via top level client option `tracePropagationTargets` - // 2. via BrowserTracing option `tracePropagationTargets` - // 3. via BrowserTracing option `tracingOrigins` (deprecated) - // - // To avoid confusion, favour top level client option `tracePropagationTargets`, and fallback to - // BrowserTracing option `tracePropagationTargets` and then `tracingOrigins` (deprecated). - // This is done as it minimizes bundle size (we don't have to have undefined checks). - // - // If both 1 and either one of 2 or 3 are set (from above), we log out a warning. - // eslint-disable-next-line deprecation/deprecation - const tracePropagationTargets = clientOptionsTracePropagationTargets || options.tracePropagationTargets; - if (DEBUG_BUILD && _hasSetTracePropagationTargets && clientOptionsTracePropagationTargets) { - logger.warn( - '[Tracing] The `tracePropagationTargets` option was set in the BrowserTracing integration and top level `Sentry.init`. The top level `Sentry.init` value is being used.', - ); - } - let activeSpan: Span | undefined; let startingUrl: string | undefined = WINDOW.location.href; @@ -384,7 +372,7 @@ export const browserTracingIntegration = ((_options: Partial true + */ + shouldCreateSpanForRequest?(this: void, url: string): boolean; } const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = { @@ -180,22 +208,11 @@ export class BrowserTracing implements Integration { private _collectWebVitals: () => void; - private _hasSetTracePropagationTargets: boolean; - public constructor(_options?: Partial) { this.name = BROWSER_TRACING_INTEGRATION_ID; - this._hasSetTracePropagationTargets = false; addTracingExtensions(); - if (DEBUG_BUILD) { - this._hasSetTracePropagationTargets = !!( - _options && - // eslint-disable-next-line deprecation/deprecation - (_options.tracePropagationTargets || _options.tracingOrigins) - ); - } - this.options = { ...DEFAULT_BROWSER_TRACING_OPTIONS, ..._options, @@ -207,15 +224,6 @@ export class BrowserTracing implements Integration { 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 - // eslint-disable-next-line deprecation/deprecation - if (_options && !_options.tracePropagationTargets && _options.tracingOrigins) { - // eslint-disable-next-line deprecation/deprecation - this.options.tracePropagationTargets = _options.tracingOrigins; - } - this._collectWebVitals = startTrackingWebVitals(); if (this.options.enableLongTask) { startTrackingLongTasks(); @@ -247,25 +255,6 @@ export class BrowserTracing implements Integration { _experiments, } = this.options; - const clientOptionsTracePropagationTargets = clientOptions && clientOptions.tracePropagationTargets; - // There are three ways to configure tracePropagationTargets: - // 1. via top level client option `tracePropagationTargets` - // 2. via BrowserTracing option `tracePropagationTargets` - // 3. via BrowserTracing option `tracingOrigins` (deprecated) - // - // To avoid confusion, favour top level client option `tracePropagationTargets`, and fallback to - // BrowserTracing option `tracePropagationTargets` and then `tracingOrigins` (deprecated). - // This is done as it minimizes bundle size (we don't have to have undefined checks). - // - // If both 1 and either one of 2 or 3 are set (from above), we log out a warning. - // eslint-disable-next-line deprecation/deprecation - const tracePropagationTargets = clientOptionsTracePropagationTargets || this.options.tracePropagationTargets; - if (DEBUG_BUILD && this._hasSetTracePropagationTargets && clientOptionsTracePropagationTargets) { - logger.warn( - '[Tracing] The `tracePropagationTargets` option was set in the BrowserTracing integration and top level `Sentry.init`. The top level `Sentry.init` value is being used.', - ); - } - instrumentRouting( (context: TransactionContext) => { const transaction = this._createRouteTransaction(context); @@ -290,7 +279,7 @@ export class BrowserTracing implements Integration { instrumentOutgoingRequests({ traceFetch, traceXHR, - tracePropagationTargets, + tracePropagationTargets: clientOptions && clientOptions.tracePropagationTargets, shouldCreateSpanForRequest, enableHTTPTimings, }); diff --git a/packages/tracing-internal/src/browser/request.ts b/packages/tracing-internal/src/browser/request.ts index 57307917cbef..e722f4be6a85 100644 --- a/packages/tracing-internal/src/browser/request.ts +++ b/packages/tracing-internal/src/browser/request.ts @@ -32,20 +32,10 @@ export const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\/(?!\/)/]; /** Options for Request Instrumentation */ export interface RequestInstrumentationOptions { /** - * @deprecated Will be removed in v8. - * Use `shouldCreateSpanForRequest` to control span creation and `tracePropagationTargets` to control - * trace header attachment. - */ - tracingOrigins: Array; - - /** - * List of strings and/or regexes used to determine which outgoing requests will have `sentry-trace` and `baggage` + * List of strings and/or Regular Expressions used to determine which outgoing requests will have `sentry-trace` and `baggage` * headers attached. * - * @deprecated Use the top-level `tracePropagationTargets` option in `Sentry.init` instead. - * This option will be removed in v8. - * - * Default: ['localhost', /^\//] @see {DEFAULT_TRACE_PROPAGATION_TARGETS} + * Default: ['localhost', /^\//] */ tracePropagationTargets: Array; @@ -83,23 +73,12 @@ export const defaultRequestInstrumentationOptions: RequestInstrumentationOptions traceFetch: true, traceXHR: true, enableHTTPTimings: true, - // TODO (v8): Remove this property - tracingOrigins: DEFAULT_TRACE_PROPAGATION_TARGETS, tracePropagationTargets: DEFAULT_TRACE_PROPAGATION_TARGETS, }; /** Registers span creators for xhr and fetch requests */ export function instrumentOutgoingRequests(_options?: Partial): void { - const { - traceFetch, - traceXHR, - // eslint-disable-next-line deprecation/deprecation - tracePropagationTargets, - // eslint-disable-next-line deprecation/deprecation - tracingOrigins, - shouldCreateSpanForRequest, - enableHTTPTimings, - } = { + const { traceFetch, traceXHR, shouldCreateSpanForRequest, enableHTTPTimings, tracePropagationTargets } = { traceFetch: defaultRequestInstrumentationOptions.traceFetch, traceXHR: defaultRequestInstrumentationOptions.traceXHR, ..._options, @@ -108,11 +87,7 @@ export function instrumentOutgoingRequests(_options?: Partial true; - // TODO(v8) Remove tracingOrigins here - // The only reason we're passing it in here is because this instrumentOutgoingRequests function is publicly exported - // and we don't want to break the API. We can remove it in v8. - const shouldAttachHeadersWithTargets = (url: string): boolean => - shouldAttachHeaders(url, tracePropagationTargets || tracingOrigins); + const shouldAttachHeadersWithTargets = (url: string): boolean => shouldAttachHeaders(url, tracePropagationTargets); const spans: Record = {}; diff --git a/packages/tracing-internal/test/browser/browsertracing.test.ts b/packages/tracing-internal/test/browser/browsertracing.test.ts index 8144f4b0621b..9d4105dc415d 100644 --- a/packages/tracing-internal/test/browser/browsertracing.test.ts +++ b/packages/tracing-internal/test/browser/browsertracing.test.ts @@ -187,129 +187,6 @@ describe('BrowserTracing', () => { expect(spanToJSON(transaction).timestamp).toBe(timestamp); }); - // TODO (v8): remove these tests - describe('tracingOrigins', () => { - it('sets tracing origins if provided and does not warn', () => { - const sampleTracingOrigins = ['something']; - const inst = createBrowserTracing(true, { - routingInstrumentation: customInstrumentRouting, - tracingOrigins: sampleTracingOrigins, - }); - - // eslint-disable-next-line deprecation/deprecation - expect(inst.options.tracingOrigins).toEqual(sampleTracingOrigins); - }); - - it('sets tracing origins to an empty array and does not warn', () => { - const sampleTracingOrigins: string[] = []; - const inst = createBrowserTracing(true, { - routingInstrumentation: customInstrumentRouting, - tracingOrigins: sampleTracingOrigins, - }); - - // eslint-disable-next-line deprecation/deprecation - expect(inst.options.tracingOrigins).toEqual(sampleTracingOrigins); - }); - }); - - describe('tracePropagationTargets', () => { - it('sets tracePropagationTargets if provided', () => { - const sampleTracePropagationTargets = ['something']; - const inst = createBrowserTracing(true, { - routingInstrumentation: customInstrumentRouting, - tracePropagationTargets: sampleTracePropagationTargets, - }); - - expect(inst.options.tracePropagationTargets).toEqual(sampleTracePropagationTargets); - }); - - it('sets tracePropagationTargets to an empty array and does not warn', () => { - const sampleTracePropagationTargets: string[] = []; - const inst = createBrowserTracing(true, { - routingInstrumentation: customInstrumentRouting, - tracePropagationTargets: sampleTracePropagationTargets, - }); - - expect(inst.options.tracePropagationTargets).toEqual(sampleTracePropagationTargets); - }); - - it('correctly passes tracePropagationTargets to `instrumentOutgoingRequests` in `setupOnce`', () => { - jest.clearAllMocks(); - const sampleTracePropagationTargets = ['something']; - createBrowserTracing(true, { - routingInstrumentation: customInstrumentRouting, - tracePropagationTargets: sampleTracePropagationTargets, - }); - - expect(instrumentOutgoingRequestsMock).toHaveBeenCalledWith({ - traceFetch: true, - traceXHR: true, - tracePropagationTargets: ['something'], - enableHTTPTimings: true, - }); - }); - - it('uses `tracePropagationTargets` set by client over integration set targets', () => { - jest.clearAllMocks(); - hub.getClient()!.getOptions().tracePropagationTargets = ['something-else']; - const sampleTracePropagationTargets = ['something']; - createBrowserTracing(true, { - routingInstrumentation: customInstrumentRouting, - tracePropagationTargets: sampleTracePropagationTargets, - }); - - expect(instrumentOutgoingRequestsMock).toHaveBeenCalledWith({ - enableHTTPTimings: true, - traceFetch: true, - traceXHR: true, - tracePropagationTargets: ['something-else'], - }); - }); - - it.each([ - [true, 'tracePropagationTargets', 'defined', { tracePropagationTargets: ['something'] }], - [false, 'tracePropagationTargets', 'undefined', { tracePropagationTargets: undefined }], - [true, 'tracingOrigins', 'defined', { tracingOrigins: ['something'] }], - [false, 'tracingOrigins', 'undefined', { tracingOrigins: undefined }], - [ - true, - 'tracePropagationTargets and tracingOrigins', - 'defined', - { tracePropagationTargets: ['something'], tracingOrigins: ['something-else'] }, - ], - [ - false, - 'tracePropagationTargets and tracingOrigins', - 'undefined', - { tracePropagationTargets: undefined, tracingOrigins: undefined }, - ], - [ - true, - 'tracePropagationTargets and tracingOrigins', - 'defined and undefined', - { tracePropagationTargets: ['something'], tracingOrigins: undefined }, - ], - [ - true, - 'tracePropagationTargets and tracingOrigins', - 'undefined and defined', - { tracePropagationTargets: undefined, tracingOrigins: ['something'] }, - ], - ])( - 'sets `_hasSetTracePropagationTargets` to %s if %s is %s', - (hasSet: boolean, _: string, __: string, options: Partial) => { - jest.clearAllMocks(); - const inst = createBrowserTracing(true, { - routingInstrumentation: customInstrumentRouting, - ...options, - }); - - // @ts-expect-error accessing private property - expect(inst._hasSetTracePropagationTargets).toBe(hasSet); - }, - ); - }); - describe('beforeNavigate', () => { it('is called on transaction creation', () => { const mockBeforeNavigation = jest.fn().mockReturnValue({ name: 'here/is/my/path' });