From 76b00957708e445b9c8b8526c4cca93c4967b950 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 14 Feb 2024 12:06:38 +0000 Subject: [PATCH 01/44] remove test usages --- .size-limit.js | 14 +++++++------- .../browserTracingIntegrationHashShim/init.js | 2 +- .../suites/tracing/browserTracingShim/init.js | 2 +- .../browsertracing/backgroundtab-custom/init.js | 3 +-- .../tracing/browsertracing/http-timings/init.js | 3 +-- .../tracing/browsertracing/interactions/init.js | 3 +-- .../browsertracing/long-tasks-disabled/init.js | 3 +-- .../browsertracing/long-tasks-enabled/init.js | 3 +-- .../suites/tracing/browsertracing/meta/init.js | 3 +-- .../suites/tracing/browsertracing/pageload/init.js | 3 +-- .../tracing/browsertracing/pageloadDelayed/init.js | 3 +-- .../pageloadWithHeartbeatTimeout/init.js | 3 +-- .../defaultTargetsNoMatch/init.js | 3 +-- .../envelope-header-transaction-name/init.js | 3 +-- .../suites/tracing/metrics/init.js | 3 +-- .../create-react-app/src/index.tsx | 3 +-- .../create-remix-app-v2/app/entry.client.tsx | 6 ++++-- .../create-remix-app/app/entry.client.tsx | 7 +------ .../test-apps/booking-app/with-replay.html | 2 +- .../test-apps/booking-app/with-sentry.html | 2 +- packages/astro/src/integration/snippets.ts | 2 +- packages/astro/test/integration/snippets.test.ts | 6 +++--- .../remix/test/integration/app_v1/entry.client.tsx | 6 ++++-- 23 files changed, 37 insertions(+), 51 deletions(-) diff --git a/.size-limit.js b/.size-limit.js index 5e94a923e656..739c3f62aae1 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -3,28 +3,28 @@ module.exports = [ { name: '@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped)', path: 'packages/browser/build/npm/esm/index.js', - import: '{ init, Replay, BrowserTracing, Feedback }', + import: '{ init, Replay, browserTracingIntegration, Feedback }', gzip: true, limit: '90 KB', }, { name: '@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped)', path: 'packages/browser/build/npm/esm/index.js', - import: '{ init, Replay, BrowserTracing }', + import: '{ init, Replay, browserTracingIntegration }', gzip: true, limit: '75 KB', }, { name: '@sentry/browser (incl. Tracing, Replay with Canvas) - Webpack (gzipped)', path: 'packages/browser/build/npm/esm/index.js', - import: '{ init, Replay, BrowserTracing, ReplayCanvas }', + import: '{ init, Replay, browserTracingIntegration, ReplayCanvas }', gzip: true, limit: '90 KB', }, { name: '@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped)', path: 'packages/browser/build/npm/esm/index.js', - import: '{ init, Replay, BrowserTracing }', + import: '{ init, Replay, browserTracingIntegration }', gzip: true, limit: '75 KB', modifyWebpackConfig: function (config) { @@ -43,7 +43,7 @@ module.exports = [ { name: '@sentry/browser (incl. Tracing) - Webpack (gzipped)', path: 'packages/browser/build/npm/esm/index.js', - import: '{ init, BrowserTracing }', + import: '{ init, browserTracingIntegration }', gzip: true, limit: '35 KB', }, @@ -138,7 +138,7 @@ module.exports = [ { name: '@sentry/react (incl. Tracing, Replay) - Webpack (gzipped)', path: 'packages/react/build/esm/index.js', - import: '{ init, BrowserTracing, Replay }', + import: '{ init, browserTracingIntegration, Replay }', gzip: true, limit: '75 KB', }, @@ -154,7 +154,7 @@ module.exports = [ { name: '@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped)', path: 'packages/nextjs/build/esm/client/index.js', - import: '{ init, BrowserTracing, Replay }', + import: '{ init, browserTracingIntegration, Replay }', gzip: true, limit: '110 KB', }, diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/init.js b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/init.js index cd05f29615bb..e8ba5702cff8 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/init.js @@ -5,7 +5,7 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', sampleRate: 1, - integrations: [new Sentry.Integrations.BrowserTracing()], + integrations: [new Sentry.browserTracingIntegration()], }); // This should not fail diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js b/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js index 95f654dd4428..e8ba5702cff8 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js @@ -5,7 +5,7 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', sampleRate: 1, - integrations: [new Sentry.BrowserTracing()], + integrations: [new Sentry.browserTracingIntegration()], }); // This should not fail diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/init.js index a4bddcff1b21..cc71ddf80317 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/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({ idleTimeout: 9000 })], + integrations: [new Sentry.browserTracingIntegration({ idleTimeout: 9000 })], tracesSampleRate: 1, }); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/init.js index efe1e2ef9778..e32d09a13fab 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/init.js @@ -1,12 +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({ + Sentry.browserTracingIntegration({ idleTimeout: 1000, _experiments: { enableHTTPTimings: true, diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/init.js index d30222b7f47e..cb9e47548c4a 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/init.js @@ -1,12 +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({ + Sentry.browserTracingIntegration({ idleTimeout: 1000, _experiments: { enableInteractions: true, diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js index c1d5e8a8a7ae..06e7886e0b1d 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/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({ enableLongTask: false, idleTimeout: 9000 })], + integrations: [new Sentry.browserTracingIntegration({ enableLongTask: false, idleTimeout: 9000 })], tracesSampleRate: 1, }); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/init.js index 037e2dc88517..1bc041d266be 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/init.js @@ -1,12 +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({ + new Sentry.browserTracingIntegration({ idleTimeout: 9000, }), ], diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/init.js index 50f4a898e251..d4c7810ef518 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/init.js @@ -1,11 +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()], + integrations: [Sentry.browserTracingIntegration()], tracesSampleRate: 1, environment: 'staging', }); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageload/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageload/init.js index 2340df528aa7..1f0b64911a75 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageload/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageload/init.js @@ -1,11 +1,10 @@ import * as Sentry from '@sentry/browser'; -import { Integrations } from '@sentry/tracing'; window.Sentry = Sentry; window._testBaseTimestamp = performance.timeOrigin / 1000; 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/browsertracing/pageloadDelayed/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadDelayed/init.js index ff6345dec8f2..2c5a44a7f76d 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadDelayed/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadDelayed/init.js @@ -1,5 +1,4 @@ import * as Sentry from '@sentry/browser'; -import { Integrations } from '@sentry/tracing'; window.Sentry = Sentry; window._testBaseTimestamp = performance.timeOrigin / 1000; @@ -8,7 +7,7 @@ setTimeout(() => { window._testTimeoutTimestamp = (performance.timeOrigin + performance.now()) / 1000; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new Integrations.BrowserTracing()], + integrations: [Sentry.browserTracingIntegration()], tracesSampleRate: 1, }); }, 250); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadWithHeartbeatTimeout/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadWithHeartbeatTimeout/init.js index ce0d16f0f0db..8b12fe807d7b 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadWithHeartbeatTimeout/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadWithHeartbeatTimeout/init.js @@ -1,12 +1,11 @@ import * as Sentry from '@sentry/browser'; import { startSpanManual } 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/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/init.js index ce4e0c4ad7f7..83076460599f 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/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-transaction-name/init.js b/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js index e28325fcf78e..c8ae4c87a514 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js @@ -1,11 +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: [/.*/] })], + integrations: [Sentry.browserTracingIntegration({ tracingOrigins: [/.*/] })], environment: 'production', tracesSampleRate: 1, debug: true, diff --git a/dev-packages/browser-integration-tests/suites/tracing/metrics/init.js b/dev-packages/browser-integration-tests/suites/tracing/metrics/init.js index 037e2dc88517..ad1d8832b228 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/metrics/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/metrics/init.js @@ -1,12 +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({ + Sentry.browserTracingIntegration({ idleTimeout: 9000, }), ], diff --git a/dev-packages/e2e-tests/test-applications/create-react-app/src/index.tsx b/dev-packages/e2e-tests/test-applications/create-react-app/src/index.tsx index f4f58b689b9e..1c10b3e92da6 100644 --- a/dev-packages/e2e-tests/test-applications/create-react-app/src/index.tsx +++ b/dev-packages/e2e-tests/test-applications/create-react-app/src/index.tsx @@ -1,5 +1,4 @@ import * as Sentry from '@sentry/react'; -import { BrowserTracing } from '@sentry/tracing'; import React from 'react'; import ReactDOM from 'react-dom/client'; import App from './App'; @@ -9,7 +8,7 @@ import reportWebVitals from './reportWebVitals'; Sentry.init({ environment: 'qa', // dynamic sampling bias to keep transactions dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new BrowserTracing()], + integrations: [Sentry.browserTracingIntegration()], // We recommend adjusting this value in production, or using tracesSampler // for finer control diff --git a/dev-packages/e2e-tests/test-applications/create-remix-app-v2/app/entry.client.tsx b/dev-packages/e2e-tests/test-applications/create-remix-app-v2/app/entry.client.tsx index 15cb6513a917..45d2fa9aaf83 100644 --- a/dev-packages/e2e-tests/test-applications/create-remix-app-v2/app/entry.client.tsx +++ b/dev-packages/e2e-tests/test-applications/create-remix-app-v2/app/entry.client.tsx @@ -12,8 +12,10 @@ import { hydrateRoot } from 'react-dom/client'; Sentry.init({ dsn: window.ENV.SENTRY_DSN, integrations: [ - new Sentry.BrowserTracing({ - routingInstrumentation: Sentry.remixRouterInstrumentation(useEffect, useLocation, useMatches), + Sentry.browserTracingIntegration({ + useEffect, + useLocation, + useMatches, }), new Sentry.Replay(), ], diff --git a/dev-packages/e2e-tests/test-applications/create-remix-app/app/entry.client.tsx b/dev-packages/e2e-tests/test-applications/create-remix-app/app/entry.client.tsx index 15cb6513a917..96c77dd1f399 100644 --- a/dev-packages/e2e-tests/test-applications/create-remix-app/app/entry.client.tsx +++ b/dev-packages/e2e-tests/test-applications/create-remix-app/app/entry.client.tsx @@ -11,12 +11,7 @@ import { hydrateRoot } from 'react-dom/client'; Sentry.init({ dsn: window.ENV.SENTRY_DSN, - integrations: [ - new Sentry.BrowserTracing({ - routingInstrumentation: Sentry.remixRouterInstrumentation(useEffect, useLocation, useMatches), - }), - new Sentry.Replay(), - ], + integrations: [Sentry.browserTracingIntegration({ useEffect, useMatches, useLocation }), new Sentry.Replay()], // Performance Monitoring tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production! // Session Replay diff --git a/dev-packages/overhead-metrics/test-apps/booking-app/with-replay.html b/dev-packages/overhead-metrics/test-apps/booking-app/with-replay.html index 7f471cc12c94..21f19f6260be 100644 --- a/dev-packages/overhead-metrics/test-apps/booking-app/with-replay.html +++ b/dev-packages/overhead-metrics/test-apps/booking-app/with-replay.html @@ -223,7 +223,7 @@

This is a test app.

replaysOnErrorSampleRate: 1.0, enableTracing: true, integrations: [ - new Sentry.Integrations.BrowserTracing(), + Sentry.browserTracingIntegration(), new Sentry.Integrations.Replay({ useCompression: true, flushMinDelay: 2000, diff --git a/dev-packages/overhead-metrics/test-apps/booking-app/with-sentry.html b/dev-packages/overhead-metrics/test-apps/booking-app/with-sentry.html index cd122c172ad2..94c581f184ab 100644 --- a/dev-packages/overhead-metrics/test-apps/booking-app/with-sentry.html +++ b/dev-packages/overhead-metrics/test-apps/booking-app/with-sentry.html @@ -220,7 +220,7 @@

This is a test app.

Sentry.init({ dsn: 'https://d16ae2d36f9249849c7964e9a3a8a608@o447951.ingest.sentry.io/5429213', enableTracing: true, - integrations: [new Sentry.Integrations.BrowserTracing()], + integrations: [Sentry.browserTracingIntegration()], }); diff --git a/packages/astro/src/integration/snippets.ts b/packages/astro/src/integration/snippets.ts index ad5047e9954a..5a9ec2e4dcfe 100644 --- a/packages/astro/src/integration/snippets.ts +++ b/packages/astro/src/integration/snippets.ts @@ -57,7 +57,7 @@ const buildClientIntegrations = (options: SentryOptions): string => { const integrations: string[] = []; if (options.tracesSampleRate == null || options.tracesSampleRate) { - integrations.push('new Sentry.BrowserTracing()'); + integrations.push('Sentry.browserTracingIntegration()'); } if ( diff --git a/packages/astro/test/integration/snippets.test.ts b/packages/astro/test/integration/snippets.test.ts index 172756847a5c..2a08ec33315c 100644 --- a/packages/astro/test/integration/snippets.test.ts +++ b/packages/astro/test/integration/snippets.test.ts @@ -23,7 +23,7 @@ describe('buildClientSnippet', () => { environment: import.meta.env.PUBLIC_VERCEL_ENV, release: import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA, tracesSampleRate: 1, - integrations: [new Sentry.BrowserTracing(), new Sentry.Replay()], + integrations: [Sentry.browserTracingIntegration(), new Sentry.Replay()], replaysSessionSampleRate: 0.1, replaysOnErrorSampleRate: 1, });" @@ -43,7 +43,7 @@ describe('buildClientSnippet', () => { release: \\"1.0.0\\", tracesSampleRate: 0.3, sampleRate: 0.2, - integrations: [new Sentry.BrowserTracing(), new Sentry.Replay()], + integrations: [Sentry.browserTracingIntegration(), new Sentry.Replay()], replaysSessionSampleRate: 0.5, replaysOnErrorSampleRate: 0.4, });" @@ -80,7 +80,7 @@ it('does not include Replay if replay sample ratest are 0', () => { environment: import.meta.env.PUBLIC_VERCEL_ENV, release: import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA, tracesSampleRate: 1, - integrations: [new Sentry.BrowserTracing()], + integrations: [Sentry.browserTracingIntegration()], replaysSessionSampleRate: 0, replaysOnErrorSampleRate: 0, });" diff --git a/packages/remix/test/integration/app_v1/entry.client.tsx b/packages/remix/test/integration/app_v1/entry.client.tsx index 17da03ff6a70..bdee1860d03f 100644 --- a/packages/remix/test/integration/app_v1/entry.client.tsx +++ b/packages/remix/test/integration/app_v1/entry.client.tsx @@ -7,8 +7,10 @@ Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', tracesSampleRate: 1, integrations: [ - new Sentry.BrowserTracing({ - routingInstrumentation: Sentry.remixRouterInstrumentation(useEffect, useLocation, useMatches), + Sentry.browserTracingIntegration({ + useEffect, + useLocation, + useMatches, }), ], }); From a941362fddf2f1f70b3709a43a6b33a732e87393 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 14 Feb 2024 15:50:54 +0000 Subject: [PATCH 02/44] fix --- .../browserTracingIntegrationHashShim/init.js | 2 +- .../suites/tracing/browserTracingShim/init.js | 2 +- .../backgroundtab-custom/init.js | 2 +- .../long-tasks-disabled/init.js | 2 +- .../browsertracing/long-tasks-enabled/init.js | 2 +- yarn.lock | 32 ++++++++++++++++--- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/init.js b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/init.js index e8ba5702cff8..d7cfd52aedcc 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/init.js @@ -5,7 +5,7 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', sampleRate: 1, - integrations: [new Sentry.browserTracingIntegration()], + integrations: [Sentry.browserTracingIntegration()], }); // This should not fail diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js b/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js index e8ba5702cff8..d7cfd52aedcc 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js @@ -5,7 +5,7 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', sampleRate: 1, - integrations: [new Sentry.browserTracingIntegration()], + integrations: [Sentry.browserTracingIntegration()], }); // This should not fail diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/init.js index cc71ddf80317..e5453b648509 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/init.js @@ -4,6 +4,6 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new Sentry.browserTracingIntegration({ idleTimeout: 9000 })], + integrations: [Sentry.browserTracingIntegration({ idleTimeout: 9000 })], tracesSampleRate: 1, }); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js index 06e7886e0b1d..bde12a1304ed 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js @@ -4,6 +4,6 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [new Sentry.browserTracingIntegration({ enableLongTask: false, idleTimeout: 9000 })], + integrations: [Sentry.browserTracingIntegration({ enableLongTask: false, idleTimeout: 9000 })], tracesSampleRate: 1, }); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/init.js index 1bc041d266be..ad1d8832b228 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/init.js @@ -5,7 +5,7 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', integrations: [ - new Sentry.browserTracingIntegration({ + Sentry.browserTracingIntegration({ idleTimeout: 9000, }), ], diff --git a/yarn.lock b/yarn.lock index 56b525f02a77..e85098e415ac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5913,6 +5913,18 @@ sirv "^2.0.3" tiny-glob "^0.2.9" +"@sveltejs/vite-plugin-svelte@1.4.0": + version "1.4.0" + resolved "https://registry.yarnpkg.com/@sveltejs/vite-plugin-svelte/-/vite-plugin-svelte-1.4.0.tgz#412a735de489ca731d0c780c2b410f45dd95b392" + integrity sha512-6QupI/jemMfK+yI2pMtJcu5iO2gtgTfcBdGwMZZt+lgbFELhszbDl6Qjh000HgAV8+XUA+8EY8DusOFk8WhOIg== + dependencies: + debug "^4.3.4" + deepmerge "^4.2.2" + kleur "^4.1.5" + magic-string "^0.26.7" + svelte-hmr "^0.15.1" + vitefu "^0.2.2" + "@szmarczak/http-timer@^1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-1.1.2.tgz#b1665e2c461a2cd92f4c1bbf50d5454de0d4b421" @@ -21294,6 +21306,13 @@ magic-string@^0.25.0, magic-string@^0.25.1, magic-string@^0.25.7: dependencies: sourcemap-codec "^1.4.8" +magic-string@^0.26.7: + version "0.26.7" + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.26.7.tgz#caf7daf61b34e9982f8228c4527474dac8981d6f" + integrity sha512-hX9XH3ziStPoPhJxLq1syWuZMxbDvGNbVchfrdCtanC7D13888bMFow61x8axrx+GfHLtVeAx2kxL7tTGRl+Ow== + dependencies: + sourcemap-codec "^1.4.8" + magic-string@^0.30.0: version "0.30.0" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.30.0.tgz#fd58a4748c5c4547338a424e90fa5dd17f4de529" @@ -30065,10 +30084,10 @@ supports-preserve-symlinks-flag@^1.0.0: resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09" integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w== -svelte-jester@^2.3.2: - version "2.3.2" - resolved "https://registry.yarnpkg.com/svelte-jester/-/svelte-jester-2.3.2.tgz#9eb818da30807bbcc940b6130d15b2c34408d64f" - integrity sha512-JtxSz4FWAaCRBXbPsh4LcDs4Ua7zdXgLC0TZvT1R56hRV0dymmNP+abw67DTPF7sQPyNxWsOKd0Sl7Q8SnP8kg== +svelte-hmr@^0.15.1: + version "0.15.3" + resolved "https://registry.yarnpkg.com/svelte-hmr/-/svelte-hmr-0.15.3.tgz#df54ccde9be3f091bf5f18fc4ef7b8eb6405fbe6" + integrity sha512-41snaPswvSf8TJUhlkoJBekRrABDXDMdpNpT2tfHIv4JuhgvHqLMhEPGtaQn0BmbNSTkuz2Ed20DF2eHw0SmBQ== svelte@3.49.0: version "3.49.0" @@ -31940,6 +31959,11 @@ vite@^5.0.10: optionalDependencies: fsevents "~2.3.3" +vitefu@^0.2.2: + version "0.2.5" + resolved "https://registry.yarnpkg.com/vitefu/-/vitefu-0.2.5.tgz#c1b93c377fbdd3e5ddd69840ea3aa70b40d90969" + integrity sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q== + vitefu@^0.2.4: version "0.2.4" resolved "https://registry.yarnpkg.com/vitefu/-/vitefu-0.2.4.tgz#212dc1a9d0254afe65e579351bed4e25d81e0b35" From 5f376a72be72e492258b91ac06151ebd60ecf98b Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 14 Feb 2024 15:54:47 +0000 Subject: [PATCH 03/44] . --- .../tracing/envelope-header-transaction-name/init.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js b/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js index c8ae4c87a514..c383862da218 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js @@ -4,16 +4,18 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [Sentry.browserTracingIntegration({ tracingOrigins: [/.*/] })], + integrations: [Sentry.browserTracingIntegration()], environment: 'production', tracesSampleRate: 1, debug: true, }); -const scope = Sentry.getCurrentScope(); -scope.setUser({ id: 'user123' }); -scope.addEventProcessor(event => { +Sentry.setUser({ id: 'user123' }); + +Sentry.addEventProcessor(event => { event.transaction = 'testTransactionDSC'; return event; }); + +const scope = Sentry.getCurrentScope(); scope.getTransaction().setMetadata({ source: 'custom' }); From 6eebdeb0fa700530a610f17078c2c97040bdf724 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 15 Feb 2024 11:06:56 +0000 Subject: [PATCH 04/44] wth man --- .../tracing/envelope-header-transaction-name/init.js | 3 ++- packages/core/src/tracing/dynamicSamplingContext.ts | 6 ++++++ .../src/browser/browserTracingIntegration.ts | 4 ++-- packages/tracing-internal/src/browser/router.ts | 10 +++++++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js b/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js index c383862da218..d0b402e3ffc8 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js @@ -4,7 +4,7 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [Sentry.browserTracingIntegration()], + integrations: [new Sentry.BrowserTracing()], environment: 'production', tracesSampleRate: 1, debug: true, @@ -19,3 +19,4 @@ Sentry.addEventProcessor(event => { const scope = Sentry.getCurrentScope(); scope.getTransaction().setMetadata({ source: 'custom' }); +scope.getTransaction().setAttributes({ [Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom' }); diff --git a/packages/core/src/tracing/dynamicSamplingContext.ts b/packages/core/src/tracing/dynamicSamplingContext.ts index d7fe3872b42f..9cf9ccbd590d 100644 --- a/packages/core/src/tracing/dynamicSamplingContext.ts +++ b/packages/core/src/tracing/dynamicSamplingContext.ts @@ -3,6 +3,7 @@ import { dropUndefinedKeys } from '@sentry/utils'; import { DEFAULT_ENVIRONMENT } from '../constants'; import { getClient } from '../exports'; +import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes'; import { getRootSpan } from '../utils/getRootSpan'; import { spanIsSampled, spanToJSON } from '../utils/spanUtils'; @@ -74,6 +75,11 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly( return; } - let startingUrl: string | undefined = WINDOW.location.href; + let startingUrl: string | undefined = 'wtf4'; let activeTransaction: T | undefined; if (startTransactionOnPageLoad) { activeTransaction = customStartTransaction({ - name: WINDOW.location.pathname, + name: WINDOW.location.pathname, // wtf5 // pageload should always start at timeOrigin (and needs to be in s, not ms) startTimestamp: browserPerformanceTimeOrigin ? browserPerformanceTimeOrigin / 1000 : undefined, op: 'pageload', origin: 'auto.pageload.browser', metadata: { source: 'url' }, + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', + }, }); } @@ -55,7 +59,7 @@ export function instrumentRoutingWithDefaults( activeTransaction.end(); } activeTransaction = customStartTransaction({ - name: WINDOW.location.pathname, + name: 'wtf6', op: 'navigation', origin: 'auto.navigation.browser', metadata: { source: 'url' }, From 361c22d435086e9a0a89fd29269fd8034d0c7d8e Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 15 Feb 2024 12:30:07 +0000 Subject: [PATCH 05/44] ref: Migrate transaction source from metadata to attributes --- .../envelope-header-transaction-name/init.js | 3 +- .../src/tracing/dynamicSamplingContext.ts | 5 +- packages/core/src/tracing/transaction.ts | 15 +++-- .../tracing/dynamicSamplingContext.test.ts | 13 +++-- .../core/test/lib/tracing/transaction.test.ts | 26 ++------- .../common/withServerActionInstrumentation.ts | 6 +- .../test/integration/transactions.test.ts | 58 ++++++++++++------- packages/node/test/integrations/http.test.ts | 6 +- .../opentelemetry-node/src/spanprocessor.ts | 4 +- packages/opentelemetry/src/spanExporter.ts | 5 +- .../test/integration/transactions.test.ts | 6 +- packages/opentelemetry/test/trace.test.ts | 8 ++- packages/remix/src/client/performance.tsx | 8 +-- packages/remix/src/utils/instrumentServer.ts | 3 +- packages/sveltekit/src/client/load.ts | 11 ++-- packages/sveltekit/src/server/handle.ts | 3 +- packages/sveltekit/src/server/load.ts | 13 +++-- .../src/browser/browserTracingIntegration.ts | 23 ++------ .../src/browser/browsertracing.ts | 23 ++------ .../tracing-internal/src/browser/router.ts | 9 ++- packages/types/src/span.ts | 4 +- packages/types/src/transaction.ts | 8 +-- packages/utils/src/requestdata.ts | 9 +-- 23 files changed, 138 insertions(+), 131 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js b/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js index e28325fcf78e..579523ee2015 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/envelope-header-transaction-name/init.js @@ -1,4 +1,5 @@ import * as Sentry from '@sentry/browser'; +import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/browser'; import { Integrations } from '@sentry/tracing'; window.Sentry = Sentry; @@ -17,4 +18,4 @@ scope.addEventProcessor(event => { event.transaction = 'testTransactionDSC'; return event; }); -scope.getTransaction().setMetadata({ source: 'custom' }); +scope.getTransaction().setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'custom'); diff --git a/packages/core/src/tracing/dynamicSamplingContext.ts b/packages/core/src/tracing/dynamicSamplingContext.ts index d7fe3872b42f..e5bc279a1ef9 100644 --- a/packages/core/src/tracing/dynamicSamplingContext.ts +++ b/packages/core/src/tracing/dynamicSamplingContext.ts @@ -3,6 +3,7 @@ import { dropUndefinedKeys } from '@sentry/utils'; import { DEFAULT_ENVIRONMENT } from '../constants'; import { getClient } from '../exports'; +import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes'; import { getRootSpan } from '../utils/getRootSpan'; import { spanIsSampled, spanToJSON } from '../utils/spanUtils'; @@ -66,7 +67,7 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly { name: 'tx', metadata: { sampleRate: 0.56, - source: 'route', + }, + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', }, sampled: true, }); @@ -97,9 +98,11 @@ describe('getDynamicSamplingContextFromSpan', () => { const transaction = new Transaction({ name: 'tx', metadata: { - source: 'url', sampleRate: 0.56, }, + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', + }, }); const dsc = getDynamicSamplingContextFromSpan(transaction); @@ -112,8 +115,8 @@ describe('getDynamicSamplingContextFromSpan', () => { ])('%s', (_: string, source) => { const transaction = startInactiveSpan({ name: 'tx', - metadata: { - ...(source && { source: source as TransactionSource }), + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source, }, }); diff --git a/packages/core/test/lib/tracing/transaction.test.ts b/packages/core/test/lib/tracing/transaction.test.ts index 415c0448f78e..fa6abde9f545 100644 --- a/packages/core/test/lib/tracing/transaction.test.ts +++ b/packages/core/test/lib/tracing/transaction.test.ts @@ -16,7 +16,7 @@ describe('transaction', () => { transaction.name = 'new name'; expect(transaction.name).toEqual('new name'); - expect(transaction.metadata.source).toEqual('custom'); + expect(transaction.attributes['sentry.source']).toEqual('custom'); }); it('allows to update the name via setName', () => { @@ -27,7 +27,7 @@ describe('transaction', () => { transaction.setName('new name'); expect(transaction.name).toEqual('new name'); - expect(transaction.metadata.source).toEqual('custom'); + expect(transaction.attributes['sentry.source']).toEqual('custom'); }); it('allows to update the name via updateName', () => { @@ -38,7 +38,7 @@ describe('transaction', () => { transaction.updateName('new name'); expect(transaction.name).toEqual('new name'); - expect(transaction.metadata.source).toEqual('route'); + expect(transaction.attributes['sentry.source']).toEqual('route'); }); /* eslint-enable deprecation/deprecation */ }); @@ -48,15 +48,13 @@ describe('transaction', () => { it('works with defaults', () => { const transaction = new Transaction({ name: 'span name' }); expect(transaction.metadata).toEqual({ - source: 'custom', spanMetadata: {}, }); }); it('allows to set metadata in constructor', () => { - const transaction = new Transaction({ name: 'span name', metadata: { source: 'url', request: {} } }); + const transaction = new Transaction({ name: 'span name', metadata: { request: {} } }); expect(transaction.metadata).toEqual({ - source: 'url', spanMetadata: {}, request: {}, }); @@ -80,28 +78,16 @@ describe('transaction', () => { }); it('allows to update metadata via setMetadata', () => { - const transaction = new Transaction({ name: 'span name', metadata: { source: 'url', request: {} } }); + const transaction = new Transaction({ name: 'span name', metadata: {} }); - transaction.setMetadata({ source: 'route' }); + transaction.setMetadata({ request: {} }); expect(transaction.metadata).toEqual({ - source: 'route', spanMetadata: {}, request: {}, }); }); - it('allows to update metadata via setAttribute', () => { - const transaction = new Transaction({ name: 'span name', metadata: { source: 'url', request: {} } }); - - transaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route'); - - expect(transaction.metadata).toEqual({ - source: 'route', - spanMetadata: {}, - request: {}, - }); - }); /* eslint-enable deprecation/deprecation */ }); }); diff --git a/packages/nextjs/src/common/withServerActionInstrumentation.ts b/packages/nextjs/src/common/withServerActionInstrumentation.ts index 1f4cdaf992c9..0c54a4f5b665 100644 --- a/packages/nextjs/src/common/withServerActionInstrumentation.ts +++ b/packages/nextjs/src/common/withServerActionInstrumentation.ts @@ -1,4 +1,4 @@ -import { getIsolationScope } from '@sentry/core'; +import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getIsolationScope } from '@sentry/core'; import { addTracingExtensions, captureException, @@ -94,8 +94,8 @@ async function withServerActionInstrumentationImplementation { diff --git a/packages/node-experimental/test/integration/transactions.test.ts b/packages/node-experimental/test/integration/transactions.test.ts index 7de51c7811e6..23edcca3c579 100644 --- a/packages/node-experimental/test/integration/transactions.test.ts +++ b/packages/node-experimental/test/integration/transactions.test.ts @@ -32,7 +32,9 @@ describe('Integration | Transactions', () => { { op: 'test op', name: 'test name', - source: 'task', + attributes: { + [Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task', + }, origin: 'auto.test', metadata: { requestPath: 'test-path' }, }, @@ -188,26 +190,34 @@ describe('Integration | Transactions', () => { Sentry.addBreadcrumb({ message: 'test breadcrumb 1', timestamp: 123456 }); Sentry.withIsolationScope(() => { - Sentry.startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, span => { - Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 }); + Sentry.startSpan( + { + op: 'test op', + name: 'test name', + origin: 'auto.test', + attributes: { [Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task' }, + }, + span => { + Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 }); - span.setAttributes({ - 'test.outer': 'test value', - }); + span.setAttributes({ + 'test.outer': 'test value', + }); - const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' }); - subSpan.end(); + const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' }); + subSpan.end(); - Sentry.setTag('test.tag', 'test value'); + Sentry.setTag('test.tag', 'test value'); - Sentry.startSpan({ name: 'inner span 2' }, innerSpan => { - Sentry.addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 }); + Sentry.startSpan({ name: 'inner span 2' }, innerSpan => { + Sentry.addBreadcrumb({ message: 'test breadcrumb 3', timestamp: 123456 }); - innerSpan.setAttributes({ - 'test.inner': 'test value', + innerSpan.setAttributes({ + 'test.inner': 'test value', + }); }); - }); - }); + }, + ); }); Sentry.withIsolationScope(() => { @@ -511,12 +521,20 @@ describe('Integration | Transactions', () => { context.with( trace.setSpanContext(setPropagationContextOnContext(context.active(), propagationContext), spanContext), () => { - Sentry.startSpan({ op: 'test op', name: 'test name', source: 'task', origin: 'auto.test' }, () => { - const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' }); - subSpan.end(); + Sentry.startSpan( + { + op: 'test op', + name: 'test name', + origin: 'auto.test', + attributes: { [Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task' }, + }, + () => { + const subSpan = Sentry.startInactiveSpan({ name: 'inner span 1' }); + subSpan.end(); - Sentry.startSpan({ name: 'inner span 2' }, () => {}); - }); + Sentry.startSpan({ name: 'inner span 2' }, () => {}); + }, + ); }, ); diff --git a/packages/node/test/integrations/http.test.ts b/packages/node/test/integrations/http.test.ts index b7e2149c74c9..a055aca30948 100644 --- a/packages/node/test/integrations/http.test.ts +++ b/packages/node/test/integrations/http.test.ts @@ -1,6 +1,6 @@ import * as http from 'http'; import * as https from 'https'; -import type { Span } from '@sentry/core'; +import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Span } from '@sentry/core'; import { Transaction } from '@sentry/core'; import { getCurrentScope, makeMain, setUser, spanToJSON, startInactiveSpan } from '@sentry/core'; import { Hub, addTracingExtensions } from '@sentry/core'; @@ -162,7 +162,7 @@ describe('tracing', () => { it('adds the transaction name to the the baggage header if a valid transaction source is set', async () => { nock('http://dogs.are.great').get('/').reply(200); - createTransactionOnScope({}, { metadata: { source: 'route' } }); + createTransactionOnScope({}, { attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route' } }); const request = http.get({ host: 'http://dogs.are.great/', headers: { baggage: 'dog=great' } }); const baggageHeader = request.getHeader('baggage') as string; @@ -176,7 +176,7 @@ describe('tracing', () => { it('does not add the transaction name to the the baggage header if url transaction source is set', async () => { nock('http://dogs.are.great').get('/').reply(200); - createTransactionOnScope({}, { metadata: { source: 'url' } }); + createTransactionOnScope({}, { attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url' } }); const request = http.get({ host: 'http://dogs.are.great/', headers: { baggage: 'dog=great' } }); const baggageHeader = request.getHeader('baggage') as string; diff --git a/packages/opentelemetry-node/src/spanprocessor.ts b/packages/opentelemetry-node/src/spanprocessor.ts index 9996fc73111f..f79dc9f5b2e4 100644 --- a/packages/opentelemetry-node/src/spanprocessor.ts +++ b/packages/opentelemetry-node/src/spanprocessor.ts @@ -179,7 +179,9 @@ function getTraceData(otelSpan: OtelSpan, parentContext: Context): Partial { { op: 'test op', name: 'test name', - source: 'task', origin: 'auto.test', metadata: { requestPath: 'test-path' }, + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task', + }, }, span => { addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 }); diff --git a/packages/opentelemetry/test/trace.test.ts b/packages/opentelemetry/test/trace.test.ts index 5785eb7fdb00..fa6e1d09dad8 100644 --- a/packages/opentelemetry/test/trace.test.ts +++ b/packages/opentelemetry/test/trace.test.ts @@ -218,8 +218,10 @@ describe('trace', () => { name: 'outer', op: 'my-op', origin: 'auto.test.origin', - source: 'task', metadata: { requestPath: 'test-path' }, + attributes: { + [InternalSentrySemanticAttributes.SOURCE]: 'task', + }, }, span => { expect(span).toBeDefined(); @@ -335,7 +337,9 @@ describe('trace', () => { name: 'outer', op: 'my-op', origin: 'auto.test.origin', - source: 'task', + attributes: { + [InternalSentrySemanticAttributes.SOURCE]: 'task', + }, metadata: { requestPath: 'test-path' }, }); diff --git a/packages/remix/src/client/performance.tsx b/packages/remix/src/client/performance.tsx index 10e91837149d..347e8a2f73e8 100644 --- a/packages/remix/src/client/performance.tsx +++ b/packages/remix/src/client/performance.tsx @@ -78,8 +78,8 @@ export function startPageloadSpan(): void { op: 'pageload', origin: 'auto.pageload.remix', tags: DEFAULT_TAGS, - metadata: { - source: 'url', + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', }, }; @@ -103,8 +103,8 @@ function startNavigationSpan(matches: RouteMatch[]): void { op: 'navigation', origin: 'auto.navigation.remix', tags: DEFAULT_TAGS, - metadata: { - source: 'route', + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', }, }; diff --git a/packages/remix/src/utils/instrumentServer.ts b/packages/remix/src/utils/instrumentServer.ts index 7e1822aa8612..793fdbe60f6b 100644 --- a/packages/remix/src/utils/instrumentServer.ts +++ b/packages/remix/src/utils/instrumentServer.ts @@ -1,6 +1,7 @@ /* eslint-disable max-lines */ import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, + SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getActiveSpan, getActiveTransaction, getClient, @@ -415,13 +416,13 @@ export function startRequestHandlerTransaction( op: 'http.server', attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.remix', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source, }, tags: { method: request.method, }, ...traceparentData, metadata: { - source, dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext, }, }); diff --git a/packages/sveltekit/src/client/load.ts b/packages/sveltekit/src/client/load.ts index 3e454bdb364a..621015badbf1 100644 --- a/packages/sveltekit/src/client/load.ts +++ b/packages/sveltekit/src/client/load.ts @@ -1,4 +1,9 @@ -import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, handleCallbackErrors, startSpan } from '@sentry/core'; +import { + SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, + SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, + handleCallbackErrors, + startSpan, +} from '@sentry/core'; import { captureException } from '@sentry/svelte'; import { addNonEnumerableProperty, objectify } from '@sentry/utils'; import type { LoadEvent } from '@sveltejs/kit'; @@ -86,12 +91,10 @@ export function wrapLoadWithSentry any>(origLoad: T) op: 'function.sveltekit.load', attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.sveltekit', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: routeId ? 'route' : 'url', }, name: routeId ? routeId : event.url.pathname, status: 'ok', - metadata: { - source: routeId ? 'route' : 'url', - }, }, () => handleCallbackErrors(() => wrappingTarget.apply(thisArg, [patchedEvent]), sendErrorToSentry), ); diff --git a/packages/sveltekit/src/server/handle.ts b/packages/sveltekit/src/server/handle.ts index 42f95c905ca5..2fa5a16b07b4 100644 --- a/packages/sveltekit/src/server/handle.ts +++ b/packages/sveltekit/src/server/handle.ts @@ -1,5 +1,6 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, + SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getActiveSpan, getCurrentScope, getDynamicSamplingContextFromSpan, @@ -178,12 +179,12 @@ async function instrumentHandle( op: 'http.server', attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.sveltekit', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: event.route?.id ? 'route' : 'url', }, name: `${event.request.method} ${event.route?.id || event.url.pathname}`, status: 'ok', ...traceparentData, metadata: { - source: event.route?.id ? 'route' : 'url', dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext, }, }, diff --git a/packages/sveltekit/src/server/load.ts b/packages/sveltekit/src/server/load.ts index 9728dcf47b5b..0d73b27a9d1b 100644 --- a/packages/sveltekit/src/server/load.ts +++ b/packages/sveltekit/src/server/load.ts @@ -1,5 +1,10 @@ /* eslint-disable @sentry-internal/sdk/no-optional-chaining */ -import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getCurrentScope, startSpan } from '@sentry/core'; +import { + SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, + SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, + getCurrentScope, + startSpan, +} from '@sentry/core'; import { captureException } from '@sentry/node'; import { addNonEnumerableProperty, objectify } from '@sentry/utils'; import type { LoadEvent, ServerLoadEvent } from '@sveltejs/kit'; @@ -69,12 +74,10 @@ export function wrapLoadWithSentry any>(origLoad: T) op: 'function.sveltekit.load', attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.sveltekit', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: routeId ? 'route' : 'url', }, name: routeId ? routeId : event.url.pathname, status: 'ok', - metadata: { - source: routeId ? 'route' : 'url', - }, }; try { @@ -138,11 +141,11 @@ export function wrapServerLoadWithSentry any>(origSe op: 'function.sveltekit.server.load', attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.sveltekit', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: routeId ? 'route' : 'url', }, name: routeId ? routeId : event.url.pathname, status: 'ok', metadata: { - source: routeId ? 'route' : 'url', dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext, }, data: { diff --git a/packages/tracing-internal/src/browser/browserTracingIntegration.ts b/packages/tracing-internal/src/browser/browserTracingIntegration.ts index 95dee0c42f5e..ad70af5aa666 100644 --- a/packages/tracing-internal/src/browser/browserTracingIntegration.ts +++ b/packages/tracing-internal/src/browser/browserTracingIntegration.ts @@ -236,16 +236,15 @@ export const browserTracingIntegration = ((_options: Partial( startTimestamp: browserPerformanceTimeOrigin ? browserPerformanceTimeOrigin / 1000 : undefined, op: 'pageload', origin: 'auto.pageload.browser', - metadata: { source: 'url' }, + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', + }, }); } @@ -58,7 +61,9 @@ export function instrumentRoutingWithDefaults( name: WINDOW.location.pathname, op: 'navigation', origin: 'auto.navigation.browser', - metadata: { source: 'url' }, + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', + }, }); } }); diff --git a/packages/types/src/span.ts b/packages/types/src/span.ts index 69704d497b8f..f9e29a188327 100644 --- a/packages/types/src/span.ts +++ b/packages/types/src/span.ts @@ -2,7 +2,7 @@ import type { TraceContext } from './context'; import type { Instrumenter } from './instrumenter'; import type { Primitive } from './misc'; import type { HrTime } from './opentelemetry'; -import type { Transaction } from './transaction'; +import type { Transaction, TransactionSource } from './transaction'; type SpanOriginType = 'manual' | 'auto'; type SpanOriginCategory = string; // e.g. http, db, ui, .... @@ -26,7 +26,7 @@ export type SpanAttributeValue = export type SpanAttributes = Partial<{ 'sentry.origin': string; 'sentry.op': string; - 'sentry.source': string; + 'sentry.source': TransactionSource; 'sentry.sample_rate': number; }> & Record; diff --git a/packages/types/src/transaction.ts b/packages/types/src/transaction.ts index fbcf8b38f02d..f57841e63ee9 100644 --- a/packages/types/src/transaction.ts +++ b/packages/types/src/transaction.ts @@ -109,7 +109,7 @@ export interface Transaction extends TransactionContext, Omit Date: Thu, 15 Feb 2024 14:42:11 +0000 Subject: [PATCH 06/44] beep boop --- packages/core/src/tracing/span.ts | 7 ++++++- packages/core/src/tracing/transaction.ts | 3 --- .../tracing/dynamicSamplingContext.test.ts | 3 ++- packages/core/test/lib/tracing/span.test.ts | 21 +++++++++++++------ packages/core/test/lib/tracing/trace.test.ts | 1 + .../core/test/lib/tracing/transaction.test.ts | 15 +++++++++++-- .../core/test/lib/utils/spanUtils.test.ts | 2 ++ 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/packages/core/src/tracing/span.ts b/packages/core/src/tracing/span.ts index 5ded23cc386d..eb6b85c1aeb1 100644 --- a/packages/core/src/tracing/span.ts +++ b/packages/core/src/tracing/span.ts @@ -17,7 +17,11 @@ import { dropUndefinedKeys, logger, timestampInSeconds, uuid4 } from '@sentry/ut import { DEBUG_BUILD } from '../debug-build'; import { getMetricSummaryJsonForSpan } from '../metrics/metric-summary'; -import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes'; +import { + SEMANTIC_ATTRIBUTE_SENTRY_OP, + SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, + SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, +} from '../semanticAttributes'; import { getRootSpan } from '../utils/getRootSpan'; import { TRACE_FLAG_NONE, @@ -140,6 +144,7 @@ export class Span implements SpanInterface { this.setAttributes({ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: spanContext.origin || 'manual', [SEMANTIC_ATTRIBUTE_SENTRY_OP]: spanContext.op, + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom', ...spanContext.attributes, }); diff --git a/packages/core/src/tracing/transaction.ts b/packages/core/src/tracing/transaction.ts index dafed6b4ff47..f699ac3557f3 100644 --- a/packages/core/src/tracing/transaction.ts +++ b/packages/core/src/tracing/transaction.ts @@ -117,9 +117,6 @@ export class Transaction extends SpanClass implements TransactionInterface { ...this._metadata, // From attributes - ...{ - source: (this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] as TransactionSource | undefined) || 'custom', - }, ...(this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] && { sampleRate: this._attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] as TransactionMetadata['sampleRate'], }), diff --git a/packages/core/test/lib/tracing/dynamicSamplingContext.test.ts b/packages/core/test/lib/tracing/dynamicSamplingContext.test.ts index ae3cb9e54e60..3d48cb893594 100644 --- a/packages/core/test/lib/tracing/dynamicSamplingContext.test.ts +++ b/packages/core/test/lib/tracing/dynamicSamplingContext.test.ts @@ -1,3 +1,4 @@ +import { TransactionSource } from '@sentry/types'; import { Hub, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, makeMain } from '../../../src'; import { Transaction, getDynamicSamplingContextFromSpan, startInactiveSpan } from '../../../src/tracing'; import { addTracingExtensions } from '../../../src/tracing'; @@ -112,7 +113,7 @@ describe('getDynamicSamplingContextFromSpan', () => { test.each([ ['is included if transaction source is parameterized route/url', 'route'], ['is included if transaction source is a custom name', 'custom'], - ])('%s', (_: string, source) => { + ] as const)('%s', (_: string, source: TransactionSource) => { const transaction = startInactiveSpan({ name: 'tx', attributes: { diff --git a/packages/core/test/lib/tracing/span.test.ts b/packages/core/test/lib/tracing/span.test.ts index b3c08987d4b2..8aac2340b3e6 100644 --- a/packages/core/test/lib/tracing/span.test.ts +++ b/packages/core/test/lib/tracing/span.test.ts @@ -86,6 +86,7 @@ describe('span', () => { arrayWithUndefined: [1, undefined, 2], // origin is set by default to 'manual' in the Span constructor 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); }); @@ -94,12 +95,12 @@ describe('span', () => { span.setAttribute('str', 'bar'); - // length 2 because `sentry.origin` is always set by default - expect(Object.keys(span['_attributes']).length).toEqual(2); + // length 3 because `sentry.origin` and `sentry.source` are always set by default + expect(Object.keys(span['_attributes']).length).toEqual(3); span.setAttribute('str', undefined); - expect(Object.keys(span['_attributes']).length).toEqual(1); + expect(Object.keys(span['_attributes']).length).toEqual(2); }); it('disallows invalid attribute types', () => { @@ -125,6 +126,7 @@ describe('span', () => { expect(initialAttributes).toEqual({ // origin is set by default to 'manual' in the Span constructor 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); const newAttributes = { @@ -152,6 +154,7 @@ describe('span', () => { boolArray: [true, false], arrayWithUndefined: [1, undefined, 2], 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); expect(span['_attributes']).not.toBe(newAttributes); @@ -172,6 +175,7 @@ describe('span', () => { boolArray: [true, false], arrayWithUndefined: [1, undefined, 2], 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); }); @@ -180,12 +184,12 @@ describe('span', () => { span.setAttribute('str', 'bar'); - // length 2 because `sentry.origin` is always set by default - expect(Object.keys(span['_attributes']).length).toEqual(2); + // length 3 because `sentry.origin` and `sentry.source` are always set by default + expect(Object.keys(span['_attributes']).length).toEqual(3); span.setAttributes({ str: undefined }); - expect(Object.keys(span['_attributes']).length).toEqual(1); + expect(Object.keys(span['_attributes']).length).toEqual(2); }); }); @@ -287,6 +291,7 @@ describe('span', () => { expect(span['_getData']()).toEqual({ // origin is set by default to 'manual' in the Span constructor 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); }); @@ -299,11 +304,13 @@ describe('span', () => { foo: 'bar', // origin is set by default to 'manual' in the Span constructor 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); expect(span['_getData']()).toStrictEqual({ // eslint-disable-next-line deprecation/deprecation ...span.data, 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); }); @@ -315,6 +322,7 @@ describe('span', () => { foo: 'bar', // origin is set by default to 'manual' in the Span constructor 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); // eslint-disable-next-line deprecation/deprecation expect(span['_getData']()).toBe(span.attributes); @@ -335,6 +343,7 @@ describe('span', () => { baz: 'baz', // origin is set by default to 'manual' in the Span constructor 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); // eslint-disable-next-line deprecation/deprecation expect(span['_getData']()).not.toBe(span.attributes); diff --git a/packages/core/test/lib/tracing/trace.test.ts b/packages/core/test/lib/tracing/trace.test.ts index a3276952fd48..1b792bbda539 100644 --- a/packages/core/test/lib/tracing/trace.test.ts +++ b/packages/core/test/lib/tracing/trace.test.ts @@ -256,6 +256,7 @@ describe('startSpan', () => { data: { 'sentry.origin': 'auto.http.browser', 'sentry.sample_rate': 0, + 'sentry.source': 'custom', }, origin: 'auto.http.browser', description: 'GET users/[id]', diff --git a/packages/core/test/lib/tracing/transaction.test.ts b/packages/core/test/lib/tracing/transaction.test.ts index fa6abde9f545..9371bda548fd 100644 --- a/packages/core/test/lib/tracing/transaction.test.ts +++ b/packages/core/test/lib/tracing/transaction.test.ts @@ -1,4 +1,9 @@ -import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Transaction } from '../../../src'; +import { + SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, + SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, + SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, + Transaction, +} from '../../../src'; describe('transaction', () => { describe('name', () => { @@ -69,12 +74,18 @@ describe('transaction', () => { [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 0.5, }, }); + expect(transaction.metadata).toEqual({ - source: 'url', sampleRate: 0.5, spanMetadata: {}, request: {}, }); + + expect(transaction.attributes).toEqual({ + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'manual', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', + [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 0.5, + }); }); it('allows to update metadata via setMetadata', () => { diff --git a/packages/core/test/lib/utils/spanUtils.test.ts b/packages/core/test/lib/utils/spanUtils.test.ts index 0afb59530623..3f52daa39160 100644 --- a/packages/core/test/lib/utils/spanUtils.test.ts +++ b/packages/core/test/lib/utils/spanUtils.test.ts @@ -57,6 +57,7 @@ describe('spanToJSON', () => { start_timestamp: span['_startTime'], data: { 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, }); }); @@ -93,6 +94,7 @@ describe('spanToJSON', () => { data: { 'sentry.op': 'test op', 'sentry.origin': 'auto', + 'sentry.source': 'custom', }, }); }); From 2838b09ba4ca3b6be3c0b5e2272fa0e4392b7ccc Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 15 Feb 2024 14:47:33 +0000 Subject: [PATCH 07/44] I am losing braincells --- .../browser/browserTracingIntegration.test.ts | 4 ++++ .../test/browser/browsertracing.test.ts | 19 +++++++++++++++---- .../test/browser/router.test.ts | 5 +++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts b/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts index 6ae36a8b9304..b886c01909e5 100644 --- a/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts +++ b/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts @@ -232,6 +232,7 @@ describe('browserTracingIntegration', () => { [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload', [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'manual', [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1, + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom', }, span_id: expect.any(String), start_timestamp: expect.any(Number), @@ -265,6 +266,7 @@ describe('browserTracingIntegration', () => { [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload', [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test', [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1, + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom', testy: 'yes', }, span_id: expect.any(String), @@ -326,6 +328,7 @@ describe('browserTracingIntegration', () => { [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation', [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'manual', [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1, + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom', }, span_id: expect.any(String), start_timestamp: expect.any(Number), @@ -359,6 +362,7 @@ describe('browserTracingIntegration', () => { [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation', [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test', [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1, + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom', testy: 'yes', }, span_id: expect.any(String), diff --git a/packages/tracing-internal/test/browser/browsertracing.test.ts b/packages/tracing-internal/test/browser/browsertracing.test.ts index 9d4105dc415d..58e4f741ee7a 100644 --- a/packages/tracing-internal/test/browser/browsertracing.test.ts +++ b/packages/tracing-internal/test/browser/browsertracing.test.ts @@ -1,5 +1,12 @@ /* eslint-disable deprecation/deprecation */ -import { Hub, TRACING_DEFAULTS, makeMain, setCurrentClient, spanToJSON } from '@sentry/core'; +import { + Hub, + SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, + TRACING_DEFAULTS, + makeMain, + setCurrentClient, + spanToJSON, +} from '@sentry/core'; import * as hubExtensions from '@sentry/core'; import type { BaseTransportOptions, ClientOptions, DsnComponents, HandlerDataHistory } from '@sentry/types'; import { JSDOM } from 'jsdom'; @@ -240,7 +247,7 @@ describe('BrowserTracing', () => { const transaction = getActiveTransaction(hub) as IdleTransaction; expect(transaction).toBeDefined(); expect(transaction.name).toBe('newName'); - expect(transaction.metadata.source).toBe('custom'); + expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('custom'); expect(mockBeforeNavigation).toHaveBeenCalledTimes(1); }); @@ -252,13 +259,17 @@ describe('BrowserTracing', () => { createBrowserTracing(true, { beforeNavigate: mockBeforeNavigation, routingInstrumentation: (customStartTransaction: (obj: any) => void) => { - customStartTransaction({ name: 'a/path', op: 'pageload', metadata: { source: 'url' } }); + customStartTransaction({ + name: 'a/path', + op: 'pageload', + attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url' }, + }); }, }); const transaction = getActiveTransaction(hub) as IdleTransaction; expect(transaction).toBeDefined(); expect(transaction.name).toBe('a/path'); - expect(transaction.metadata.source).toBe('url'); + expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('url'); expect(mockBeforeNavigation).toHaveBeenCalledTimes(1); }); diff --git a/packages/tracing-internal/test/browser/router.test.ts b/packages/tracing-internal/test/browser/router.test.ts index a27926ad9803..e7a12ea91506 100644 --- a/packages/tracing-internal/test/browser/router.test.ts +++ b/packages/tracing-internal/test/browser/router.test.ts @@ -1,3 +1,4 @@ +import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; import type { HandlerDataHistory } from '@sentry/types'; import { JSDOM } from 'jsdom'; @@ -45,7 +46,7 @@ conditionalTest({ min: 16 })('instrumentRoutingWithDefaults', () => { name: 'blank', op: 'pageload', origin: 'auto.pageload.browser', - metadata: { source: 'url' }, + attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url' }, startTimestamp: expect.any(Number), }); }); @@ -80,7 +81,7 @@ conditionalTest({ min: 16 })('instrumentRoutingWithDefaults', () => { name: 'blank', op: 'navigation', origin: 'auto.navigation.browser', - metadata: { source: 'url' }, + attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url' }, }); }); From 796eb844e5e195d881c413097115ee3e65683c97 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 15 Feb 2024 15:08:15 +0000 Subject: [PATCH 08/44] ci happy pls --- .../lib/tracing/dynamicSamplingContext.test.ts | 2 +- packages/node/test/integrations/http.test.ts | 3 ++- packages/tracing/test/span.test.ts | 12 ++++++------ packages/tracing/test/transaction.test.ts | 17 ++++++++++------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/core/test/lib/tracing/dynamicSamplingContext.test.ts b/packages/core/test/lib/tracing/dynamicSamplingContext.test.ts index 3d48cb893594..15a3344bfc5e 100644 --- a/packages/core/test/lib/tracing/dynamicSamplingContext.test.ts +++ b/packages/core/test/lib/tracing/dynamicSamplingContext.test.ts @@ -1,4 +1,4 @@ -import { TransactionSource } from '@sentry/types'; +import type { TransactionSource } from '@sentry/types'; import { Hub, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, makeMain } from '../../../src'; import { Transaction, getDynamicSamplingContextFromSpan, startInactiveSpan } from '../../../src/tracing'; import { addTracingExtensions } from '../../../src/tracing'; diff --git a/packages/node/test/integrations/http.test.ts b/packages/node/test/integrations/http.test.ts index a055aca30948..56d7c96b3c8f 100644 --- a/packages/node/test/integrations/http.test.ts +++ b/packages/node/test/integrations/http.test.ts @@ -1,6 +1,7 @@ import * as http from 'http'; import * as https from 'https'; -import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Span } from '@sentry/core'; +import type { Span } from '@sentry/core'; +import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; import { Transaction } from '@sentry/core'; import { getCurrentScope, makeMain, setUser, spanToJSON, startInactiveSpan } from '@sentry/core'; import { Hub, addTracingExtensions } from '@sentry/core'; diff --git a/packages/tracing/test/span.test.ts b/packages/tracing/test/span.test.ts index 798cc2a8263c..5634ca243d9b 100644 --- a/packages/tracing/test/span.test.ts +++ b/packages/tracing/test/span.test.ts @@ -1,7 +1,7 @@ /* eslint-disable deprecation/deprecation */ import { BrowserClient } from '@sentry/browser'; import { Hub, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Scope, makeMain, spanToJSON } from '@sentry/core'; -import type { BaseTransportOptions, ClientOptions, TransactionSource } from '@sentry/types'; +import type { BaseTransportOptions, ClientOptions } from '@sentry/types'; import { Span, TRACEPARENT_REGEXP, Transaction } from '../src'; import { getDefaultBrowserClientOptions } from './testutils'; @@ -638,8 +638,8 @@ describe('Span', () => { const transaction = new Transaction( { name: 'tx', - metadata: { - source: 'url', + attributes: { + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', }, }, hub, @@ -652,12 +652,12 @@ describe('Span', () => { test.each([ ['is included if transaction source is paremeterized route/url', 'route'], ['is included if transaction source is a custom name', 'custom'], - ])('%s', (_: string, source) => { + ] as const)('%s', (_, source) => { const transaction = new Transaction( { name: 'tx', - metadata: { - ...(source && { source: source as TransactionSource }), + attributes: { + ...(source && { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source }), }, }, hub, diff --git a/packages/tracing/test/transaction.test.ts b/packages/tracing/test/transaction.test.ts index f9e950dd9cb9..ab7cc427d3dd 100644 --- a/packages/tracing/test/transaction.test.ts +++ b/packages/tracing/test/transaction.test.ts @@ -16,17 +16,20 @@ describe('`Transaction` class', () => { describe('transaction name source', () => { it('sets source in constructor if provided', () => { - const transaction = new Transaction({ name: 'dogpark', metadata: { source: 'route' } }); + const transaction = new Transaction({ + name: 'dogpark', + attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route' }, + }); expect(transaction.name).toEqual('dogpark'); - expect(transaction.metadata.source).toEqual('route'); + expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route'); }); it("sets source to be `'custom'` in constructor if not provided", () => { const transaction = new Transaction({ name: 'dogpark' }); expect(transaction.name).toEqual('dogpark'); - expect(transaction.metadata.source).toBe('custom'); + expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('custom'); }); it("sets source to `'custom'` when assigning to `name` property", () => { @@ -34,7 +37,7 @@ describe('`Transaction` class', () => { transaction.name = 'ballpit'; expect(transaction.name).toEqual('ballpit'); - expect(transaction.metadata.source).toEqual('custom'); + expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('custom'); }); it('sets instrumenter to be `sentry` in constructor if not provided', () => { @@ -55,7 +58,7 @@ describe('`Transaction` class', () => { transaction.setName('ballpit'); expect(transaction.name).toEqual('ballpit'); - expect(transaction.metadata.source).toEqual('custom'); + expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('custom'); }); it('uses given `source` value', () => { @@ -63,7 +66,7 @@ describe('`Transaction` class', () => { transaction.setName('ballpit', 'route'); expect(transaction.name).toEqual('ballpit'); - expect(transaction.metadata.source).toEqual('route'); + expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route'); }); }); @@ -74,7 +77,7 @@ describe('`Transaction` class', () => { transaction.updateName('ballpit'); expect(transaction.name).toEqual('ballpit'); - expect(transaction.metadata.source).toEqual('route'); + expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route'); }); }); }); From 5eb1406c5664bf12e4056159250b7d24786fbb2f Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 15 Feb 2024 15:46:19 +0000 Subject: [PATCH 09/44] Tests --- .../test/custom/transaction.test.ts | 2 -- .../test/integration/scope.test.ts | 1 + .../test/integration/transactions.test.ts | 3 +++ packages/sveltekit/test/client/load.test.ts | 10 +++------- packages/sveltekit/test/server/handle.test.ts | 6 +++--- packages/sveltekit/test/server/load.test.ts | 20 +++++++------------ packages/tracing/test/hub.test.ts | 4 ++-- packages/tracing/test/span.test.ts | 4 ++++ packages/tracing/test/transaction.test.ts | 2 ++ 9 files changed, 25 insertions(+), 27 deletions(-) diff --git a/packages/opentelemetry/test/custom/transaction.test.ts b/packages/opentelemetry/test/custom/transaction.test.ts index ae07939981cc..f56350abeb8e 100644 --- a/packages/opentelemetry/test/custom/transaction.test.ts +++ b/packages/opentelemetry/test/custom/transaction.test.ts @@ -24,7 +24,6 @@ describe('startTranscation', () => { expect(transaction.spanRecorder?.spans).toHaveLength(1); // eslint-disable-next-line deprecation/deprecation expect(transaction.metadata).toEqual({ - source: 'custom', spanMetadata: {}, }); @@ -55,7 +54,6 @@ describe('startTranscation', () => { expect(transaction).toBeInstanceOf(Transaction); // eslint-disable-next-line deprecation/deprecation expect(transaction.metadata).toEqual({ - source: 'custom', spanMetadata: {}, }); diff --git a/packages/opentelemetry/test/integration/scope.test.ts b/packages/opentelemetry/test/integration/scope.test.ts index cc4def42ddbc..594fa1bcf9ae 100644 --- a/packages/opentelemetry/test/integration/scope.test.ts +++ b/packages/opentelemetry/test/integration/scope.test.ts @@ -98,6 +98,7 @@ describe('Integration | Scope', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, span_id: spanId, status: 'ok', diff --git a/packages/opentelemetry/test/integration/transactions.test.ts b/packages/opentelemetry/test/integration/transactions.test.ts index 1a7c6a14c659..4218657f9cd2 100644 --- a/packages/opentelemetry/test/integration/transactions.test.ts +++ b/packages/opentelemetry/test/integration/transactions.test.ts @@ -88,6 +88,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op', 'sentry.origin': 'auto.test', + 'sentry.source': 'custom', }, op: 'test op', span_id: expect.any(String), @@ -252,6 +253,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op', 'sentry.origin': 'auto.test', + 'sentry.source': 'custom', }, op: 'test op', span_id: expect.any(String), @@ -379,6 +381,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op', 'sentry.origin': 'auto.test', + 'sentry.source': 'custom', }, op: 'test op', span_id: expect.any(String), diff --git a/packages/sveltekit/test/client/load.test.ts b/packages/sveltekit/test/client/load.test.ts index ca7c1d625224..3c625865cf1c 100644 --- a/packages/sveltekit/test/client/load.test.ts +++ b/packages/sveltekit/test/client/load.test.ts @@ -3,7 +3,7 @@ import type { Load } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit'; import { vi } from 'vitest'; -import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core'; +import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; import { wrapLoadWithSentry } from '../../src/client/load'; const mockCaptureException = vi.spyOn(SentrySvelte, 'captureException').mockImplementation(() => 'xx'); @@ -109,13 +109,11 @@ describe('wrapLoadWithSentry', () => { { attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.sveltekit', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', }, op: 'function.sveltekit.load', name: '/users/[id]', status: 'ok', - metadata: { - source: 'route', - }, }, expect.any(Function), ); @@ -139,13 +137,11 @@ describe('wrapLoadWithSentry', () => { { attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.sveltekit', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', }, op: 'function.sveltekit.load', name: '/users/123', status: 'ok', - metadata: { - source: 'url', - }, }, expect.any(Function), ); diff --git a/packages/sveltekit/test/server/handle.test.ts b/packages/sveltekit/test/server/handle.test.ts index a90c70964a03..2de92846bbd5 100644 --- a/packages/sveltekit/test/server/handle.test.ts +++ b/packages/sveltekit/test/server/handle.test.ts @@ -1,4 +1,4 @@ -import { Hub, addTracingExtensions, makeMain } from '@sentry/core'; +import { Hub, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, addTracingExtensions, makeMain } from '@sentry/core'; import { NodeClient } from '@sentry/node'; import * as SentryNode from '@sentry/node'; import type { Transaction } from '@sentry/types'; @@ -136,7 +136,7 @@ describe('handleSentry', () => { expect(ref.name).toEqual('GET /users/[id]'); expect(ref.op).toEqual('http.server'); expect(ref.status).toEqual(isError ? 'internal_error' : 'ok'); - expect(ref.metadata.source).toEqual('route'); + expect(ref.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route'); expect(ref.endTimestamp).toBeDefined(); expect(ref.spanRecorder.spans).toHaveLength(1); @@ -172,7 +172,7 @@ describe('handleSentry', () => { expect(ref.name).toEqual('GET /users/[id]'); expect(ref.op).toEqual('http.server'); expect(ref.status).toEqual(isError ? 'internal_error' : 'ok'); - expect(ref.metadata.source).toEqual('route'); + expect(ref.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route'); expect(ref.endTimestamp).toBeDefined(); diff --git a/packages/sveltekit/test/server/load.test.ts b/packages/sveltekit/test/server/load.test.ts index 388541a8d884..f047c6074064 100644 --- a/packages/sveltekit/test/server/load.test.ts +++ b/packages/sveltekit/test/server/load.test.ts @@ -1,4 +1,4 @@ -import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, addTracingExtensions } from '@sentry/core'; +import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, addTracingExtensions } from '@sentry/core'; import * as SentryNode from '@sentry/node'; import type { Load, ServerLoad } from '@sveltejs/kit'; import { error, redirect } from '@sveltejs/kit'; @@ -199,13 +199,11 @@ describe('wrapLoadWithSentry calls trace', () => { { attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.sveltekit', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', }, op: 'function.sveltekit.load', name: '/users/[id]', status: 'ok', - metadata: { - source: 'route', - }, }, expect.any(Function), ); @@ -220,13 +218,11 @@ describe('wrapLoadWithSentry calls trace', () => { { attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.sveltekit', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', }, op: 'function.sveltekit.load', name: '/users/123', status: 'ok', - metadata: { - source: 'url', - }, }, expect.any(Function), ); @@ -256,6 +252,7 @@ describe('wrapServerLoadWithSentry calls trace', () => { { attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.sveltekit', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', }, op: 'function.sveltekit.server.load', name: '/users/[id]', @@ -275,7 +272,6 @@ describe('wrapServerLoadWithSentry calls trace', () => { trace_id: '1234567890abcdef1234567890abcdef', transaction: 'dogpark', }, - source: 'route', }, }, expect.any(Function), @@ -291,6 +287,7 @@ describe('wrapServerLoadWithSentry calls trace', () => { { attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.sveltekit', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', }, op: 'function.sveltekit.server.load', name: '/users/[id]', @@ -298,9 +295,6 @@ describe('wrapServerLoadWithSentry calls trace', () => { data: { 'http.method': 'GET', }, - metadata: { - source: 'route', - }, }, expect.any(Function), ); @@ -315,6 +309,7 @@ describe('wrapServerLoadWithSentry calls trace', () => { { attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.sveltekit', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route', }, op: 'function.sveltekit.server.load', name: '/users/[id]', @@ -327,7 +322,6 @@ describe('wrapServerLoadWithSentry calls trace', () => { }, metadata: { dynamicSamplingContext: {}, - source: 'route', }, }, expect.any(Function), @@ -346,6 +340,7 @@ describe('wrapServerLoadWithSentry calls trace', () => { { attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.sveltekit', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', }, op: 'function.sveltekit.server.load', name: '/users/123', @@ -365,7 +360,6 @@ describe('wrapServerLoadWithSentry calls trace', () => { trace_id: '1234567890abcdef1234567890abcdef', transaction: 'dogpark', }, - source: 'url', }, }, expect.any(Function), diff --git a/packages/tracing/test/hub.test.ts b/packages/tracing/test/hub.test.ts index b12966e6b3dc..5a96cd3f607c 100644 --- a/packages/tracing/test/hub.test.ts +++ b/packages/tracing/test/hub.test.ts @@ -305,8 +305,8 @@ describe('Hub', () => { makeMain(hub); hub.startTransaction({ name: 'dogpark', parentSampled: true }); - // length 2 because origin and op are set as attributes on span initialization - expect(Transaction.prototype.setAttribute).toHaveBeenCalledTimes(2); + // length 3 because origin, source and op are set as attributes on span initialization + expect(Transaction.prototype.setAttribute).toHaveBeenCalledTimes(3); }); it('should record sampling method and rate when sampling decision comes from traceSampleRate', () => { diff --git a/packages/tracing/test/span.test.ts b/packages/tracing/test/span.test.ts index 5634ca243d9b..3ea5d43c937f 100644 --- a/packages/tracing/test/span.test.ts +++ b/packages/tracing/test/span.test.ts @@ -176,6 +176,7 @@ describe('Span', () => { origin: 'manual', data: { 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, }); }); @@ -480,6 +481,7 @@ describe('Span', () => { trace_id: 'c', data: { 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, origin: 'manual', }); @@ -508,6 +510,7 @@ describe('Span', () => { data: { 'sentry.op': 'op', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, }); }); @@ -581,6 +584,7 @@ describe('Span', () => { data1: 'bar', 'sentry.op': 'op', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); }); }); diff --git a/packages/tracing/test/transaction.test.ts b/packages/tracing/test/transaction.test.ts index ab7cc427d3dd..55d162becc21 100644 --- a/packages/tracing/test/transaction.test.ts +++ b/packages/tracing/test/transaction.test.ts @@ -173,6 +173,7 @@ describe('`Transaction` class', () => { data: { [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1, [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'manual', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom', }, span_id: transaction.spanId, trace_id: transaction.traceId, @@ -204,6 +205,7 @@ describe('`Transaction` class', () => { data: { [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1, [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'manual', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom', }, span_id: transaction.spanId, trace_id: transaction.traceId, From 8771b70faf178bef63851ba3f746f895da5397c4 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 15 Feb 2024 16:05:44 +0000 Subject: [PATCH 10/44] tests --- packages/ember/addon/index.ts | 16 +++++++++++++--- .../integration/test/client/tracingFetch.test.ts | 1 + .../test/integration/scope.test.ts | 2 +- .../test/integration/transactions.test.ts | 2 ++ .../test/integration/transactions.test.ts | 6 +++--- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/ember/addon/index.ts b/packages/ember/addon/index.ts index f403df54284e..5f5cbf054666 100644 --- a/packages/ember/addon/index.ts +++ b/packages/ember/addon/index.ts @@ -9,6 +9,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, applySdkMetadata } from '@sentry/core import { GLOBAL_OBJ } from '@sentry/utils'; import Ember from 'ember'; +import type { TransactionSource } from '@sentry/types'; import type { EmberSentryConfig, GlobalConfig, OwnConfig } from './types'; function _getSentryInitConfig(): EmberSentryConfig['sentry'] { @@ -68,11 +69,12 @@ export const instrumentRoutePerformance = (BaseRoute description: string, fn: X, args: Parameters, + source: TransactionSource, ): Promise> => { return startSpan( { attributes: { - [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'ember', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source, }, op, name: description, @@ -94,15 +96,22 @@ export const instrumentRoutePerformance = (BaseRoute this.fullRouteName, super.beforeModel.bind(this), args, + 'custom', ); } public async model(...args: unknown[]): Promise { - return instrumentFunction('ui.ember.route.model', this.fullRouteName, super.model.bind(this), args); + return instrumentFunction('ui.ember.route.model', this.fullRouteName, super.model.bind(this), args, 'custom'); } public afterModel(...args: unknown[]): void | Promise { - return instrumentFunction('ui.ember.route.after_model', this.fullRouteName, super.afterModel.bind(this), args); + return instrumentFunction( + 'ui.ember.route.after_model', + this.fullRouteName, + super.afterModel.bind(this), + args, + 'custom', + ); } public setupController(...args: unknown[]): void | Promise { @@ -111,6 +120,7 @@ export const instrumentRoutePerformance = (BaseRoute this.fullRouteName, super.setupController.bind(this), args, + 'custom', ); } }, diff --git a/packages/nextjs/test/integration/test/client/tracingFetch.test.ts b/packages/nextjs/test/integration/test/client/tracingFetch.test.ts index 8517b4ab0fce..9b9d01774919 100644 --- a/packages/nextjs/test/integration/test/client/tracingFetch.test.ts +++ b/packages/nextjs/test/integration/test/client/tracingFetch.test.ts @@ -38,6 +38,7 @@ test('should correctly instrument `fetch` for performance tracing', async ({ pag 'http.response.status_code': 200, 'sentry.op': 'http.client', 'sentry.origin': 'auto.http.browser', + 'sentry.source': 'custom', }, description: 'GET http://example.com', op: 'http.client', diff --git a/packages/node-experimental/test/integration/scope.test.ts b/packages/node-experimental/test/integration/scope.test.ts index e800de4d41d0..2187f2020dde 100644 --- a/packages/node-experimental/test/integration/scope.test.ts +++ b/packages/node-experimental/test/integration/scope.test.ts @@ -88,7 +88,7 @@ describe('Integration | Scope', () => { expect.objectContaining({ contexts: expect.objectContaining({ trace: { - data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual' }, + data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', 'sentry.source': 'task' }, span_id: spanId, status: 'ok', trace_id: traceId, diff --git a/packages/node-experimental/test/integration/transactions.test.ts b/packages/node-experimental/test/integration/transactions.test.ts index 23edcca3c579..80187c735cbd 100644 --- a/packages/node-experimental/test/integration/transactions.test.ts +++ b/packages/node-experimental/test/integration/transactions.test.ts @@ -422,6 +422,7 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, span_id: expect.any(String), status: 'ok', @@ -552,6 +553,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op', 'sentry.origin': 'auto.test', + 'sentry.source': 'task', }, op: 'test op', span_id: expect.any(String), diff --git a/packages/opentelemetry/test/integration/transactions.test.ts b/packages/opentelemetry/test/integration/transactions.test.ts index 4218657f9cd2..d5af81663657 100644 --- a/packages/opentelemetry/test/integration/transactions.test.ts +++ b/packages/opentelemetry/test/integration/transactions.test.ts @@ -73,6 +73,7 @@ describe('Integration | Transactions', () => { otel: { attributes: { 'test.outer': 'test value', + 'sentry.source': 'custom', }, resource: { 'service.name': 'opentelemetry-test', @@ -109,7 +110,6 @@ describe('Integration | Transactions', () => { transaction: 'test name', }), sampleRate: 1, - source: 'task', spanMetadata: expect.any(Object), requestPath: 'test-path', }), @@ -253,7 +253,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op', 'sentry.origin': 'auto.test', - 'sentry.source': 'custom', + 'sentry.source': 'task', }, op: 'test op', span_id: expect.any(String), @@ -381,7 +381,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op', 'sentry.origin': 'auto.test', - 'sentry.source': 'custom', + 'sentry.source': 'task', }, op: 'test op', span_id: expect.any(String), From a657600bee4fd73509770ba70021449fbb67b76b Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 15 Feb 2024 16:21:22 +0000 Subject: [PATCH 11/44] gimmemytimeback --- .../test/integration/transactions.test.ts | 1 + .../opentelemetry/test/integration/transactions.test.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/node-experimental/test/integration/transactions.test.ts b/packages/node-experimental/test/integration/transactions.test.ts index 80187c735cbd..d1354b95678b 100644 --- a/packages/node-experimental/test/integration/transactions.test.ts +++ b/packages/node-experimental/test/integration/transactions.test.ts @@ -466,6 +466,7 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, span_id: expect.any(String), status: 'ok', diff --git a/packages/opentelemetry/test/integration/transactions.test.ts b/packages/opentelemetry/test/integration/transactions.test.ts index d5af81663657..b19dea8b0a36 100644 --- a/packages/opentelemetry/test/integration/transactions.test.ts +++ b/packages/opentelemetry/test/integration/transactions.test.ts @@ -73,7 +73,6 @@ describe('Integration | Transactions', () => { otel: { attributes: { 'test.outer': 'test value', - 'sentry.source': 'custom', }, resource: { 'service.name': 'opentelemetry-test', @@ -89,7 +88,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op', 'sentry.origin': 'auto.test', - 'sentry.source': 'custom', + 'sentry.source': 'task', }, op: 'test op', span_id: expect.any(String), @@ -149,6 +148,7 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, description: 'inner span 1', origin: 'manual', @@ -164,6 +164,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'test.inner': 'test value', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, description: 'inner span 2', origin: 'manual', @@ -300,6 +301,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op b', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, op: 'test op b', span_id: expect.any(String), @@ -423,6 +425,7 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, description: 'inner span 1', origin: 'manual', @@ -437,6 +440,7 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, description: 'inner span 2', origin: 'manual', From 9f44cc0b1a5e86d5cf71a2e1b598eac865586793 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 09:23:09 +0000 Subject: [PATCH 12/44] otel tests --- .../test/integration/scope.test.ts | 2 +- .../test/integration/transactions.test.ts | 8 +++++++- .../opentelemetry-node/test/spanprocessor.test.ts | 13 +++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/node-experimental/test/integration/scope.test.ts b/packages/node-experimental/test/integration/scope.test.ts index 2187f2020dde..5ea0c9194356 100644 --- a/packages/node-experimental/test/integration/scope.test.ts +++ b/packages/node-experimental/test/integration/scope.test.ts @@ -88,7 +88,7 @@ describe('Integration | Scope', () => { expect.objectContaining({ contexts: expect.objectContaining({ trace: { - data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', 'sentry.source': 'task' }, + data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', 'sentry.source': 'custom' }, span_id: spanId, status: 'ok', trace_id: traceId, diff --git a/packages/node-experimental/test/integration/transactions.test.ts b/packages/node-experimental/test/integration/transactions.test.ts index d1354b95678b..fbe539616df2 100644 --- a/packages/node-experimental/test/integration/transactions.test.ts +++ b/packages/node-experimental/test/integration/transactions.test.ts @@ -90,6 +90,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op', 'sentry.origin': 'auto.test', + 'sentry.source': 'task', }, op: 'test op', span_id: expect.any(String), @@ -111,7 +112,6 @@ describe('Integration | Transactions', () => { transaction: 'test name', }), sampleRate: 1, - source: 'task', spanMetadata: expect.any(Object), requestPath: 'test-path', }), @@ -152,6 +152,7 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, description: 'inner span 1', origin: 'manual', @@ -167,6 +168,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'test.inner': 'test value', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, description: 'inner span 2', origin: 'manual', @@ -264,6 +266,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op', 'sentry.origin': 'auto.test', + 'sentry.source': 'task', }, op: 'test op', span_id: expect.any(String), @@ -310,6 +313,7 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'sentry.op': 'test op b', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, op: 'test op b', span_id: expect.any(String), @@ -596,6 +600,7 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, description: 'inner span 1', origin: 'manual', @@ -610,6 +615,7 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, description: 'inner span 2', origin: 'manual', diff --git a/packages/opentelemetry-node/test/spanprocessor.test.ts b/packages/opentelemetry-node/test/spanprocessor.test.ts index 768c12369130..455a13d635b4 100644 --- a/packages/opentelemetry-node/test/spanprocessor.test.ts +++ b/packages/opentelemetry-node/test/spanprocessor.test.ts @@ -5,6 +5,7 @@ import type { Span as OtelSpan } from '@opentelemetry/sdk-trace-base'; import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; import { SemanticAttributes, SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; import type { SpanStatusType } from '@sentry/core'; +import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; import { captureException, getCurrentScope, setCurrentClient } from '@sentry/core'; import { Span as SentrySpan, Transaction, addTracingExtensions, createTransport, spanToJSON } from '@sentry/core'; import { NodeClient } from '@sentry/node'; @@ -336,7 +337,7 @@ describe('SentrySpanProcessor', () => { const sentrySpan = getSpanForOtelSpan(child); // origin is set by default to 'manual' - expect(spanToJSON(sentrySpan!).data).toEqual({ 'sentry.origin': 'manual' }); + expect(spanToJSON(sentrySpan!).data).toEqual({ 'sentry.origin': 'manual', 'sentry.source': 'custom' }); child.end(); @@ -347,6 +348,7 @@ describe('SentrySpanProcessor', () => { 'test-attribute-3': 0, 'test-attribute-4': false, 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); }); @@ -586,6 +588,7 @@ describe('SentrySpanProcessor', () => { url: 'http://example.com/my/route/123', 'sentry.op': 'http', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); parentOtelSpan.end(); @@ -617,6 +620,7 @@ describe('SentrySpanProcessor', () => { url: 'http://example.com/my/route/123', 'sentry.op': 'http', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); expect(op).toBe('http'); @@ -651,6 +655,7 @@ describe('SentrySpanProcessor', () => { 'http.fragment': '#myHash', 'sentry.op': 'http', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }); expect(op).toBe('http'); @@ -671,7 +676,7 @@ describe('SentrySpanProcessor', () => { otelSpan.end(); // eslint-disable-next-line deprecation/deprecation - expect(sentrySpan?.transaction?.metadata.source).toBe('url'); + expect(sentrySpan?.transaction?.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('url'); }); }); @@ -687,7 +692,7 @@ describe('SentrySpanProcessor', () => { otelSpan.end(); // eslint-disable-next-line deprecation/deprecation - expect(sentrySpan?.transaction?.metadata.source).toBe('route'); + expect(sentrySpan?.transaction?.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('route'); }); }); @@ -703,7 +708,7 @@ describe('SentrySpanProcessor', () => { otelSpan.end(); // eslint-disable-next-line deprecation/deprecation - expect(sentrySpan?.transaction?.metadata.source).toBe('route'); + expect(sentrySpan?.transaction?.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('route'); }); }); From 317190f7bcb7cacd7a468211d6661bdc2541e24f Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 10:33:40 +0000 Subject: [PATCH 13/44] fix --- .../suites/express/multiple-routers/complex-router/server.ts | 3 +-- .../suites/tracing-experimental/apollo-graphql/test.ts | 3 +++ packages/node/src/handlers.ts | 2 +- packages/tracing-internal/src/node/integrations/express.ts | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dev-packages/node-integration-tests/suites/express/multiple-routers/complex-router/server.ts b/dev-packages/node-integration-tests/suites/express/multiple-routers/complex-router/server.ts index 8df1b9c3d988..08b3a8f024cc 100644 --- a/dev-packages/node-integration-tests/suites/express/multiple-routers/complex-router/server.ts +++ b/dev-packages/node-integration-tests/suites/express/multiple-routers/complex-router/server.ts @@ -1,6 +1,5 @@ import { loggingTransport, startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests'; import * as Sentry from '@sentry/node'; -import * as Tracing from '@sentry/tracing'; import express from 'express'; const app = express(); @@ -9,7 +8,7 @@ Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', release: '1.0', // eslint-disable-next-line deprecation/deprecation - integrations: [new Sentry.Integrations.Http({ tracing: true }), new Tracing.Integrations.Express({ app })], + integrations: [new Sentry.Integrations.Http({ tracing: true }), new Sentry.Integrations.Express({ app })], tracesSampleRate: 1.0, transport: loggingTransport, }); diff --git a/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts b/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts index ad32799a5e79..77a64302447a 100644 --- a/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts @@ -11,6 +11,7 @@ describe('GraphQL/Apollo Tests', () => { 'graphql.source': '{hello}', 'otel.kind': 'INTERNAL', 'sentry.origin': 'auto.graphql.otel.graphql', + 'sentry.source': 'custom', }, description: 'query', status: 'ok', @@ -24,6 +25,7 @@ describe('GraphQL/Apollo Tests', () => { 'graphql.source': 'hello', 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', + 'sentry.source': 'custom', }, description: 'graphql.resolve hello', status: 'ok', @@ -46,6 +48,7 @@ describe('GraphQL/Apollo Tests', () => { 'graphql.source': 'mutation Mutation($email: String) {\n login(email: $email)\n}', 'otel.kind': 'INTERNAL', 'sentry.origin': 'auto.graphql.otel.graphql', + 'sentry.source': 'custom', }, description: 'mutation Mutation', status: 'ok', diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index b1140d0d9c28..220d2818028a 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -74,7 +74,7 @@ export function tracingHandler(): ( op: 'http.server', origin: 'auto.http.node.tracingHandler', ...ctx, - data: { + attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source, }, metadata: { diff --git a/packages/tracing-internal/src/node/integrations/express.ts b/packages/tracing-internal/src/node/integrations/express.ts index 7dabd973252e..617a7d981cf4 100644 --- a/packages/tracing-internal/src/node/integrations/express.ts +++ b/packages/tracing-internal/src/node/integrations/express.ts @@ -376,7 +376,7 @@ function instrumentRouter(appOrRouter: ExpressRouter): void { const transaction = res.__sentry_transaction; const attributes = (transaction && spanToJSON(transaction).data) || {}; - if (transaction && attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] !== 'custom') { + if (transaction && attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === 'url') { // If the request URL is '/' or empty, the reconstructed route will be empty. // Therefore, we fall back to setting the final route to '/' in this case. const finalRoute = req._reconstructedRoute || '/'; From 065dcfb6b3bc91b88afee9e94c01350172c3b66e Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 10:40:10 +0000 Subject: [PATCH 14/44] source not on all spans but on txns --- packages/core/src/tracing/span.ts | 1 - packages/core/src/tracing/transaction.ts | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/src/tracing/span.ts b/packages/core/src/tracing/span.ts index eb6b85c1aeb1..9a9e520fab3b 100644 --- a/packages/core/src/tracing/span.ts +++ b/packages/core/src/tracing/span.ts @@ -144,7 +144,6 @@ export class Span implements SpanInterface { this.setAttributes({ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: spanContext.origin || 'manual', [SEMANTIC_ATTRIBUTE_SENTRY_OP]: spanContext.op, - [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom', ...spanContext.attributes, }); diff --git a/packages/core/src/tracing/transaction.ts b/packages/core/src/tracing/transaction.ts index f699ac3557f3..170236117312 100644 --- a/packages/core/src/tracing/transaction.ts +++ b/packages/core/src/tracing/transaction.ts @@ -69,6 +69,11 @@ export class Transaction extends SpanClass implements TransactionInterface { this._trimEnd = transactionContext.trimEnd; + this._attributes = { + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom', + ...this._attributes, + }; + // this is because transactions are also spans, and spans have a transaction pointer // TODO (v8): Replace this with another way to set the root span // eslint-disable-next-line deprecation/deprecation From a2d246448ba427baae717a854345c2363f47331e Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 10:45:13 +0000 Subject: [PATCH 15/44] tests --- packages/tracing/test/hub.test.ts | 4 ++-- packages/tracing/test/span.test.ts | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/tracing/test/hub.test.ts b/packages/tracing/test/hub.test.ts index 5a96cd3f607c..b12966e6b3dc 100644 --- a/packages/tracing/test/hub.test.ts +++ b/packages/tracing/test/hub.test.ts @@ -305,8 +305,8 @@ describe('Hub', () => { makeMain(hub); hub.startTransaction({ name: 'dogpark', parentSampled: true }); - // length 3 because origin, source and op are set as attributes on span initialization - expect(Transaction.prototype.setAttribute).toHaveBeenCalledTimes(3); + // length 2 because origin and op are set as attributes on span initialization + expect(Transaction.prototype.setAttribute).toHaveBeenCalledTimes(2); }); it('should record sampling method and rate when sampling decision comes from traceSampleRate', () => { diff --git a/packages/tracing/test/span.test.ts b/packages/tracing/test/span.test.ts index 7ac884fc842e..c51a069e9c51 100644 --- a/packages/tracing/test/span.test.ts +++ b/packages/tracing/test/span.test.ts @@ -192,7 +192,6 @@ describe('Span', () => { origin: 'manual', data: { 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, }); }); @@ -509,7 +508,6 @@ describe('Span', () => { trace_id: 'c', data: { 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, origin: 'manual', }); @@ -538,7 +536,6 @@ describe('Span', () => { data: { 'sentry.op': 'op', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, }); }); @@ -612,7 +609,6 @@ describe('Span', () => { data1: 'bar', 'sentry.op': 'op', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); }); }); From c7122a8dff406e3036c0ab199b6a4520468a9b47 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 10:53:30 +0000 Subject: [PATCH 16/44] test --- .../nextjs/test/integration/test/client/tracingFetch.test.ts | 1 - .../node-experimental/test/integration/transactions.test.ts | 4 ---- packages/opentelemetry/test/integration/transactions.test.ts | 4 ---- 3 files changed, 9 deletions(-) diff --git a/packages/nextjs/test/integration/test/client/tracingFetch.test.ts b/packages/nextjs/test/integration/test/client/tracingFetch.test.ts index 9b9d01774919..8517b4ab0fce 100644 --- a/packages/nextjs/test/integration/test/client/tracingFetch.test.ts +++ b/packages/nextjs/test/integration/test/client/tracingFetch.test.ts @@ -38,7 +38,6 @@ test('should correctly instrument `fetch` for performance tracing', async ({ pag 'http.response.status_code': 200, 'sentry.op': 'http.client', 'sentry.origin': 'auto.http.browser', - 'sentry.source': 'custom', }, description: 'GET http://example.com', op: 'http.client', diff --git a/packages/node-experimental/test/integration/transactions.test.ts b/packages/node-experimental/test/integration/transactions.test.ts index fbe539616df2..21a411191634 100644 --- a/packages/node-experimental/test/integration/transactions.test.ts +++ b/packages/node-experimental/test/integration/transactions.test.ts @@ -152,7 +152,6 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, description: 'inner span 1', origin: 'manual', @@ -168,7 +167,6 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'test.inner': 'test value', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, description: 'inner span 2', origin: 'manual', @@ -600,7 +598,6 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, description: 'inner span 1', origin: 'manual', @@ -615,7 +612,6 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, description: 'inner span 2', origin: 'manual', diff --git a/packages/opentelemetry/test/integration/transactions.test.ts b/packages/opentelemetry/test/integration/transactions.test.ts index b19dea8b0a36..08a62e93361d 100644 --- a/packages/opentelemetry/test/integration/transactions.test.ts +++ b/packages/opentelemetry/test/integration/transactions.test.ts @@ -148,7 +148,6 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, description: 'inner span 1', origin: 'manual', @@ -164,7 +163,6 @@ describe('Integration | Transactions', () => { 'otel.kind': 'INTERNAL', 'test.inner': 'test value', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, description: 'inner span 2', origin: 'manual', @@ -425,7 +423,6 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, description: 'inner span 1', origin: 'manual', @@ -440,7 +437,6 @@ describe('Integration | Transactions', () => { data: { 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, description: 'inner span 2', origin: 'manual', From d8bfeb893f3e1dbcfbb86091d655975075c33ced Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 11:15:41 +0000 Subject: [PATCH 17/44] . --- packages/core/test/lib/tracing/span.test.ts | 21 ++++------- .../core/test/lib/utils/spanUtils.test.ts | 2 -- .../deno/test/__snapshots__/mod.test.ts.snap | 35 ------------------- packages/deno/test/normalize.ts | 4 +-- packages/sveltekit/test/server/load.test.ts | 1 + 5 files changed, 9 insertions(+), 54 deletions(-) diff --git a/packages/core/test/lib/tracing/span.test.ts b/packages/core/test/lib/tracing/span.test.ts index 8aac2340b3e6..b3c08987d4b2 100644 --- a/packages/core/test/lib/tracing/span.test.ts +++ b/packages/core/test/lib/tracing/span.test.ts @@ -86,7 +86,6 @@ describe('span', () => { arrayWithUndefined: [1, undefined, 2], // origin is set by default to 'manual' in the Span constructor 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); }); @@ -95,12 +94,12 @@ describe('span', () => { span.setAttribute('str', 'bar'); - // length 3 because `sentry.origin` and `sentry.source` are always set by default - expect(Object.keys(span['_attributes']).length).toEqual(3); + // length 2 because `sentry.origin` is always set by default + expect(Object.keys(span['_attributes']).length).toEqual(2); span.setAttribute('str', undefined); - expect(Object.keys(span['_attributes']).length).toEqual(2); + expect(Object.keys(span['_attributes']).length).toEqual(1); }); it('disallows invalid attribute types', () => { @@ -126,7 +125,6 @@ describe('span', () => { expect(initialAttributes).toEqual({ // origin is set by default to 'manual' in the Span constructor 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); const newAttributes = { @@ -154,7 +152,6 @@ describe('span', () => { boolArray: [true, false], arrayWithUndefined: [1, undefined, 2], 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); expect(span['_attributes']).not.toBe(newAttributes); @@ -175,7 +172,6 @@ describe('span', () => { boolArray: [true, false], arrayWithUndefined: [1, undefined, 2], 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); }); @@ -184,12 +180,12 @@ describe('span', () => { span.setAttribute('str', 'bar'); - // length 3 because `sentry.origin` and `sentry.source` are always set by default - expect(Object.keys(span['_attributes']).length).toEqual(3); + // length 2 because `sentry.origin` is always set by default + expect(Object.keys(span['_attributes']).length).toEqual(2); span.setAttributes({ str: undefined }); - expect(Object.keys(span['_attributes']).length).toEqual(2); + expect(Object.keys(span['_attributes']).length).toEqual(1); }); }); @@ -291,7 +287,6 @@ describe('span', () => { expect(span['_getData']()).toEqual({ // origin is set by default to 'manual' in the Span constructor 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); }); @@ -304,13 +299,11 @@ describe('span', () => { foo: 'bar', // origin is set by default to 'manual' in the Span constructor 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); expect(span['_getData']()).toStrictEqual({ // eslint-disable-next-line deprecation/deprecation ...span.data, 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); }); @@ -322,7 +315,6 @@ describe('span', () => { foo: 'bar', // origin is set by default to 'manual' in the Span constructor 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); // eslint-disable-next-line deprecation/deprecation expect(span['_getData']()).toBe(span.attributes); @@ -343,7 +335,6 @@ describe('span', () => { baz: 'baz', // origin is set by default to 'manual' in the Span constructor 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); // eslint-disable-next-line deprecation/deprecation expect(span['_getData']()).not.toBe(span.attributes); diff --git a/packages/core/test/lib/utils/spanUtils.test.ts b/packages/core/test/lib/utils/spanUtils.test.ts index 3f52daa39160..0afb59530623 100644 --- a/packages/core/test/lib/utils/spanUtils.test.ts +++ b/packages/core/test/lib/utils/spanUtils.test.ts @@ -57,7 +57,6 @@ describe('spanToJSON', () => { start_timestamp: span['_startTime'], data: { 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, }); }); @@ -94,7 +93,6 @@ describe('spanToJSON', () => { data: { 'sentry.op': 'test op', 'sentry.origin': 'auto', - 'sentry.source': 'custom', }, }); }); diff --git a/packages/deno/test/__snapshots__/mod.test.ts.snap b/packages/deno/test/__snapshots__/mod.test.ts.snap index d728072d38d6..417acf1e7639 100644 --- a/packages/deno/test/__snapshots__/mod.test.ts.snap +++ b/packages/deno/test/__snapshots__/mod.test.ts.snap @@ -41,41 +41,6 @@ snapshot[`captureException 1`] = ` }, stacktrace: { frames: [ - { - colno: 20, - filename: "ext:cli/40_testing.js", - function: "outerWrapped", - in_app: false, - lineno: 472, - }, - { - colno: 33, - filename: "ext:cli/40_testing.js", - function: "exitSanitizer", - in_app: false, - lineno: 458, - }, - { - colno: 31, - filename: "ext:cli/40_testing.js", - function: "resourceSanitizer", - in_app: false, - lineno: 410, - }, - { - colno: 33, - filename: "ext:cli/40_testing.js", - function: "asyncOpSanitizer", - in_app: false, - lineno: 177, - }, - { - colno: 11, - filename: "ext:cli/40_testing.js", - function: "innerWrapped", - in_app: false, - lineno: 526, - }, { colno: 27, context_line: " client.captureException(something());", diff --git a/packages/deno/test/normalize.ts b/packages/deno/test/normalize.ts index 64295932e00d..4dbbc8f3f6ec 100644 --- a/packages/deno/test/normalize.ts +++ b/packages/deno/test/normalize.ts @@ -152,9 +152,9 @@ function normalizeEvent(event: sentryTypes.Event): sentryTypes.Event { } if (event.exception?.values?.[0].stacktrace?.frames) { - // Exlcude Deno frames since these may change between versions + // Exclude Deno frames since these may change between versions event.exception.values[0].stacktrace.frames = event.exception.values[0].stacktrace.frames.filter( - frame => !frame.filename?.includes('deno:'), + frame => !frame.filename?.includes('deno:') && !frame.filename?.startsWith('ext:'), ); } diff --git a/packages/sveltekit/test/server/load.test.ts b/packages/sveltekit/test/server/load.test.ts index f047c6074064..790ded799106 100644 --- a/packages/sveltekit/test/server/load.test.ts +++ b/packages/sveltekit/test/server/load.test.ts @@ -292,6 +292,7 @@ describe('wrapServerLoadWithSentry calls trace', () => { op: 'function.sveltekit.server.load', name: '/users/[id]', status: 'ok', + metadata: {}, data: { 'http.method': 'GET', }, From c6918d0f5374dc845b2723be9bbcbd29e2ca7f60 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 11:16:29 +0000 Subject: [PATCH 18/44] . --- packages/core/src/tracing/span.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/core/src/tracing/span.ts b/packages/core/src/tracing/span.ts index 9a9e520fab3b..5ded23cc386d 100644 --- a/packages/core/src/tracing/span.ts +++ b/packages/core/src/tracing/span.ts @@ -17,11 +17,7 @@ import { dropUndefinedKeys, logger, timestampInSeconds, uuid4 } from '@sentry/ut import { DEBUG_BUILD } from '../debug-build'; import { getMetricSummaryJsonForSpan } from '../metrics/metric-summary'; -import { - SEMANTIC_ATTRIBUTE_SENTRY_OP, - SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, - SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, -} from '../semanticAttributes'; +import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes'; import { getRootSpan } from '../utils/getRootSpan'; import { TRACE_FLAG_NONE, From 2dbec1c47427cf9c4e290e731a89cc144636c89d Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 13:06:12 +0000 Subject: [PATCH 19/44] . --- packages/opentelemetry-node/test/spanprocessor.test.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/opentelemetry-node/test/spanprocessor.test.ts b/packages/opentelemetry-node/test/spanprocessor.test.ts index 0ad8def44ee4..e3d741c50f3c 100644 --- a/packages/opentelemetry-node/test/spanprocessor.test.ts +++ b/packages/opentelemetry-node/test/spanprocessor.test.ts @@ -348,7 +348,6 @@ describe('SentrySpanProcessor', () => { 'test-attribute-3': 0, 'test-attribute-4': false, 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); }); @@ -588,7 +587,6 @@ describe('SentrySpanProcessor', () => { url: 'http://example.com/my/route/123', 'sentry.op': 'http', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); parentOtelSpan.end(); @@ -620,7 +618,6 @@ describe('SentrySpanProcessor', () => { url: 'http://example.com/my/route/123', 'sentry.op': 'http', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); expect(op).toBe('http'); @@ -655,7 +652,6 @@ describe('SentrySpanProcessor', () => { 'http.fragment': '#myHash', 'sentry.op': 'http', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }); expect(op).toBe('http'); From c23c59eb184bed493bf54e0211595adc073f2451 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 13:37:25 +0000 Subject: [PATCH 20/44] =?UTF-8?q?=F0=9F=99=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../suites/tracing-experimental/apollo-graphql/test.ts | 2 -- packages/opentelemetry-node/test/spanprocessor.test.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts b/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts index 77a64302447a..13ee6b246743 100644 --- a/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts @@ -25,7 +25,6 @@ describe('GraphQL/Apollo Tests', () => { 'graphql.source': 'hello', 'otel.kind': 'INTERNAL', 'sentry.origin': 'manual', - 'sentry.source': 'custom', }, description: 'graphql.resolve hello', status: 'ok', @@ -48,7 +47,6 @@ describe('GraphQL/Apollo Tests', () => { 'graphql.source': 'mutation Mutation($email: String) {\n login(email: $email)\n}', 'otel.kind': 'INTERNAL', 'sentry.origin': 'auto.graphql.otel.graphql', - 'sentry.source': 'custom', }, description: 'mutation Mutation', status: 'ok', diff --git a/packages/opentelemetry-node/test/spanprocessor.test.ts b/packages/opentelemetry-node/test/spanprocessor.test.ts index e3d741c50f3c..b5e2a26fa4c2 100644 --- a/packages/opentelemetry-node/test/spanprocessor.test.ts +++ b/packages/opentelemetry-node/test/spanprocessor.test.ts @@ -337,7 +337,7 @@ describe('SentrySpanProcessor', () => { const sentrySpan = getSpanForOtelSpan(child); // origin is set by default to 'manual' - expect(spanToJSON(sentrySpan!).data).toEqual({ 'sentry.origin': 'manual', 'sentry.source': 'custom' }); + expect(spanToJSON(sentrySpan!).data).toEqual({ 'sentry.origin': 'manual' }); child.end(); From 392548a07f6e2f4795eb7d4f5adbc000c3c103bf Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 13:51:37 +0000 Subject: [PATCH 21/44] . --- .../node-experimental-fastify-app/tests/propagation.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dev-packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/propagation.test.ts b/dev-packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/propagation.test.ts index 9b83e882a739..cbb2c889edec 100644 --- a/dev-packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/propagation.test.ts +++ b/dev-packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/propagation.test.ts @@ -65,6 +65,7 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => { 'http.response.status_code': 200, 'sentry.op': 'http.server', 'sentry.origin': 'auto.http.otel.http', + 'sentry.source': 'route', }, op: 'http.server', span_id: expect.any(String), @@ -89,6 +90,7 @@ test('Propagates trace for outgoing http requests', async ({ baseURL }) => { 'http.response.status_code': 200, 'sentry.op': 'http.server', 'sentry.origin': 'auto.http.otel.http', + 'sentry.source': 'route', }, op: 'http.server', parent_span_id: outgoingHttpSpanId, @@ -162,6 +164,7 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => { 'http.response.status_code': 200, 'sentry.op': 'http.server', 'sentry.origin': 'auto.http.otel.http', + 'sentry.source': 'route', }, op: 'http.server', span_id: expect.any(String), @@ -186,6 +189,7 @@ test('Propagates trace for outgoing fetch requests', async ({ baseURL }) => { 'http.response.status_code': 200, 'sentry.op': 'http.server', 'sentry.origin': 'auto.http.otel.http', + 'sentry.source': 'route', }, op: 'http.server', parent_span_id: outgoingHttpSpanId, From 56601f164ff22d32481b509e236747250598abbc Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 14:05:25 +0000 Subject: [PATCH 22/44] . --- .../node-experimental-fastify-app/tests/transactions.test.ts | 1 + .../suites/tracing-experimental/apollo-graphql/test.ts | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/transactions.test.ts b/dev-packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/transactions.test.ts index d2ab9e3d664f..0429adca8623 100644 --- a/dev-packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/transactions.test.ts +++ b/dev-packages/e2e-tests/test-applications/node-experimental-fastify-app/tests/transactions.test.ts @@ -30,6 +30,7 @@ test('Sends an API route transaction', async ({ baseURL }) => { 'http.response.status_code': 200, 'sentry.op': 'http.server', 'sentry.origin': 'auto.http.otel.http', + 'sentry.source': 'route', }, op: 'http.server', span_id: expect.any(String), diff --git a/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts b/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts index 13ee6b246743..ad32799a5e79 100644 --- a/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing-experimental/apollo-graphql/test.ts @@ -11,7 +11,6 @@ describe('GraphQL/Apollo Tests', () => { 'graphql.source': '{hello}', 'otel.kind': 'INTERNAL', 'sentry.origin': 'auto.graphql.otel.graphql', - 'sentry.source': 'custom', }, description: 'query', status: 'ok', From cd323cd515553cdd2fcfe9a877fc19bc46d19bdd Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 14:18:10 +0000 Subject: [PATCH 23/44] stuff --- .../suites/tracing/browsertracing/init.js | 3 +- .../test/integration/app_v2/entry.client.tsx | 6 +- packages/sveltekit/src/client/sdk.ts | 64 +------------------ packages/sveltekit/test/client/sdk.test.ts | 49 +------------- .../src/browser/browserTracingIntegration.ts | 3 - .../test/browser/browsertracing.test.ts | 12 ++-- packages/tracing/test/hub.test.ts | 6 +- 7 files changed, 19 insertions(+), 124 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/init.js index ce4e0c4ad7f7..83076460599f 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/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/packages/remix/test/integration/app_v2/entry.client.tsx b/packages/remix/test/integration/app_v2/entry.client.tsx index 17da03ff6a70..bdee1860d03f 100644 --- a/packages/remix/test/integration/app_v2/entry.client.tsx +++ b/packages/remix/test/integration/app_v2/entry.client.tsx @@ -7,8 +7,10 @@ Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', tracesSampleRate: 1, integrations: [ - new Sentry.BrowserTracing({ - routingInstrumentation: Sentry.remixRouterInstrumentation(useEffect, useLocation, useMatches), + Sentry.browserTracingIntegration({ + useEffect, + useLocation, + useMatches, }), ], }); diff --git a/packages/sveltekit/src/client/sdk.ts b/packages/sveltekit/src/client/sdk.ts index a3c996457c46..86b869af65d3 100644 --- a/packages/sveltekit/src/client/sdk.ts +++ b/packages/sveltekit/src/client/sdk.ts @@ -1,13 +1,10 @@ import { applySdkMetadata, hasTracingEnabled, setTag } from '@sentry/core'; -import type { BrowserOptions, browserTracingIntegration } from '@sentry/svelte'; +import type { BrowserOptions } from '@sentry/svelte'; import { getDefaultIntegrations as getDefaultSvelteIntegrations } from '@sentry/svelte'; import { WINDOW, init as initSvelteSdk } from '@sentry/svelte'; import type { Integration } from '@sentry/types'; -import { - BrowserTracing, - browserTracingIntegration as svelteKitBrowserTracingIntegration, -} from './browserTracingIntegration'; +import { browserTracingIntegration as svelteKitBrowserTracingIntegration } from './browserTracingIntegration'; type WindowWithSentryFetchProxy = typeof WINDOW & { _sentryFetchProxy?: typeof fetch; @@ -29,8 +26,6 @@ export function init(options: BrowserOptions): void { applySdkMetadata(opts, 'sveltekit', ['sveltekit', 'svelte']); - fixBrowserTracingIntegration(opts); - // 1. Switch window.fetch to our fetch proxy we injected earlier const actualFetch = switchToFetchProxy(); @@ -45,61 +40,6 @@ export function init(options: BrowserOptions): void { setTag('runtime', 'browser'); } -// TODO v8: Remove this again -// We need to handle BrowserTracing passed to `integrations` that comes from `@sentry/tracing`, not `@sentry/sveltekit` :( -function fixBrowserTracingIntegration(options: BrowserOptions): void { - const { integrations } = options; - if (!integrations) { - return; - } - - if (Array.isArray(integrations)) { - options.integrations = maybeUpdateBrowserTracingIntegration(integrations); - } else { - options.integrations = defaultIntegrations => { - const userFinalIntegrations = integrations(defaultIntegrations); - - return maybeUpdateBrowserTracingIntegration(userFinalIntegrations); - }; - } -} - -function isNewBrowserTracingIntegration( - integration: Integration, -): integration is Integration & { options?: Parameters[0] } { - // eslint-disable-next-line deprecation/deprecation - return !!integration.afterAllSetup && !!(integration as BrowserTracing).options; -} - -function maybeUpdateBrowserTracingIntegration(integrations: Integration[]): Integration[] { - const browserTracing = integrations.find(integration => integration.name === 'BrowserTracing'); - - if (!browserTracing) { - return integrations; - } - - // If `browserTracingIntegration()` was added, we need to force-convert it to our custom one - if (isNewBrowserTracingIntegration(browserTracing)) { - const { options } = browserTracing; - // eslint-disable-next-line deprecation/deprecation - integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options); - } - - // If BrowserTracing was added, but it is not our forked version, - // replace it with our forked version with the same options - // eslint-disable-next-line deprecation/deprecation - if (!(browserTracing instanceof BrowserTracing)) { - // eslint-disable-next-line deprecation/deprecation - const options: ConstructorParameters[0] = (browserTracing as BrowserTracing).options; - // This option is overwritten by the custom integration - delete options.routingInstrumentation; - // eslint-disable-next-line deprecation/deprecation - integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options); - } - - return integrations; -} - function getDefaultIntegrations(options: BrowserOptions): Integration[] | undefined { // This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", in which case everything inside // will get treeshaken away diff --git a/packages/sveltekit/test/client/sdk.test.ts b/packages/sveltekit/test/client/sdk.test.ts index 9e969c08504d..4cfc345a1b6f 100644 --- a/packages/sveltekit/test/client/sdk.test.ts +++ b/packages/sveltekit/test/client/sdk.test.ts @@ -61,7 +61,7 @@ describe('Sentry client SDK', () => { ['tracesSampleRate', { tracesSampleRate: 0 }], ['tracesSampler', { tracesSampler: () => 1.0 }], ['enableTracing', { enableTracing: true }], - ])('adds the BrowserTracing integration if tracing is enabled via %s', (_, tracingOptions) => { + ])('adds a browserTracingIntegration if tracing is enabled via %s', (_, tracingOptions) => { init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', ...tracingOptions, @@ -74,7 +74,7 @@ describe('Sentry client SDK', () => { it.each([ ['enableTracing', { enableTracing: false }], ['no tracing option set', {}], - ])("doesn't add the BrowserTracing integration if tracing is disabled via %s", (_, tracingOptions) => { + ])("doesn't add a browserTracingIntegration integration if tracing is disabled via %s", (_, tracingOptions) => { init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', ...tracingOptions, @@ -84,7 +84,7 @@ describe('Sentry client SDK', () => { expect(browserTracing).toBeUndefined(); }); - it("doesn't add the BrowserTracing integration if `__SENTRY_TRACING__` is set to false", () => { + it("doesn't add a browserTracingIntegration if `__SENTRY_TRACING__` is set to false", () => { // This is the closest we can get to unit-testing the `__SENTRY_TRACING__` tree-shaking guard // IRL, the code to add the integration would most likely be removed by the bundler. @@ -100,49 +100,6 @@ describe('Sentry client SDK', () => { delete globalThis.__SENTRY_TRACING__; }); - - it('Merges a user-provided BrowserTracing integration with the automatically added one', () => { - init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - // eslint-disable-next-line deprecation/deprecation - integrations: [new BrowserTracing({ finalTimeout: 10 })], - enableTracing: true, - }); - - // eslint-disable-next-line deprecation/deprecation - const browserTracing = getClient()?.getIntegrationByName('BrowserTracing') as BrowserTracing; - const options = browserTracing.options; - - expect(browserTracing).toBeDefined(); - - // This shows that the user-configured options are still here - expect(options.finalTimeout).toEqual(10); - - // But we force the routing instrumentation to be ours - // eslint-disable-next-line deprecation/deprecation - expect(options.routingInstrumentation).toEqual(svelteKitRoutingInstrumentation); - }); - - it('Merges a user-provided browserTracingIntegration with the automatically added one', () => { - init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [browserTracingIntegration({ finalTimeout: 10 })], - enableTracing: true, - }); - - // eslint-disable-next-line deprecation/deprecation - const browserTracing = getClient()?.getIntegrationByName('BrowserTracing') as BrowserTracing; - const options = browserTracing.options; - - expect(browserTracing).toBeDefined(); - - // This shows that the user-configured options are still here - expect(options.finalTimeout).toEqual(10); - - // But we force the routing instrumentation to be ours - // eslint-disable-next-line deprecation/deprecation - expect(options.routingInstrumentation).toEqual(svelteKitRoutingInstrumentation); - }); }); }); }); diff --git a/packages/tracing-internal/src/browser/browserTracingIntegration.ts b/packages/tracing-internal/src/browser/browserTracingIntegration.ts index e87670b0bdd3..eebc82fcff1a 100644 --- a/packages/tracing-internal/src/browser/browserTracingIntegration.ts +++ b/packages/tracing-internal/src/browser/browserTracingIntegration.ts @@ -380,9 +380,6 @@ export const browserTracingIntegration = ((_options: Partial { } }); - function createBrowserTracing(setup?: boolean, _options?: Partial): BrowserTracing { - const instance = new BrowserTracing(_options); + function createBrowserTracing(setup?: boolean, options?: Partial) { + const instance = browserTracingIntegration(options); if (setup) { - const processor = () => undefined; - instance.setupOnce(processor, () => getCurrentHub() as hubExtensions.Hub); + instance.afterAllSetup(new BrowserClient()); } return instance; diff --git a/packages/tracing/test/hub.test.ts b/packages/tracing/test/hub.test.ts index b12966e6b3dc..f033ed8e9885 100644 --- a/packages/tracing/test/hub.test.ts +++ b/packages/tracing/test/hub.test.ts @@ -1,6 +1,6 @@ /* eslint-disable deprecation/deprecation */ /* eslint-disable @typescript-eslint/unbound-method */ -import { BrowserClient } from '@sentry/browser'; +import { BrowserClient, browserTracingIntegration } from '@sentry/browser'; import { Hub, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, makeMain } from '@sentry/core'; import * as utilsModule from '@sentry/utils'; // for mocking import { extractTraceparentData, logger } from '@sentry/utils'; @@ -457,7 +457,7 @@ The transaction will not be sampled. Please use the otel instrumentation to star const options = getDefaultBrowserClientOptions({ dsn: 'https://1231@dogs.are.great/1121', tracesSampleRate: 1, - integrations: [new BrowserTracing()], + integrations: [browserTracingIntegration()], }); const hub = new Hub(new BrowserClient(options)); makeMain(hub); @@ -496,7 +496,7 @@ The transaction will not be sampled. Please use the otel instrumentation to star const options = getDefaultBrowserClientOptions({ dsn: 'https://1231@dogs.are.great/1121', tracesSampleRate: 1, - integrations: [new BrowserTracing()], + integrations: [browserTracingIntegration()], }); const hub = new Hub(new BrowserClient(options)); makeMain(hub); From fec77bc143888240f9d82451ec24ea5b579fec0f Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 16 Feb 2024 14:43:16 +0000 Subject: [PATCH 24/44] . --- .../test/browser/browsertracing.test.ts | 62 +------------------ 1 file changed, 2 insertions(+), 60 deletions(-) diff --git a/packages/tracing-internal/test/browser/browsertracing.test.ts b/packages/tracing-internal/test/browser/browsertracing.test.ts index 167df73e30ed..c4d0a24ca9b2 100644 --- a/packages/tracing-internal/test/browser/browsertracing.test.ts +++ b/packages/tracing-internal/test/browser/browsertracing.test.ts @@ -10,16 +10,13 @@ import * as hubExtensions from '@sentry/core'; import type { BaseTransportOptions, ClientOptions, DsnComponents, HandlerDataHistory } from '@sentry/types'; import { JSDOM } from 'jsdom'; -import { BrowserClient } from '@sentry/browser'; +import { browserTracingIntegration } from '@sentry/browser'; import { timestampInSeconds } from '@sentry/utils'; import type { IdleTransaction } from '../../../tracing/src'; import { getActiveTransaction } from '../../../tracing/src'; import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils'; -import { browserTracingIntegration } from '../../build/types'; import type { BrowserTracingOptions } from '../../src/browser/browsertracing'; import { getMetaContent } from '../../src/browser/browsertracing'; -import { defaultRequestInstrumentationOptions } from '../../src/browser/request'; -import { instrumentRoutingWithDefaults } from '../../src/browser/router'; import { WINDOW } from '../../src/browser/types'; import { TestClient } from '../utils/TestClient'; @@ -86,67 +83,12 @@ describe('BrowserTracing', () => { function createBrowserTracing(setup?: boolean, options?: Partial) { const instance = browserTracingIntegration(options); if (setup) { - instance.afterAllSetup(new BrowserClient()); + instance.afterAllSetup(new TestClient(getDefaultBrowserClientOptions())); } return instance; } - // These are important enough to check with a test as incorrect defaults could - // break a lot of users' configurations. - it('is created with default settings', () => { - const browserTracing = createBrowserTracing(); - - expect(browserTracing.options).toEqual({ - enableLongTask: true, - _experiments: {}, - ...TRACING_DEFAULTS, - 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({ - enableLongTask: false, - ...TRACING_DEFAULTS, - markBackgroundTransactions: true, - routingInstrumentation: instrumentRoutingWithDefaults, - startTransactionOnLocationChange: true, - startTransactionOnPageLoad: true, - ...defaultRequestInstrumentationOptions, - _experiments: { - enableLongTask: false, - }, - }); - }); - - it('is allows to disable enableLongTask', () => { - const browserTracing = createBrowserTracing(false, { - enableLongTask: false, - }); - - expect(browserTracing.options).toEqual({ - enableLongTask: false, - _experiments: {}, - ...TRACING_DEFAULTS, - markBackgroundTransactions: true, - routingInstrumentation: instrumentRoutingWithDefaults, - startTransactionOnLocationChange: true, - startTransactionOnPageLoad: true, - ...defaultRequestInstrumentationOptions, - }); - }); - /** * All of these tests under `describe('route transaction')` are tested with * `browserTracing.options = { routingInstrumentation: customInstrumentRouting }`, From cc9bf5dcd4c9477671c88377e4a547bd673dce26 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 19 Feb 2024 08:30:33 +0000 Subject: [PATCH 25/44] . --- .../src/browser/browserTracingIntegration.ts | 4 ++-- packages/tracing-internal/src/browser/router.ts | 6 +++--- .../test/browser/browsertracing.test.ts | 11 ----------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/packages/tracing-internal/src/browser/browserTracingIntegration.ts b/packages/tracing-internal/src/browser/browserTracingIntegration.ts index eebc82fcff1a..aaa4ba341036 100644 --- a/packages/tracing-internal/src/browser/browserTracingIntegration.ts +++ b/packages/tracing-internal/src/browser/browserTracingIntegration.ts @@ -322,7 +322,7 @@ export const browserTracingIntegration = ((_options: Partial( return; } - let startingUrl: string | undefined = 'wtf4'; + let startingUrl: string | undefined = WINDOW.location.href; let activeTransaction: T | undefined; if (startTransactionOnPageLoad) { activeTransaction = customStartTransaction({ - name: WINDOW.location.pathname, // wtf5 + name: WINDOW.location.pathname, // pageload should always start at timeOrigin (and needs to be in s, not ms) startTimestamp: browserPerformanceTimeOrigin ? browserPerformanceTimeOrigin / 1000 : undefined, op: 'pageload', @@ -58,7 +58,7 @@ export function instrumentRoutingWithDefaults( activeTransaction.end(); } activeTransaction = customStartTransaction({ - name: 'wtf6', + name: WINDOW.location.pathname, op: 'navigation', origin: 'auto.navigation.browser', attributes: { diff --git a/packages/tracing-internal/test/browser/browsertracing.test.ts b/packages/tracing-internal/test/browser/browsertracing.test.ts index c4d0a24ca9b2..348b05b7c922 100644 --- a/packages/tracing-internal/test/browser/browsertracing.test.ts +++ b/packages/tracing-internal/test/browser/browsertracing.test.ts @@ -99,17 +99,6 @@ describe('BrowserTracing', () => { customStartTransaction({ name: 'a/path', op: 'pageload' }); }; - it('_experiements calls onStartRouteTransaction on route instrumentation', () => { - const onStartTranscation = jest.fn(); - createBrowserTracing(true, { - _experiments: { - onStartRouteTransaction: onStartTranscation, - }, - }); - - expect(onStartTranscation).toHaveBeenCalledTimes(1); - }); - it('calls custom routing instrumenation', () => { createBrowserTracing(true, { routingInstrumentation: customInstrumentRouting, From fca8f2ea7e032009683d8a48b1dfa832bc7feecb Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Tue, 20 Feb 2024 15:13:08 +0000 Subject: [PATCH 26/44] format --- packages/sveltekit/test/client/sdk.test.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/sveltekit/test/client/sdk.test.ts b/packages/sveltekit/test/client/sdk.test.ts index 4cfc345a1b6f..162ccd72852d 100644 --- a/packages/sveltekit/test/client/sdk.test.ts +++ b/packages/sveltekit/test/client/sdk.test.ts @@ -1,17 +1,9 @@ import type { BrowserClient } from '@sentry/svelte'; import * as SentrySvelte from '@sentry/svelte'; -import { - SDK_VERSION, - browserTracingIntegration, - getClient, - getCurrentScope, - getGlobalScope, - getIsolationScope, -} from '@sentry/svelte'; +import { SDK_VERSION, getClient, getCurrentScope, getGlobalScope, getIsolationScope } from '@sentry/svelte'; import { vi } from 'vitest'; -import { BrowserTracing, init } from '../../src/client'; -import { svelteKitRoutingInstrumentation } from '../../src/client/router'; +import { init } from '../../src/client'; const svelteInit = vi.spyOn(SentrySvelte, 'init'); From 5e8d0b577ad772776ad62c92b75c44259c8b8840 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 21 Feb 2024 13:48:44 +0000 Subject: [PATCH 27/44] tests --- .../browser/browserTracingIntegration.test.ts | 461 ++++++++++++++++ .../test/browser/browsertracing.test.ts | 521 ------------------ 2 files changed, 461 insertions(+), 521 deletions(-) delete mode 100644 packages/tracing-internal/test/browser/browsertracing.test.ts diff --git a/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts b/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts index 2655ae05dbe7..6cf610730bba 100644 --- a/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts +++ b/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts @@ -1,14 +1,21 @@ import { + IdleTransaction, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, + TRACING_DEFAULTS, getActiveSpan, + getActiveTransaction, getCurrentScope, setCurrentClient, spanIsSampled, spanToJSON, + startInactiveSpan, } from '@sentry/core'; +import * as hubExtensions from '@sentry/core'; +import type { StartSpanOptions } from '@sentry/types'; +import { timestampInSeconds } from '@sentry/utils'; import { JSDOM } from 'jsdom'; import { browserTracingIntegration, startBrowserTracingNavigationSpan, startBrowserTracingPageLoadSpan } from '../..'; import { WINDOW } from '../../src/browser/types'; @@ -82,6 +89,19 @@ describe('browserTracingIntegration', () => { expect(spanIsSampled(span!)).toBe(false); }); + it("doesn't create a pageload span when instrumentPageLoad is false", () => { + const client = new TestClient( + getDefaultClientOptions({ + integrations: [browserTracingIntegration({ instrumentPageLoad: false })], + }), + ); + setCurrentClient(client); + client.init(); + + const span = getActiveSpan(); + expect(span).not.toBeDefined(); + }); + it('works with tracing enabled but unsampled', () => { const client = new TestClient( getDefaultClientOptions({ @@ -181,6 +201,75 @@ describe('browserTracingIntegration', () => { }); }); + it('extracts window.location/self.location for sampling context in pageload transactions', () => { + // this is what is used to get the span name - JSDOM does not update this on it's own! + const dom = new JSDOM(undefined, { url: 'https://example.com/test' }); + Object.defineProperty(global, 'location', { value: dom.window.document.location, writable: true }); + + const tracesSampler = jest.fn(); + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 1, + integrations: [browserTracingIntegration()], + tracesSampler, + }), + ); + setCurrentClient(client); + client.init(); + + expect(tracesSampler).toHaveBeenCalledWith( + expect.objectContaining({ + location: dom.window.document.location, + }), + ); + }); + + it('extracts window.location/self.location for sampling context in navigation transactions', () => { + const tracesSampler = jest.fn(); + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 1, + integrations: [browserTracingIntegration({ instrumentPageLoad: false })], + tracesSampler, + }), + ); + setCurrentClient(client); + client.init(); + + // this is what is used to get the span name - JSDOM does not update this on it's own! + const dom = new JSDOM(undefined, { url: 'https://example.com/test' }); + Object.defineProperty(global, 'location', { value: dom.window.document.location, writable: true }); + + WINDOW.history.pushState({}, '', '/test'); + + expect(tracesSampler).toHaveBeenCalledWith( + expect.objectContaining({ + location: dom.window.document.location, + }), + ); + }); + + it("trims pageload transactions to the max duration of the transaction's children", () => { + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 1, + integrations: [browserTracingIntegration()], + }), + ); + + setCurrentClient(client); + client.init(); + + const pageloadSpan = getActiveSpan(); + const childSpan = startInactiveSpan({ name: 'pageload-child' }); + const timestamp = timestampInSeconds(); + + childSpan?.end(timestamp); + pageloadSpan?.end(timestamp + 12345); + + expect(spanToJSON(pageloadSpan!).timestamp).toBe(timestamp); + }); + describe('startBrowserTracingPageLoadSpan', () => { it('works without integration setup', () => { const client = new TestClient( @@ -275,6 +364,87 @@ describe('browserTracingIntegration', () => { trace_id: expect.any(String), }); }); + + it('calls before beforeStartSpan', () => { + const mockBeforeStartSpan = jest.fn((options: StartSpanOptions) => options); + + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 0, + integrations: [ + browserTracingIntegration({ instrumentPageLoad: false, beforeStartSpan: mockBeforeStartSpan }), + ], + }), + ); + setCurrentClient(client); + client.init(); + + startBrowserTracingPageLoadSpan(client, { name: 'test span' }); + + expect(mockBeforeStartSpan).toHaveBeenCalledWith( + expect.objectContaining({ + name: 'test span', + op: 'pageload', + }), + ); + }); + + it('uses options overridden with beforeStartSpan', () => { + const mockBeforeStartSpan = jest.fn((options: StartSpanOptions) => ({ + ...options, + op: 'test op', + })); + + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 0, + integrations: [ + browserTracingIntegration({ + instrumentPageLoad: false, + instrumentNavigation: false, + beforeStartSpan: mockBeforeStartSpan, + }), + ], + }), + ); + setCurrentClient(client); + client.init(); + + startBrowserTracingPageLoadSpan(client, { name: 'test span' }); + + const pageloadSpan = getActiveSpan(); + + expect(spanToJSON(pageloadSpan!).op).toBe('test op'); + }); + }); + + it('sets source to "custom" if name is changed in beforeStartSpan', () => { + const mockBeforeStartSpan = jest.fn((options: StartSpanOptions) => ({ + ...options, + name: 'changed', + })); + + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 0, + integrations: [ + browserTracingIntegration({ + instrumentPageLoad: false, + instrumentNavigation: false, + beforeStartSpan: mockBeforeStartSpan, + }), + ], + }), + ); + setCurrentClient(client); + client.init(); + + startBrowserTracingPageLoadSpan(client, { name: 'test span' }); + + const pageloadSpan = getActiveSpan(); + + expect(spanToJSON(pageloadSpan!).description).toBe('changed'); + expect(spanToJSON(pageloadSpan!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('custom'); }); describe('startBrowserTracingNavigationSpan', () => { @@ -371,5 +541,296 @@ describe('browserTracingIntegration', () => { trace_id: expect.any(String), }); }); + + it('calls before beforeStartSpan', () => { + const mockBeforeStartSpan = jest.fn((options: StartSpanOptions) => options); + + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 0, + integrations: [ + browserTracingIntegration({ + instrumentPageLoad: false, + instrumentNavigation: false, + beforeStartSpan: mockBeforeStartSpan, + }), + ], + }), + ); + setCurrentClient(client); + client.init(); + + startBrowserTracingNavigationSpan(client, { name: 'test span' }); + + expect(mockBeforeStartSpan).toHaveBeenCalledWith( + expect.objectContaining({ + name: 'test span', + op: 'navigation', + }), + ); + }); + + it('uses options overridden with beforeStartSpan', () => { + const mockBeforeStartSpan = jest.fn((options: StartSpanOptions) => ({ + ...options, + op: 'test op', + })); + + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 0, + integrations: [ + browserTracingIntegration({ + instrumentPageLoad: false, + instrumentNavigation: false, + beforeStartSpan: mockBeforeStartSpan, + }), + ], + }), + ); + setCurrentClient(client); + client.init(); + + startBrowserTracingNavigationSpan(client, { name: 'test span' }); + + const navigationSpan = getActiveSpan(); + + expect(spanToJSON(navigationSpan!).op).toBe('test op'); + }); + + it('sets source to "custom" if name is changed in beforeStartSpan', () => { + const mockBeforeStartSpan = jest.fn((options: StartSpanOptions) => ({ + ...options, + name: 'changed', + })); + + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 0, + integrations: [ + browserTracingIntegration({ + instrumentPageLoad: false, + instrumentNavigation: false, + beforeStartSpan: mockBeforeStartSpan, + }), + ], + }), + ); + setCurrentClient(client); + client.init(); + + startBrowserTracingNavigationSpan(client, { name: 'test span' }); + + const pageloadSpan = getActiveSpan(); + + expect(spanToJSON(pageloadSpan!).description).toBe('changed'); + expect(spanToJSON(pageloadSpan!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('custom'); + }); + }); + + it('sets transaction context from sentry-trace header for pageload transactions', () => { + const name = 'sentry-trace'; + const content = '126de09502ae4e0fb26c6967190756a4-b6e54397b12a2a0f-1'; + document.head.innerHTML = + `` + ''; + const startIdleTransaction = jest.spyOn(hubExtensions, 'startIdleTransaction'); + + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 1, + integrations: [browserTracingIntegration()], + }), + ); + setCurrentClient(client); + client.init(); + + expect(startIdleTransaction).toHaveBeenCalledWith( + expect.any(Object), + expect.objectContaining({ + traceId: '126de09502ae4e0fb26c6967190756a4', + parentSpanId: 'b6e54397b12a2a0f', + parentSampled: true, + metadata: { + dynamicSamplingContext: { release: '2.1.14' }, + }, + }), + expect.any(Number), + expect.any(Number), + expect.any(Boolean), + expect.any(Object), + expect.any(Number), + true, + ); + }); + + describe('using the tag data', () => { + it('uses the tracing data for pageload transactions', () => { + // make sampled false here, so we can see that it's being used rather than the tracesSampleRate-dictated one + document.head.innerHTML = + '' + + ''; + + const client = new TestClient( + getDefaultClientOptions({ + integrations: [browserTracingIntegration()], + }), + ); + setCurrentClient(client); + + // pageload transactions are created as part of the BrowserTracing integration's initialization + client.init(); + + const transaction = getActiveTransaction() as IdleTransaction; + const dynamicSamplingContext = transaction.getDynamicSamplingContext()!; + + expect(transaction).toBeDefined(); + expect(transaction.op).toBe('pageload'); + expect(transaction.traceId).toEqual('12312012123120121231201212312012'); + expect(transaction.parentSpanId).toEqual('1121201211212012'); + expect(transaction.sampled).toBe(false); + expect(dynamicSamplingContext).toBeDefined(); + expect(dynamicSamplingContext).toStrictEqual({ release: '2.1.14' }); + }); + + it('puts frozen Dynamic Sampling Context on pageload transactions if sentry-trace data and only 3rd party baggage is present', () => { + // make sampled false here, so we can see that it's being used rather than the tracesSampleRate-dictated one + document.head.innerHTML = + '' + + ''; + + const client = new TestClient( + getDefaultClientOptions({ + integrations: [browserTracingIntegration()], + }), + ); + setCurrentClient(client); + + // pageload transactions are created as part of the BrowserTracing integration's initialization + client.init(); + + const transaction = getActiveTransaction() as IdleTransaction; + const dynamicSamplingContext = transaction.getDynamicSamplingContext()!; + + expect(transaction).toBeDefined(); + expect(transaction.op).toBe('pageload'); + expect(transaction.traceId).toEqual('12312012123120121231201212312012'); + expect(transaction.parentSpanId).toEqual('1121201211212012'); + expect(transaction.sampled).toBe(false); + expect(dynamicSamplingContext).toStrictEqual({}); + }); + + it('ignores the meta tag data for navigation transactions', () => { + document.head.innerHTML = + '' + + ''; + + const client = new TestClient( + getDefaultClientOptions({ + integrations: [browserTracingIntegration({ instrumentPageLoad: false })], + }), + ); + setCurrentClient(client); + + // pageload transactions are created as part of the BrowserTracing integration's initialization + client.init(); + + // this is what is used to get the span name - JSDOM does not update this on it's own! + const dom = new JSDOM(undefined, { url: 'https://example.com/navigation-test' }); + Object.defineProperty(global, 'location', { value: dom.window.document.location, writable: true }); + + WINDOW.history.pushState({}, '', '/navigation-test'); + + const transaction = getActiveTransaction() as IdleTransaction; + const dynamicSamplingContext = transaction.getDynamicSamplingContext()!; + + expect(transaction).toBeDefined(); + expect(transaction.op).toBe('navigation'); + expect(transaction.traceId).not.toEqual('12312012123120121231201212312012'); + expect(transaction.parentSpanId).toBeUndefined(); + expect(dynamicSamplingContext).toMatchObject({ + trace_id: expect.not.stringMatching('12312012123120121231201212312012'), + }); + transaction.end(); + }); + }); + + describe('idleTimeout', () => { + it('is created by default', () => { + jest.useFakeTimers(); + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 1, + integrations: [browserTracingIntegration()], + }), + ); + setCurrentClient(client); + client.init(); + + const mockFinish = jest.fn(); + const transaction = getActiveTransaction() as IdleTransaction; + transaction.sendAutoFinishSignal(); + transaction.end = mockFinish; + + const span = transaction.startChild(); // activities = 1 + span.end(); // activities = 0 + + expect(mockFinish).toHaveBeenCalledTimes(0); + jest.advanceTimersByTime(TRACING_DEFAULTS.idleTimeout); + expect(mockFinish).toHaveBeenCalledTimes(1); + }); + + it('can be a custom value', () => { + jest.useFakeTimers(); + + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 1, + integrations: [browserTracingIntegration({ idleTimeout: 2000 })], + }), + ); + setCurrentClient(client); + client.init(); + + const mockFinish = jest.fn(); + const transaction = getActiveTransaction() as IdleTransaction; + transaction.sendAutoFinishSignal(); + transaction.end = mockFinish; + + const span = transaction.startChild(); // activities = 1 + span.end(); // activities = 0 + + expect(mockFinish).toHaveBeenCalledTimes(0); + jest.advanceTimersByTime(2000); + expect(mockFinish).toHaveBeenCalledTimes(1); + }); + }); + + // TODO(lforst): I cannot manage to get this test to pass. + it.skip('heartbeatInterval can be a custom value', () => { + jest.useFakeTimers(); + + const interval = 200; + + const client = new TestClient( + getDefaultClientOptions({ + tracesSampleRate: 1, + integrations: [browserTracingIntegration({ heartbeatInterval: interval })], + }), + ); + + setCurrentClient(client); + client.init(); + + const mockFinish = jest.fn(); + const transaction = getActiveTransaction() as IdleTransaction; + transaction.sendAutoFinishSignal(); + transaction.end = mockFinish; + + const span = startInactiveSpan({ name: 'child-span' }); // activities = 1 + span!.end(); // activities = 0 + + expect(mockFinish).toHaveBeenCalledTimes(0); + jest.advanceTimersByTime(interval * 3); + expect(mockFinish).toHaveBeenCalledTimes(1); }); }); diff --git a/packages/tracing-internal/test/browser/browsertracing.test.ts b/packages/tracing-internal/test/browser/browsertracing.test.ts deleted file mode 100644 index 348b05b7c922..000000000000 --- a/packages/tracing-internal/test/browser/browsertracing.test.ts +++ /dev/null @@ -1,521 +0,0 @@ -/* eslint-disable deprecation/deprecation */ -import { - SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, - TRACING_DEFAULTS, - getClient, - setCurrentClient, - spanToJSON, -} from '@sentry/core'; -import * as hubExtensions from '@sentry/core'; -import type { BaseTransportOptions, ClientOptions, DsnComponents, HandlerDataHistory } from '@sentry/types'; -import { JSDOM } from 'jsdom'; - -import { browserTracingIntegration } from '@sentry/browser'; -import { timestampInSeconds } from '@sentry/utils'; -import type { IdleTransaction } from '../../../tracing/src'; -import { getActiveTransaction } from '../../../tracing/src'; -import { getDefaultBrowserClientOptions } from '../../../tracing/test/testutils'; -import type { BrowserTracingOptions } from '../../src/browser/browsertracing'; -import { getMetaContent } from '../../src/browser/browsertracing'; -import { WINDOW } from '../../src/browser/types'; -import { TestClient } from '../utils/TestClient'; - -let mockChangeHistory: (data: HandlerDataHistory) => void = () => {}; - -jest.mock('@sentry/utils', () => { - const actual = jest.requireActual('@sentry/utils'); - return { - ...actual, - - addHistoryInstrumentationHandler: (callback: (data: HandlerDataHistory) => void): void => { - mockChangeHistory = callback; - }, - }; -}); - -const mockStartTrackingWebVitals = jest.fn().mockReturnValue(() => () => {}); - -jest.mock('../../src/browser/metrics', () => ({ - addPerformanceEntries: jest.fn(), - startTrackingInteractions: jest.fn(), - startTrackingLongTasks: jest.fn(), - startTrackingWebVitals: () => mockStartTrackingWebVitals(), -})); - -const instrumentOutgoingRequestsMock = jest.fn(); -jest.mock('./../../src/browser/request', () => { - const actual = jest.requireActual('./../../src/browser/request'); - return { - ...actual, - instrumentOutgoingRequests: (options: Partial) => instrumentOutgoingRequestsMock(options), - }; -}); - -beforeAll(() => { - const dom = new JSDOM(); - // @ts-expect-error need to override global document - WINDOW.document = dom.window.document; - // @ts-expect-error need to override global document - WINDOW.window = dom.window; - WINDOW.location = dom.window.location; -}); - -describe('BrowserTracing', () => { - beforeEach(() => { - jest.useFakeTimers(); - const options = getDefaultBrowserClientOptions({ tracesSampleRate: 1 }); - const client = new TestClient(options); - setCurrentClient(client); - client.init(); - document.head.innerHTML = ''; - - mockStartTrackingWebVitals.mockClear(); - }); - - afterEach(() => { - const activeTransaction = getActiveTransaction(); - if (activeTransaction) { - // Should unset off of scope. - activeTransaction.end(); - } - }); - - function createBrowserTracing(setup?: boolean, options?: Partial) { - const instance = browserTracingIntegration(options); - if (setup) { - instance.afterAllSetup(new TestClient(getDefaultBrowserClientOptions())); - } - - return instance; - } - - /** - * All of these tests under `describe('route transaction')` are tested with - * `browserTracing.options = { routingInstrumentation: customInstrumentRouting }`, - * so that we can show this functionality works independent of the default routing integration. - */ - describe('route transaction', () => { - const customInstrumentRouting = (customStartTransaction: (obj: any) => void) => { - customStartTransaction({ name: 'a/path', op: 'pageload' }); - }; - - it('calls custom routing instrumenation', () => { - createBrowserTracing(true, { - routingInstrumentation: customInstrumentRouting, - }); - - const transaction = getActiveTransaction() as IdleTransaction; - expect(transaction).toBeDefined(); - expect(transaction.name).toBe('a/path'); - expect(transaction.op).toBe('pageload'); - }); - - it('trims all transactions', () => { - createBrowserTracing(true, { - routingInstrumentation: customInstrumentRouting, - }); - - const transaction = getActiveTransaction() as IdleTransaction; - const span = transaction.startChild(); - - const timestamp = timestampInSeconds(); - span.end(timestamp); - transaction.end(timestamp + 12345); - - expect(spanToJSON(transaction).timestamp).toBe(timestamp); - }); - - describe('beforeNavigate', () => { - it('is called on transaction creation', () => { - const mockBeforeNavigation = jest.fn().mockReturnValue({ name: 'here/is/my/path' }); - createBrowserTracing(true, { - beforeNavigate: mockBeforeNavigation, - routingInstrumentation: customInstrumentRouting, - }); - const transaction = getActiveTransaction() as IdleTransaction; - expect(transaction).toBeDefined(); - - expect(mockBeforeNavigation).toHaveBeenCalledTimes(1); - }); - - it('creates a transaction with sampled = false if beforeNavigate returns undefined', () => { - const mockBeforeNavigation = jest.fn().mockReturnValue(undefined); - createBrowserTracing(true, { - beforeNavigate: mockBeforeNavigation, - routingInstrumentation: customInstrumentRouting, - }); - const transaction = getActiveTransaction() as IdleTransaction; - expect(transaction.sampled).toBe(false); - - expect(mockBeforeNavigation).toHaveBeenCalledTimes(1); - }); - - it('can override default context values', () => { - const mockBeforeNavigation = jest.fn(ctx => ({ - ...ctx, - op: 'not-pageload', - })); - createBrowserTracing(true, { - beforeNavigate: mockBeforeNavigation, - routingInstrumentation: customInstrumentRouting, - }); - const transaction = getActiveTransaction() as IdleTransaction; - expect(transaction).toBeDefined(); - expect(transaction.op).toBe('not-pageload'); - - expect(mockBeforeNavigation).toHaveBeenCalledTimes(1); - }); - - it("sets transaction name source to `'custom'` if name is changed", () => { - const mockBeforeNavigation = jest.fn(ctx => ({ - ...ctx, - name: 'newName', - })); - createBrowserTracing(true, { - beforeNavigate: mockBeforeNavigation, - routingInstrumentation: customInstrumentRouting, - }); - const transaction = getActiveTransaction() as IdleTransaction; - expect(transaction).toBeDefined(); - expect(transaction.name).toBe('newName'); - expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('custom'); - - expect(mockBeforeNavigation).toHaveBeenCalledTimes(1); - }); - - it('sets transaction name source to default `url` if name is not changed', () => { - const mockBeforeNavigation = jest.fn(ctx => ({ - ...ctx, - })); - createBrowserTracing(true, { - beforeNavigate: mockBeforeNavigation, - routingInstrumentation: (customStartTransaction: (obj: any) => void) => { - customStartTransaction({ - name: 'a/path', - op: 'pageload', - attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url' }, - }); - }, - }); - const transaction = getActiveTransaction() as IdleTransaction; - expect(transaction).toBeDefined(); - expect(transaction.name).toBe('a/path'); - expect(transaction.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toBe('url'); - - expect(mockBeforeNavigation).toHaveBeenCalledTimes(1); - }); - }); - - it('sets transaction context from sentry-trace header', () => { - const name = 'sentry-trace'; - const content = '126de09502ae4e0fb26c6967190756a4-b6e54397b12a2a0f-1'; - document.head.innerHTML = - `` + ''; - const startIdleTransaction = jest.spyOn(hubExtensions, 'startIdleTransaction'); - - createBrowserTracing(true, { routingInstrumentation: customInstrumentRouting }); - - expect(startIdleTransaction).toHaveBeenCalledWith( - expect.any(Object), - expect.objectContaining({ - traceId: '126de09502ae4e0fb26c6967190756a4', - parentSpanId: 'b6e54397b12a2a0f', - parentSampled: true, - metadata: { - dynamicSamplingContext: { release: '2.1.14' }, - }, - }), - expect.any(Number), - expect.any(Number), - expect.any(Boolean), - expect.any(Object), - expect.any(Number), - true, - ); - }); - - describe('idleTimeout', () => { - it('is created by default', () => { - createBrowserTracing(true, { routingInstrumentation: customInstrumentRouting }); - const mockFinish = jest.fn(); - const transaction = getActiveTransaction() as IdleTransaction; - transaction.sendAutoFinishSignal(); - transaction.end = mockFinish; - - const span = transaction.startChild(); // activities = 1 - span.end(); // activities = 0 - - expect(mockFinish).toHaveBeenCalledTimes(0); - jest.advanceTimersByTime(TRACING_DEFAULTS.idleTimeout); - expect(mockFinish).toHaveBeenCalledTimes(1); - }); - - it('can be a custom value', () => { - createBrowserTracing(true, { idleTimeout: 2000, routingInstrumentation: customInstrumentRouting }); - const mockFinish = jest.fn(); - const transaction = getActiveTransaction() as IdleTransaction; - transaction.sendAutoFinishSignal(); - transaction.end = mockFinish; - - const span = transaction.startChild(); // activities = 1 - span.end(); // activities = 0 - - expect(mockFinish).toHaveBeenCalledTimes(0); - jest.advanceTimersByTime(2000); - expect(mockFinish).toHaveBeenCalledTimes(1); - }); - - it('calls `_collectWebVitals` if enabled', () => { - createBrowserTracing(true, { routingInstrumentation: customInstrumentRouting }); - const transaction = getActiveTransaction() as IdleTransaction; - - const span = transaction.startChild(); // activities = 1 - span.end(); // activities = 0 - - jest.advanceTimersByTime(TRACING_DEFAULTS.idleTimeout); - expect(mockStartTrackingWebVitals).toHaveBeenCalledTimes(1); - }); - }); - - describe('heartbeatInterval', () => { - it('can be a custom value', () => { - const interval = 200; - createBrowserTracing(true, { heartbeatInterval: interval, routingInstrumentation: customInstrumentRouting }); - const mockFinish = jest.fn(); - const transaction = getActiveTransaction() as IdleTransaction; - transaction.sendAutoFinishSignal(); - transaction.end = mockFinish; - - const span = transaction.startChild(); // activities = 1 - span.end(); // activities = 0 - - expect(mockFinish).toHaveBeenCalledTimes(0); - jest.advanceTimersByTime(interval * 3); - expect(mockFinish).toHaveBeenCalledTimes(1); - }); - }); - }); - - // Integration tests for the default routing instrumentation - describe('default routing instrumentation', () => { - describe('pageload transaction', () => { - it('is created on setup on scope', () => { - createBrowserTracing(true); - const transaction = getActiveTransaction() as IdleTransaction; - expect(transaction).toBeDefined(); - - expect(transaction.op).toBe('pageload'); - }); - - it('is not created if the option is false', () => { - createBrowserTracing(true, { startTransactionOnPageLoad: false }); - const transaction = getActiveTransaction() as IdleTransaction; - expect(transaction).not.toBeDefined(); - }); - }); - - describe('navigation transaction', () => { - beforeEach(() => { - mockChangeHistory = () => undefined; - }); - - it('it is not created automatically at startup', () => { - createBrowserTracing(true); - jest.runAllTimers(); - - const transaction = getActiveTransaction() as IdleTransaction; - expect(transaction).not.toBeDefined(); - }); - - it('is created on location change', () => { - createBrowserTracing(true); - const transaction1 = getActiveTransaction() as IdleTransaction; - expect(transaction1.op).toBe('pageload'); - expect(spanToJSON(transaction1).timestamp).not.toBeDefined(); - - mockChangeHistory({ to: 'here', from: 'there' }); - const transaction2 = getActiveTransaction() as IdleTransaction; - expect(transaction2.op).toBe('navigation'); - - expect(spanToJSON(transaction1).timestamp).toBeDefined(); - }); - - it('is not created if startTransactionOnLocationChange is false', () => { - createBrowserTracing(true, { startTransactionOnLocationChange: false }); - const transaction1 = getActiveTransaction() as IdleTransaction; - expect(transaction1.op).toBe('pageload'); - expect(spanToJSON(transaction1).timestamp).not.toBeDefined(); - - mockChangeHistory({ to: 'here', from: 'there' }); - const transaction2 = getActiveTransaction() as IdleTransaction; - expect(transaction2.op).toBe('pageload'); - }); - }); - }); - - describe('sentry-trace and baggage elements', () => { - describe('getMetaContent', () => { - it('finds the specified tag and extracts the value', () => { - const name = 'sentry-trace'; - const content = '126de09502ae4e0fb26c6967190756a4-b6e54397b12a2a0f-1'; - document.head.innerHTML = ``; - - const metaTagValue = getMetaContent(name); - expect(metaTagValue).toBe(content); - }); - - it("doesn't return meta tags other than the one specified", () => { - document.head.innerHTML = ''; - - const metaTagValue = getMetaContent('dogpark'); - expect(metaTagValue).toBe(undefined); - }); - - it('can pick the correct tag out of multiple options', () => { - const name = 'sentry-trace'; - const content = '126de09502ae4e0fb26c6967190756a4-b6e54397b12a2a0f-1'; - const sentryTraceMeta = ``; - const otherMeta = ''; - document.head.innerHTML = `${sentryTraceMeta} ${otherMeta}`; - - const metaTagValue = getMetaContent(name); - expect(metaTagValue).toBe(content); - }); - }); - - describe('using the tag data', () => { - beforeEach(() => { - getClient()!.getOptions = () => { - return { - release: '1.0.0', - environment: 'production', - } as ClientOptions; - }; - - getClient()!.getDsn = () => { - return { - publicKey: 'pubKey', - } as DsnComponents; - }; - }); - - it('uses the tracing data for pageload transactions', () => { - // make sampled false here, so we can see that it's being used rather than the tracesSampleRate-dictated one - document.head.innerHTML = - '' + - ''; - - // pageload transactions are created as part of the BrowserTracing integration's initialization - createBrowserTracing(true); - const transaction = getActiveTransaction() as IdleTransaction; - const dynamicSamplingContext = transaction.getDynamicSamplingContext()!; - - expect(transaction).toBeDefined(); - expect(transaction.op).toBe('pageload'); - expect(transaction.traceId).toEqual('12312012123120121231201212312012'); - expect(transaction.parentSpanId).toEqual('1121201211212012'); - expect(transaction.sampled).toBe(false); - expect(dynamicSamplingContext).toBeDefined(); - expect(dynamicSamplingContext).toStrictEqual({ release: '2.1.14' }); - }); - - it('puts frozen Dynamic Sampling Context on pageload transactions if sentry-trace data and only 3rd party baggage is present', () => { - // make sampled false here, so we can see that it's being used rather than the tracesSampleRate-dictated one - document.head.innerHTML = - '' + - ''; - - // pageload transactions are created as part of the BrowserTracing integration's initialization - createBrowserTracing(true); - const transaction = getActiveTransaction() as IdleTransaction; - const dynamicSamplingContext = transaction.getDynamicSamplingContext()!; - - expect(transaction).toBeDefined(); - expect(transaction.op).toBe('pageload'); - expect(transaction.traceId).toEqual('12312012123120121231201212312012'); - expect(transaction.parentSpanId).toEqual('1121201211212012'); - expect(transaction.sampled).toBe(false); - expect(dynamicSamplingContext).toStrictEqual({}); - }); - - it('ignores the meta tag data for navigation transactions', () => { - mockChangeHistory = () => undefined; - document.head.innerHTML = - '' + - ''; - - createBrowserTracing(true); - - mockChangeHistory({ to: 'here', from: 'there' }); - const transaction = getActiveTransaction() as IdleTransaction; - const dynamicSamplingContext = transaction.getDynamicSamplingContext()!; - - expect(transaction).toBeDefined(); - expect(transaction.op).toBe('navigation'); - expect(transaction.traceId).not.toEqual('12312012123120121231201212312012'); - expect(transaction.parentSpanId).toBeUndefined(); - expect(dynamicSamplingContext).toStrictEqual({ - release: '1.0.0', - environment: 'production', - public_key: 'pubKey', - sampled: 'false', - trace_id: expect.not.stringMatching('12312012123120121231201212312012'), - }); - }); - }); - }); - - describe('sampling', () => { - const dogParkLocation = { - hash: '#next-to-the-fountain', - host: 'the.dog.park', - hostname: 'the.dog.park', - href: 'mutualsniffing://the.dog.park/by/the/trees/?chase=me&please=thankyou#next-to-the-fountain', - origin: "'mutualsniffing://the.dog.park", - pathname: '/by/the/trees/', - port: '', - protocol: 'mutualsniffing:', - search: '?chase=me&please=thankyou', - }; - - it('extracts window.location/self.location for sampling context in pageload transactions', () => { - WINDOW.location = dogParkLocation as any; - - const tracesSampler = jest.fn(); - const options = getDefaultBrowserClientOptions({ tracesSampler }); - const client = new TestClient(options); - setCurrentClient(client); - client.init(); - // setting up the BrowserTracing integration automatically starts a pageload transaction - createBrowserTracing(true); - - expect(tracesSampler).toHaveBeenCalledWith( - expect.objectContaining({ - location: dogParkLocation, - transactionContext: expect.objectContaining({ op: 'pageload' }), - }), - ); - }); - - it('extracts window.location/self.location for sampling context in navigation transactions', () => { - WINDOW.location = dogParkLocation as any; - - const tracesSampler = jest.fn(); - const options = getDefaultBrowserClientOptions({ tracesSampler }); - const client = new TestClient(options); - setCurrentClient(client); - client.init(); - // setting up the BrowserTracing integration normally automatically starts a pageload transaction, but that's not - // what we're testing here - createBrowserTracing(true, { startTransactionOnPageLoad: false }); - - mockChangeHistory({ to: 'here', from: 'there' }); - expect(tracesSampler).toHaveBeenCalledWith( - expect.objectContaining({ - location: dogParkLocation, - transactionContext: expect.objectContaining({ op: 'navigation' }), - }), - ); - }); - }); -}); From f406cf0c3829e8ab3cfbe1cd17f18064cbf390ca Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 21 Feb 2024 14:37:42 +0000 Subject: [PATCH 28/44] Random removals --- .../onLoad/customBrowserTracing/test.ts | 2 +- .../suites/tracing/envelope-header/test.ts | 2 +- packages/angular/src/tracing.ts | 2 +- packages/astro/test/client/sdk.test.ts | 8 +- .../astro/test/integration/snippets.test.ts | 2 +- packages/browser/src/helpers.ts | 36 +--- packages/browser/src/index.bundle.feedback.ts | 6 - packages/browser/src/index.bundle.replay.ts | 6 - .../index.bundle.tracing.replay.feedback.ts | 8 +- .../src/index.bundle.tracing.replay.ts | 8 +- packages/browser/src/index.bundle.tracing.ts | 8 +- packages/browser/src/index.bundle.ts | 6 - packages/browser/src/index.ts | 2 - .../test/unit/index.bundle.feedback.test.ts | 8 +- .../test/unit/index.bundle.replay.test.ts | 8 +- .../browser/test/unit/index.bundle.test.ts | 8 +- ...dex.bundle.tracing.replay.feedback.test.ts | 11 +- .../unit/index.bundle.tracing.replay.test.ts | 10 +- .../test/unit/index.bundle.tracing.test.ts | 10 +- packages/gatsby/test/sdk.test.ts | 10 +- .../src/client/browserTracingIntegration.ts | 2 +- packages/svelte/README.md | 43 ++-- .../src/client/browserTracingIntegration.ts | 21 -- packages/sveltekit/src/client/router.ts | 134 ------------ packages/sveltekit/test/client/router.test.ts | 194 ------------------ .../src/browser/browserTracingIntegration.ts | 4 +- .../tracing-internal/src/browser/index.ts | 6 +- packages/tracing-internal/src/index.ts | 2 - .../browser/browserTracingIntegration.test.ts | 6 +- packages/tracing/src/index.ts | 36 ---- packages/tracing/test/index.test.ts | 16 +- packages/types/src/client.ts | 8 +- packages/vue/src/browserTracingIntegration.ts | 2 +- 33 files changed, 68 insertions(+), 567 deletions(-) delete mode 100644 packages/sveltekit/src/client/router.ts delete mode 100644 packages/sveltekit/test/client/router.test.ts 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 64b7fb800533..12cf305fab7d 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 @@ -7,7 +7,7 @@ import { waitForTransactionRequestOnUrl, } from '../../../../utils/helpers'; -sentryTest('should handle custom added BrowserTracing integration', async ({ getLocalTestUrl, page }) => { +sentryTest('should handle custom added browserTracingIntegration instances', async ({ getLocalTestUrl, page }) => { if (shouldSkipTracingTest()) { sentryTest.skip(); } diff --git a/dev-packages/browser-integration-tests/suites/tracing/envelope-header/test.ts b/dev-packages/browser-integration-tests/suites/tracing/envelope-header/test.ts index 0d7e2b793553..6df352af5fc0 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/envelope-header/test.ts +++ b/dev-packages/browser-integration-tests/suites/tracing/envelope-header/test.ts @@ -21,7 +21,7 @@ sentryTest( // In this test, we don't expect trace.transaction to be present because without a custom routing instrumentation // we for now don't have parameterization. This might change in the future but for now the only way of having - // transaction in DSC with the default BrowserTracing integration is when the transaction name is set manually. + // transaction in DSC with the default browserTracingIntegration is when the transaction name is set manually. // This scenario is covered in another integration test (envelope-header-transaction-name). expect(envHeader.trace).toBeDefined(); expect(envHeader.trace).toEqual({ diff --git a/packages/angular/src/tracing.ts b/packages/angular/src/tracing.ts index bbfe3afd3b67..6fcff61fcbd4 100644 --- a/packages/angular/src/tracing.ts +++ b/packages/angular/src/tracing.ts @@ -67,7 +67,7 @@ export function routingInstrumentation( export const instrumentAngularRouting = routingInstrumentation; /** - * A custom BrowserTracing integration for Angular. + * A custom browser tracing integration for Angular. * * Use this integration in combination with `TraceService` */ diff --git a/packages/astro/test/client/sdk.test.ts b/packages/astro/test/client/sdk.test.ts index 311287bfc533..50f4e3c9e354 100644 --- a/packages/astro/test/client/sdk.test.ts +++ b/packages/astro/test/client/sdk.test.ts @@ -56,7 +56,7 @@ describe('Sentry client SDK', () => { ['tracesSampleRate', { tracesSampleRate: 0 }], ['tracesSampler', { tracesSampler: () => 1.0 }], ['enableTracing', { enableTracing: true }], - ])('adds the BrowserTracing integration if tracing is enabled via %s', (_, tracingOptions) => { + ])('adds browserTracingIntegration if tracing is enabled via %s', (_, tracingOptions) => { init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', ...tracingOptions, @@ -72,7 +72,7 @@ describe('Sentry client SDK', () => { it.each([ ['enableTracing', { enableTracing: false }], ['no tracing option set', {}], - ])("doesn't add the BrowserTracing integration if tracing is disabled via %s", (_, tracingOptions) => { + ])("doesn't add browserTracingIntegration if tracing is disabled via %s", (_, tracingOptions) => { init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', ...tracingOptions, @@ -85,7 +85,7 @@ describe('Sentry client SDK', () => { expect(browserTracing).toBeUndefined(); }); - it("doesn't add the BrowserTracing integration if `__SENTRY_TRACING__` is set to false", () => { + it("doesn't add browserTracingIntegration if `__SENTRY_TRACING__` is set to false", () => { globalThis.__SENTRY_TRACING__ = false; init({ @@ -102,7 +102,7 @@ describe('Sentry client SDK', () => { delete globalThis.__SENTRY_TRACING__; }); - it('Overrides the automatically default BrowserTracing instance with a a user-provided browserTracingIntegration instance', () => { + it('Overrides the automatically default browserTracingIntegration instance with a a user-provided browserTracingIntegration instance', () => { init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', integrations: [ diff --git a/packages/astro/test/integration/snippets.test.ts b/packages/astro/test/integration/snippets.test.ts index 2a08ec33315c..93743422905f 100644 --- a/packages/astro/test/integration/snippets.test.ts +++ b/packages/astro/test/integration/snippets.test.ts @@ -50,7 +50,7 @@ describe('buildClientSnippet', () => { `); }); - it('does not include BrowserTracing if tracesSampleRate is 0', () => { + it('does not include browserTracingIntegration if tracesSampleRate is 0', () => { const snippet = buildClientSnippet({ tracesSampleRate: 0 }); expect(snippet).toMatchInlineSnapshot(` "import * as Sentry from \\"@sentry/astro\\"; diff --git a/packages/browser/src/helpers.ts b/packages/browser/src/helpers.ts index 6b9df98f1751..a232d24044dc 100644 --- a/packages/browser/src/helpers.ts +++ b/packages/browser/src/helpers.ts @@ -1,7 +1,5 @@ -import type { browserTracingIntegration } from '@sentry-internal/tracing'; -import { BrowserTracing } from '@sentry-internal/tracing'; import { captureException, withScope } from '@sentry/core'; -import type { Integration, Mechanism, WrappedFunction } from '@sentry/types'; +import type { Mechanism, WrappedFunction } from '@sentry/types'; import { GLOBAL_OBJ, addExceptionMechanism, @@ -155,35 +153,3 @@ export function wrap( return sentryWrapped; } - -/** - * This is a slim shim of `browserTracingIntegration` for the CDN bundles. - * Since the actual functional integration uses a different code from `BrowserTracing`, - * we want to avoid shipping both of them in the CDN bundles, as that would blow up the size. - * Instead, we provide a functional integration with the same API, but the old implementation. - * This means that it's not possible to register custom routing instrumentation, but that's OK for now. - * We also don't expose the utilities for this anyhow in the CDN bundles. - * For users that need custom routing in CDN bundles, they have to continue using `new BrowserTracing()` until v8. - */ -export function bundleBrowserTracingIntegration( - options: Parameters[0] = {}, -): Integration { - // Migrate some options from the old integration to the new one - // eslint-disable-next-line deprecation/deprecation - const opts: ConstructorParameters[0] = options; - - if (typeof options.markBackgroundSpan === 'boolean') { - opts.markBackgroundTransactions = options.markBackgroundSpan; - } - - if (typeof options.instrumentPageLoad === 'boolean') { - opts.startTransactionOnPageLoad = options.instrumentPageLoad; - } - - if (typeof options.instrumentNavigation === 'boolean') { - opts.startTransactionOnLocationChange = options.instrumentNavigation; - } - - // eslint-disable-next-line deprecation/deprecation - return new BrowserTracing(opts); -} diff --git a/packages/browser/src/index.bundle.feedback.ts b/packages/browser/src/index.bundle.feedback.ts index 8e653c2d4757..d4c8e8bb1613 100644 --- a/packages/browser/src/index.bundle.feedback.ts +++ b/packages/browser/src/index.bundle.feedback.ts @@ -1,7 +1,6 @@ // This is exported so the loader does not fail when switching off Replay/Tracing import { Feedback, feedbackIntegration } from '@sentry-internal/feedback'; import { - BrowserTracing, Replay, addTracingExtensions, browserTracingIntegration, @@ -14,13 +13,8 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; -// eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.BrowserTracing = BrowserTracing; - export * from './index.bundle.base'; export { - // eslint-disable-next-line deprecation/deprecation - BrowserTracing, browserTracingIntegration, addTracingExtensions, // eslint-disable-next-line deprecation/deprecation diff --git a/packages/browser/src/index.bundle.replay.ts b/packages/browser/src/index.bundle.replay.ts index 2e4619ab49ea..cca0ba280642 100644 --- a/packages/browser/src/index.bundle.replay.ts +++ b/packages/browser/src/index.bundle.replay.ts @@ -1,6 +1,5 @@ // This is exported so the loader does not fail when switching off Replay/Tracing import { - BrowserTracing, Feedback, addTracingExtensions, browserTracingIntegration, @@ -14,13 +13,8 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; -// eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.BrowserTracing = BrowserTracing; - export * from './index.bundle.base'; export { - // eslint-disable-next-line deprecation/deprecation - BrowserTracing, browserTracingIntegration, addTracingExtensions, // eslint-disable-next-line deprecation/deprecation diff --git a/packages/browser/src/index.bundle.tracing.replay.feedback.ts b/packages/browser/src/index.bundle.tracing.replay.feedback.ts index 8a4a05dba6b6..fd6efc3824f4 100644 --- a/packages/browser/src/index.bundle.tracing.replay.feedback.ts +++ b/packages/browser/src/index.bundle.tracing.replay.feedback.ts @@ -1,7 +1,6 @@ import { Feedback, feedbackIntegration } from '@sentry-internal/feedback'; -import { BrowserTracing, addExtensionMethods } from '@sentry-internal/tracing'; +import { addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing'; import { Replay, replayIntegration } from '@sentry/replay'; -import { bundleBrowserTracingIntegration as browserTracingIntegration } from './helpers'; import * as Sentry from './index.bundle.base'; @@ -11,9 +10,6 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; -// eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.BrowserTracing = BrowserTracing; - // We are patching the global object with our hub extension methods addExtensionMethods(); @@ -24,8 +20,6 @@ export { Replay, feedbackIntegration, replayIntegration, - // eslint-disable-next-line deprecation/deprecation - BrowserTracing, browserTracingIntegration, addExtensionMethods, }; diff --git a/packages/browser/src/index.bundle.tracing.replay.ts b/packages/browser/src/index.bundle.tracing.replay.ts index 20bbf135ace5..dee51666e460 100644 --- a/packages/browser/src/index.bundle.tracing.replay.ts +++ b/packages/browser/src/index.bundle.tracing.replay.ts @@ -1,7 +1,6 @@ import { Feedback, feedbackIntegration } from '@sentry-internal/integration-shims'; -import { BrowserTracing, addExtensionMethods } from '@sentry-internal/tracing'; +import { addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing'; import { Replay, replayIntegration } from '@sentry/replay'; -import { bundleBrowserTracingIntegration as browserTracingIntegration } from './helpers'; import * as Sentry from './index.bundle.base'; @@ -11,9 +10,6 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; -// eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.BrowserTracing = BrowserTracing; - // We are patching the global object with our hub extension methods addExtensionMethods(); @@ -24,8 +20,6 @@ export { Replay, replayIntegration, feedbackIntegration, - // eslint-disable-next-line deprecation/deprecation - BrowserTracing, browserTracingIntegration, addExtensionMethods, }; diff --git a/packages/browser/src/index.bundle.tracing.ts b/packages/browser/src/index.bundle.tracing.ts index 5b1dc7f5d2de..20c15fc11066 100644 --- a/packages/browser/src/index.bundle.tracing.ts +++ b/packages/browser/src/index.bundle.tracing.ts @@ -1,7 +1,6 @@ // This is exported so the loader does not fail when switching off Replay import { Feedback, Replay, feedbackIntegration, replayIntegration } from '@sentry-internal/integration-shims'; -import { BrowserTracing, addExtensionMethods } from '@sentry-internal/tracing'; -import { bundleBrowserTracingIntegration as browserTracingIntegration } from './helpers'; +import { addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing'; import * as Sentry from './index.bundle.base'; @@ -11,9 +10,6 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; -// eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.BrowserTracing = BrowserTracing; - // We are patching the global object with our hub extension methods addExtensionMethods(); @@ -24,8 +20,6 @@ export { Replay, feedbackIntegration, replayIntegration, - // eslint-disable-next-line deprecation/deprecation - BrowserTracing, browserTracingIntegration, addExtensionMethods, }; diff --git a/packages/browser/src/index.bundle.ts b/packages/browser/src/index.bundle.ts index 3087d7d317ca..69a41826afe5 100644 --- a/packages/browser/src/index.bundle.ts +++ b/packages/browser/src/index.bundle.ts @@ -1,6 +1,5 @@ // This is exported so the loader does not fail when switching off Replay/Tracing import { - BrowserTracing, Feedback, Replay, addTracingExtensions, @@ -15,13 +14,8 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; -// eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.BrowserTracing = BrowserTracing; - export * from './index.bundle.base'; export { - // eslint-disable-next-line deprecation/deprecation - BrowserTracing, addTracingExtensions, // eslint-disable-next-line deprecation/deprecation Replay, diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts index 15c5adee2cc4..48005f6ce0c1 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -55,8 +55,6 @@ export { } from '@sentry-internal/feedback'; export { - // eslint-disable-next-line deprecation/deprecation - BrowserTracing, defaultRequestInstrumentationOptions, instrumentOutgoingRequests, browserTracingIntegration, diff --git a/packages/browser/test/unit/index.bundle.feedback.test.ts b/packages/browser/test/unit/index.bundle.feedback.test.ts index 5fe2940d1881..68db782291bd 100644 --- a/packages/browser/test/unit/index.bundle.feedback.test.ts +++ b/packages/browser/test/unit/index.bundle.feedback.test.ts @@ -11,11 +11,6 @@ import * as TracingReplayBundle from '../../src/index.bundle.feedback'; describe('index.bundle.feedback', () => { it('has correct exports', () => { Object.keys(TracingReplayBundle.Integrations).forEach(key => { - // Skip BrowserTracing because it doesn't have a static id field. - if (key === 'BrowserTracing') { - return; - } - expect((TracingReplayBundle.Integrations[key] as any).id).toStrictEqual(expect.any(String)); }); @@ -23,8 +18,7 @@ describe('index.bundle.feedback', () => { expect(TracingReplayBundle.Replay).toBe(ReplayShim); expect(TracingReplayBundle.replayIntegration).toBe(replayIntegrationShim); - expect(TracingReplayBundle.Integrations.BrowserTracing).toBe(BrowserTracingShim); - expect(TracingReplayBundle.BrowserTracing).toBe(BrowserTracingShim); + expect(TracingReplayBundle.browserTracingIntegration).toBe(BrowserTracingShim); expect(TracingReplayBundle.Feedback).toBe(Feedback); expect(TracingReplayBundle.feedbackIntegration).toBe(feedbackIntegration); diff --git a/packages/browser/test/unit/index.bundle.replay.test.ts b/packages/browser/test/unit/index.bundle.replay.test.ts index e2d5640a2183..c3ee1d413522 100644 --- a/packages/browser/test/unit/index.bundle.replay.test.ts +++ b/packages/browser/test/unit/index.bundle.replay.test.ts @@ -11,11 +11,6 @@ import * as TracingReplayBundle from '../../src/index.bundle.replay'; describe('index.bundle.replay', () => { it('has correct exports', () => { Object.keys(TracingReplayBundle.Integrations).forEach(key => { - // Skip BrowserTracing because it doesn't have a static id field. - if (key === 'BrowserTracing') { - return; - } - expect((TracingReplayBundle.Integrations[key] as any).id).toStrictEqual(expect.any(String)); }); @@ -23,8 +18,7 @@ describe('index.bundle.replay', () => { expect(TracingReplayBundle.Replay).toBe(Replay); expect(TracingReplayBundle.replayIntegration).toBe(replayIntegration); - expect(TracingReplayBundle.Integrations.BrowserTracing).toBe(BrowserTracingShim); - expect(TracingReplayBundle.BrowserTracing).toBe(BrowserTracingShim); + expect(TracingReplayBundle.browserTracingIntegration).toBe(BrowserTracingShim); expect(TracingReplayBundle.Feedback).toBe(FeedbackShim); expect(TracingReplayBundle.feedbackIntegration).toBe(feedbackIntegrationShim); diff --git a/packages/browser/test/unit/index.bundle.test.ts b/packages/browser/test/unit/index.bundle.test.ts index d637c8de1c3d..686e82ddef68 100644 --- a/packages/browser/test/unit/index.bundle.test.ts +++ b/packages/browser/test/unit/index.bundle.test.ts @@ -12,11 +12,6 @@ import * as TracingBundle from '../../src/index.bundle'; describe('index.bundle', () => { it('has correct exports', () => { Object.keys(TracingBundle.Integrations).forEach(key => { - // Skip BrowserTracing because it doesn't have a static id field. - if (key === 'BrowserTracing') { - return; - } - expect((TracingBundle.Integrations[key] as any).id).toStrictEqual(expect.any(String)); }); @@ -24,8 +19,7 @@ describe('index.bundle', () => { expect(TracingBundle.Replay).toBe(ReplayShim); expect(TracingBundle.replayIntegration).toBe(replayIntegrationShim); - expect(TracingBundle.Integrations.BrowserTracing).toBe(BrowserTracingShim); - expect(TracingBundle.BrowserTracing).toBe(BrowserTracingShim); + expect(TracingBundle.browserTracingIntegration).toBe(BrowserTracingShim); expect(TracingBundle.Feedback).toBe(FeedbackShim); expect(TracingBundle.feedbackIntegration).toBe(feedbackIntegrationShim); diff --git a/packages/browser/test/unit/index.bundle.tracing.replay.feedback.test.ts b/packages/browser/test/unit/index.bundle.tracing.replay.feedback.test.ts index 29b700773d92..ab01c77478c6 100644 --- a/packages/browser/test/unit/index.bundle.tracing.replay.feedback.test.ts +++ b/packages/browser/test/unit/index.bundle.tracing.replay.feedback.test.ts @@ -1,5 +1,4 @@ -/* eslint-disable deprecation/deprecation */ -import { BrowserTracing } from '@sentry-internal/tracing'; +import { browserTracingIntegration } from '@sentry-internal/tracing'; import { Feedback, Replay, feedbackIntegration, replayIntegration } from '@sentry/browser'; import * as TracingReplayFeedbackBundle from '../../src/index.bundle.tracing.replay.feedback'; @@ -7,11 +6,6 @@ import * as TracingReplayFeedbackBundle from '../../src/index.bundle.tracing.rep describe('index.bundle.tracing.replay.feedback', () => { it('has correct exports', () => { Object.keys(TracingReplayFeedbackBundle.Integrations).forEach(key => { - // Skip BrowserTracing because it doesn't have a static id field. - if (key === 'BrowserTracing') { - return; - } - expect((TracingReplayFeedbackBundle.Integrations[key] as any).id).toStrictEqual(expect.any(String)); }); @@ -19,8 +13,7 @@ describe('index.bundle.tracing.replay.feedback', () => { expect(TracingReplayFeedbackBundle.Replay).toBe(Replay); expect(TracingReplayFeedbackBundle.replayIntegration).toBe(replayIntegration); - expect(TracingReplayFeedbackBundle.Integrations.BrowserTracing).toBe(BrowserTracing); - expect(TracingReplayFeedbackBundle.BrowserTracing).toBe(BrowserTracing); + expect(TracingReplayFeedbackBundle.browserTracingIntegration).toBe(browserTracingIntegration); expect(TracingReplayFeedbackBundle.Feedback).toBe(Feedback); expect(TracingReplayFeedbackBundle.feedbackIntegration).toBe(feedbackIntegration); diff --git a/packages/browser/test/unit/index.bundle.tracing.replay.test.ts b/packages/browser/test/unit/index.bundle.tracing.replay.test.ts index 4db32003607e..039d899d51a0 100644 --- a/packages/browser/test/unit/index.bundle.tracing.replay.test.ts +++ b/packages/browser/test/unit/index.bundle.tracing.replay.test.ts @@ -3,7 +3,7 @@ import { Feedback as FeedbackShim, feedbackIntegration as feedbackIntegrationShim, } from '@sentry-internal/integration-shims'; -import { BrowserTracing } from '@sentry-internal/tracing'; +import { browserTracingIntegration } from '@sentry-internal/tracing'; import { Replay, replayIntegration } from '@sentry/browser'; import * as TracingReplayBundle from '../../src/index.bundle.tracing.replay'; @@ -11,11 +11,6 @@ import * as TracingReplayBundle from '../../src/index.bundle.tracing.replay'; describe('index.bundle.tracing.replay', () => { it('has correct exports', () => { Object.keys(TracingReplayBundle.Integrations).forEach(key => { - // Skip BrowserTracing because it doesn't have a static id field. - if (key === 'BrowserTracing') { - return; - } - expect((TracingReplayBundle.Integrations[key] as any).id).toStrictEqual(expect.any(String)); }); @@ -23,8 +18,7 @@ describe('index.bundle.tracing.replay', () => { expect(TracingReplayBundle.Replay).toBe(Replay); expect(TracingReplayBundle.replayIntegration).toBe(replayIntegration); - expect(TracingReplayBundle.Integrations.BrowserTracing).toBe(BrowserTracing); - expect(TracingReplayBundle.BrowserTracing).toBe(BrowserTracing); + expect(TracingReplayBundle.browserTracingIntegration).toBe(browserTracingIntegration); expect(TracingReplayBundle.Feedback).toBe(FeedbackShim); expect(TracingReplayBundle.feedbackIntegration).toBe(feedbackIntegrationShim); diff --git a/packages/browser/test/unit/index.bundle.tracing.test.ts b/packages/browser/test/unit/index.bundle.tracing.test.ts index cf03a26f7054..a2bf52b65710 100644 --- a/packages/browser/test/unit/index.bundle.tracing.test.ts +++ b/packages/browser/test/unit/index.bundle.tracing.test.ts @@ -5,18 +5,13 @@ import { feedbackIntegration as feedbackIntegrationShim, replayIntegration as replayIntegrationShim, } from '@sentry-internal/integration-shims'; -import { BrowserTracing } from '@sentry-internal/tracing'; +import { browserTracingIntegration } from '@sentry-internal/tracing'; import * as TracingBundle from '../../src/index.bundle.tracing'; describe('index.bundle.tracing', () => { it('has correct exports', () => { Object.keys(TracingBundle.Integrations).forEach(key => { - // Skip BrowserTracing because it doesn't have a static id field. - if (key === 'BrowserTracing') { - return; - } - expect((TracingBundle.Integrations[key] as any).id).toStrictEqual(expect.any(String)); }); @@ -24,8 +19,7 @@ describe('index.bundle.tracing', () => { expect(TracingBundle.Replay).toBe(ReplayShim); expect(TracingBundle.replayIntegration).toBe(replayIntegrationShim); - expect(TracingBundle.Integrations.BrowserTracing).toBe(BrowserTracing); - expect(TracingBundle.BrowserTracing).toBe(BrowserTracing); + expect(TracingBundle.browserTracingIntegration).toBe(browserTracingIntegration); expect(TracingBundle.Feedback).toBe(FeedbackShim); expect(TracingBundle.feedbackIntegration).toBe(feedbackIntegrationShim); diff --git a/packages/gatsby/test/sdk.test.ts b/packages/gatsby/test/sdk.test.ts index 28206d1ef6c5..7abdc82c6834 100644 --- a/packages/gatsby/test/sdk.test.ts +++ b/packages/gatsby/test/sdk.test.ts @@ -48,7 +48,7 @@ describe('Initialize React SDK', () => { }); }); - test('Has BrowserTracing if tracing enabled', () => { + test('Has browserTracingIntegration if tracing enabled', () => { gatsbyInit({ tracesSampleRate: 1 }); expect(reactInit).toHaveBeenCalledTimes(1); const calledWith = reactInit.mock.calls[0][0]; @@ -66,13 +66,13 @@ describe('Integrations from options', () => { ['tracing disabled, no integrations', [], {}, []], ['tracing enabled, no integrations', [], { tracesSampleRate: 1 }, ['BrowserTracing']], [ - 'tracing disabled, with BrowserTracing as an array', + 'tracing disabled, with browserTracingIntegration as an array', [], { integrations: [browserTracingIntegration()] }, ['BrowserTracing'], ], [ - 'tracing disabled, with BrowserTracing as a function', + 'tracing disabled, with browserTracingIntegration as a function', [], { integrations: () => [browserTracingIntegration()], @@ -80,13 +80,13 @@ describe('Integrations from options', () => { ['BrowserTracing'], ], [ - 'tracing enabled, with BrowserTracing as an array', + 'tracing enabled, with browserTracingIntegration as an array', [], { tracesSampleRate: 1, integrations: [browserTracingIntegration()] }, ['BrowserTracing'], ], [ - 'tracing enabled, with BrowserTracing as a function', + 'tracing enabled, with browserTracingIntegration as a function', [], { tracesSampleRate: 1, integrations: () => [browserTracingIntegration()] }, ['BrowserTracing'], diff --git a/packages/nextjs/src/client/browserTracingIntegration.ts b/packages/nextjs/src/client/browserTracingIntegration.ts index 42af9f9a2045..d70eb3da0746 100644 --- a/packages/nextjs/src/client/browserTracingIntegration.ts +++ b/packages/nextjs/src/client/browserTracingIntegration.ts @@ -7,7 +7,7 @@ import type { Integration, StartSpanOptions } from '@sentry/types'; import { nextRouterInstrumentation } from './routing/nextRoutingInstrumentation'; /** - * A custom BrowserTracing integration for Next.js. + * A custom browser tracing integration for Next.js. */ export function browserTracingIntegration( options: Parameters[0] = {}, diff --git a/packages/svelte/README.md b/packages/svelte/README.md index 5ea7bbed0fb8..bccd18a3c744 100644 --- a/packages/svelte/README.md +++ b/packages/svelte/README.md @@ -10,28 +10,29 @@ [![npm dm](https://img.shields.io/npm/dm/@sentry/svelte.svg)](https://www.npmjs.com/package/@sentry/svelte) [![npm dt](https://img.shields.io/npm/dt/@sentry/svelte.svg)](https://www.npmjs.com/package/@sentry/svelte) -This SDK currently only supports [Svelte](https://svelte.dev/) apps in the browser. -If you're using SvelteKit, we recommend using our dedicated [Sentry SvelteKit SDK](https://github.com/getsentry/sentry-javascript/tree/develop/packages/sveltekit). +This SDK currently only supports [Svelte](https://svelte.dev/) apps in the browser. If you're using SvelteKit, we +recommend using our dedicated +[Sentry SvelteKit SDK](https://github.com/getsentry/sentry-javascript/tree/develop/packages/sveltekit). ## General -This package is a wrapper around `@sentry/browser`, providing error monitoring and basic performance monitoring -features for [Svelte](https://svelte.dev/). +This package is a wrapper around `@sentry/browser`, providing error monitoring and basic performance monitoring features +for [Svelte](https://svelte.dev/). To use the SDK, initialize Sentry in your Svelte entry point `main.js` before you bootstrap your Svelte app: ```ts // main.js / main.ts -import App from "./App.svelte"; +import App from './App.svelte'; -import * as Sentry from "@sentry/svelte"; +import * as Sentry from '@sentry/svelte'; // Initialize the Sentry SDK here Sentry.init({ - dsn: "__DSN__", - release: "my-project-name@2.3.12", - integrations: [new Sentry.BrowserTracing()], + dsn: '__DSN__', + release: 'my-project-name@2.3.12', + integrations: [Sentry.browserTracingIntegration()], // Set tracesSampleRate to 1.0 to capture 100% // of transactions for performance monitoring. @@ -41,19 +42,25 @@ Sentry.init({ // Then bootstrap your Svelte app const app = new App({ - target: document.getElementById("app"), + target: document.getElementById('app'), }); export default app; ``` -The Sentry Svelte SDK supports all features from the `@sentry/browser` SDK. Until it becomes more stable, please refer to the Sentry [Browser SDK documentation](https://docs.sentry.io/platforms/javascript/) for more information and usage instructions. +The Sentry Svelte SDK supports all features from the `@sentry/browser` SDK. Until it becomes more stable, please refer +to the Sentry [Browser SDK documentation](https://docs.sentry.io/platforms/javascript/) for more information and usage +instructions. ## Sourcemaps and Releases -To generate source maps of your Svelte app bundle, check our guide [how to configure your bundler](https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps/generating/) to emit source maps. +To generate source maps of your Svelte app bundle, check our guide +[how to configure your bundler](https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps/generating/) to +emit source maps. -To [create releases and upload source maps](https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/) to Sentry, we recommend using [`sentry-cli`](https://github.com/getsentry/sentry-cli). You can for instance create a bash script to take care of creating a release, uploading source maps and finalizing the release: +To [create releases and upload source maps](https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/) to +Sentry, we recommend using [`sentry-cli`](https://github.com/getsentry/sentry-cli). You can for instance create a bash +script to take care of creating a release, uploading source maps and finalizing the release: ```bash #!/bin/bash @@ -69,6 +76,12 @@ sentry-cli releases files $VERSION upload-sourcemaps $SOURCEMAPS_PATH --org $ORG sentry-cli releases finalize $VERSION --org $ORG --project $PROJECT ``` -Please note that the paths provided in this example work for a typical Svelte project that adheres to the project structure set by [create-vite](https://www.npmjs.com/package/create-vite) with the `svelte(-ts)` template. If your project setup differs from this template, your configuration may need adjustments. Please refer to our documentation of [Advanced `sentry-cli` Sourcemaps Options](https://docs.sentry.io/product/cli/releases/#sentry-cli-sourcemaps) and to our [Sourcemaps Troubleshooting Guide](https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js/). +Please note that the paths provided in this example work for a typical Svelte project that adheres to the project +structure set by [create-vite](https://www.npmjs.com/package/create-vite) with the `svelte(-ts)` template. If your +project setup differs from this template, your configuration may need adjustments. Please refer to our documentation of +[Advanced `sentry-cli` Sourcemaps Options](https://docs.sentry.io/product/cli/releases/#sentry-cli-sourcemaps) and to +our [Sourcemaps Troubleshooting Guide](https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js/). -Check out our [Svelte source maps uploading](https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps/uploading/) guide for more information. +Check out our +[Svelte source maps uploading](https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps/uploading/) guide +for more information. diff --git a/packages/sveltekit/src/client/browserTracingIntegration.ts b/packages/sveltekit/src/client/browserTracingIntegration.ts index 07de01e86c11..e0e9d495a7f0 100644 --- a/packages/sveltekit/src/client/browserTracingIntegration.ts +++ b/packages/sveltekit/src/client/browserTracingIntegration.ts @@ -1,7 +1,6 @@ import { navigating, page } from '$app/stores'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; import { - BrowserTracing as OriginalBrowserTracing, WINDOW, browserTracingIntegration as originalBrowserTracingIntegration, startBrowserTracingNavigationSpan, @@ -10,26 +9,6 @@ import { } from '@sentry/svelte'; import type { Client, Integration, Span } from '@sentry/types'; import { dropUndefinedKeys } from '@sentry/utils'; -import { svelteKitRoutingInstrumentation } from './router'; - -/** - * A custom BrowserTracing integration for Sveltekit. - * - * @deprecated use `browserTracingIntegration()` instead. The new `browserTracingIntegration()` - * includes SvelteKit-specific routing instrumentation out of the box. Therefore there's no need - * to pass in `svelteKitRoutingInstrumentation` anymore. - */ -// eslint-disable-next-line deprecation/deprecation -export class BrowserTracing extends OriginalBrowserTracing { - // eslint-disable-next-line deprecation/deprecation - public constructor(options?: ConstructorParameters[0]) { - super({ - // eslint-disable-next-line deprecation/deprecation - routingInstrumentation: svelteKitRoutingInstrumentation, - ...options, - }); - } -} /** * A custom `BrowserTracing` integration for SvelteKit. diff --git a/packages/sveltekit/src/client/router.ts b/packages/sveltekit/src/client/router.ts deleted file mode 100644 index 593eeb97b1a2..000000000000 --- a/packages/sveltekit/src/client/router.ts +++ /dev/null @@ -1,134 +0,0 @@ -import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getActiveTransaction } from '@sentry/core'; -import { WINDOW } from '@sentry/svelte'; -import type { Span, Transaction, TransactionContext } from '@sentry/types'; - -import { navigating, page } from '$app/stores'; - -const DEFAULT_TAGS = { - 'routing.instrumentation': '@sentry/sveltekit', -}; - -/** - * Automatically creates pageload and navigation transactions for the client-side SvelteKit router. - * - * This instrumentation makes use of SvelteKit's `page` and `navigating` stores which can be accessed - * anywhere on the client side. - * - * @param startTransactionFn the function used to start (idle) transactions - * @param startTransactionOnPageLoad controls if pageload transactions should be created (defaults to `true`) - * @param startTransactionOnLocationChange controls if navigation transactions should be created (defauls to `true`) - * - * @deprecated use `browserTracingIntegration()` instead which includes SvelteKit-specific routing instrumentation out of the box. - * Therefore, this function will be removed in v8. - */ -export function svelteKitRoutingInstrumentation( - startTransactionFn: (context: TransactionContext) => T | undefined, - startTransactionOnPageLoad: boolean = true, - startTransactionOnLocationChange: boolean = true, -): void { - if (startTransactionOnPageLoad) { - instrumentPageload(startTransactionFn); - } - - if (startTransactionOnLocationChange) { - instrumentNavigations(startTransactionFn); - } -} - -function instrumentPageload(startTransactionFn: (context: TransactionContext) => Transaction | undefined): void { - const initialPath = WINDOW && WINDOW.location && WINDOW.location.pathname; - - const pageloadTransaction = startTransactionFn({ - name: initialPath, - op: 'pageload', - origin: 'auto.pageload.sveltekit', - description: initialPath, - tags: { - ...DEFAULT_TAGS, - }, - attributes: { - [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', - }, - }); - - page.subscribe(page => { - if (!page) { - return; - } - - const routeId = page.route && page.route.id; - - if (pageloadTransaction && routeId) { - pageloadTransaction.updateName(routeId); - pageloadTransaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route'); - } - }); -} - -/** - * Use the `navigating` store to start a transaction on navigations. - */ -function instrumentNavigations(startTransactionFn: (context: TransactionContext) => Transaction | undefined): void { - let routingSpan: Span | undefined = undefined; - let activeTransaction: Transaction | undefined; - - navigating.subscribe(navigation => { - if (!navigation) { - // `navigating` emits a 'null' value when the navigation is completed. - // So in this case, we can finish the routing span. If the transaction was an IdleTransaction, - // it will finish automatically and if it was user-created users also need to finish it. - if (routingSpan) { - routingSpan.end(); - routingSpan = undefined; - } - return; - } - - const from = navigation.from; - const to = navigation.to; - - // for the origin we can fall back to window.location.pathname because in this emission, it still is set to the origin path - const rawRouteOrigin = (from && from.url.pathname) || (WINDOW && WINDOW.location && WINDOW.location.pathname); - - const rawRouteDestination = to && to.url.pathname; - - // We don't want to create transactions for navigations of same origin and destination. - // We need to look at the raw URL here because parameterized routes can still differ in their raw parameters. - if (rawRouteOrigin === rawRouteDestination) { - return; - } - - const parameterizedRouteOrigin = from && from.route.id; - const parameterizedRouteDestination = to && to.route.id; - - // eslint-disable-next-line deprecation/deprecation - activeTransaction = getActiveTransaction(); - - if (!activeTransaction) { - activeTransaction = startTransactionFn({ - name: parameterizedRouteDestination || rawRouteDestination || 'unknown', - op: 'navigation', - origin: 'auto.navigation.sveltekit', - attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: parameterizedRouteDestination ? 'route' : 'url' }, - tags: { - ...DEFAULT_TAGS, - }, - }); - } - - if (activeTransaction) { - if (routingSpan) { - // If a routing span is still open from a previous navigation, we finish it. - routingSpan.end(); - } - // eslint-disable-next-line deprecation/deprecation - routingSpan = activeTransaction.startChild({ - op: 'ui.sveltekit.routing', - description: 'SvelteKit Route Change', - origin: 'auto.ui.sveltekit', - }); - // eslint-disable-next-line deprecation/deprecation - activeTransaction.setTag('from', parameterizedRouteOrigin); - } - }); -} diff --git a/packages/sveltekit/test/client/router.test.ts b/packages/sveltekit/test/client/router.test.ts deleted file mode 100644 index a359a9dedbf0..000000000000 --- a/packages/sveltekit/test/client/router.test.ts +++ /dev/null @@ -1,194 +0,0 @@ -/* eslint-disable @typescript-eslint/unbound-method */ -import type { Transaction } from '@sentry/types'; -import { writable } from 'svelte/store'; -import type { SpyInstance } from 'vitest'; -import { vi } from 'vitest'; - -import { navigating, page } from '$app/stores'; - -import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; -import { svelteKitRoutingInstrumentation } from '../../src/client/router'; - -// we have to overwrite the global mock from `vitest.setup.ts` here to reset the -// `navigating` store for each test. -vi.mock('$app/stores', async () => { - return { - get navigating() { - return navigatingStore; - }, - page: writable(), - }; -}); - -let navigatingStore = writable(); - -describe('sveltekitRoutingInstrumentation', () => { - let returnedTransaction: (Transaction & { returnedTransaction: SpyInstance }) | undefined; - const mockedStartTransaction = vi.fn().mockImplementation(txnCtx => { - returnedTransaction = { - ...txnCtx, - updateName: vi.fn(), - setAttribute: vi.fn(), - startChild: vi.fn().mockImplementation(ctx => { - return { ...mockedRoutingSpan, ...ctx }; - }), - setTag: vi.fn(), - }; - return returnedTransaction; - }); - - const mockedRoutingSpan = { - end: () => {}, - }; - - const routingSpanFinishSpy = vi.spyOn(mockedRoutingSpan, 'end'); - - beforeEach(() => { - navigatingStore = writable(); - vi.clearAllMocks(); - }); - - it("starts a pageload transaction when it's called with default params", () => { - // eslint-disable-next-line deprecation/deprecation - svelteKitRoutingInstrumentation(mockedStartTransaction); - - expect(mockedStartTransaction).toHaveBeenCalledTimes(1); - expect(mockedStartTransaction).toHaveBeenCalledWith({ - name: '/', - op: 'pageload', - origin: 'auto.pageload.sveltekit', - description: '/', - tags: { - 'routing.instrumentation': '@sentry/sveltekit', - }, - attributes: { - [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', - }, - }); - - // We emit an update to the `page` store to simulate the SvelteKit router lifecycle - page.set({ route: { id: 'testRoute' } }); - - // This should update the transaction name with the parameterized route: - expect(returnedTransaction?.updateName).toHaveBeenCalledTimes(1); - expect(returnedTransaction?.updateName).toHaveBeenCalledWith('testRoute'); - expect(returnedTransaction?.setAttribute).toHaveBeenCalledWith(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route'); - }); - - it("doesn't start a pageload transaction if `startTransactionOnPageLoad` is false", () => { - // eslint-disable-next-line deprecation/deprecation - svelteKitRoutingInstrumentation(mockedStartTransaction, false); - expect(mockedStartTransaction).toHaveBeenCalledTimes(0); - }); - - it("doesn't start a navigation transaction when `startTransactionOnLocationChange` is false", () => { - // eslint-disable-next-line deprecation/deprecation - svelteKitRoutingInstrumentation(mockedStartTransaction, false, false); - - // We emit an update to the `navigating` store to simulate the SvelteKit navigation lifecycle - navigating.set({ - from: { route: { id: '/users' }, url: { pathname: '/users' } }, - to: { route: { id: '/users/[id]' }, url: { pathname: '/users/7762' } }, - }); - - // This should update the transaction name with the parameterized route: - expect(mockedStartTransaction).toHaveBeenCalledTimes(0); - }); - - it('starts a navigation transaction when `startTransactionOnLocationChange` is true', () => { - // eslint-disable-next-line deprecation/deprecation - svelteKitRoutingInstrumentation(mockedStartTransaction, false, true); - - // We emit an update to the `navigating` store to simulate the SvelteKit navigation lifecycle - navigating.set({ - from: { route: { id: '/users' }, url: { pathname: '/users' } }, - to: { route: { id: '/users/[id]' }, url: { pathname: '/users/7762' } }, - }); - - // This should update the transaction name with the parameterized route: - expect(mockedStartTransaction).toHaveBeenCalledTimes(1); - expect(mockedStartTransaction).toHaveBeenCalledWith({ - name: '/users/[id]', - op: 'navigation', - origin: 'auto.navigation.sveltekit', - attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route' }, - tags: { - 'routing.instrumentation': '@sentry/sveltekit', - }, - }); - - // eslint-disable-next-line deprecation/deprecation - expect(returnedTransaction?.startChild).toHaveBeenCalledWith({ - op: 'ui.sveltekit.routing', - origin: 'auto.ui.sveltekit', - description: 'SvelteKit Route Change', - }); - - // eslint-disable-next-line deprecation/deprecation - expect(returnedTransaction?.setTag).toHaveBeenCalledWith('from', '/users'); - - // We emit `null` here to simulate the end of the navigation lifecycle - navigating.set(null); - - expect(routingSpanFinishSpy).toHaveBeenCalledTimes(1); - }); - - describe('handling same origin and destination navigations', () => { - it("doesn't start a navigation transaction if the raw navigation origin and destination are equal", () => { - // eslint-disable-next-line deprecation/deprecation - svelteKitRoutingInstrumentation(mockedStartTransaction, false, true); - - // We emit an update to the `navigating` store to simulate the SvelteKit navigation lifecycle - navigating.set({ - from: { route: { id: '/users/[id]' }, url: { pathname: '/users/7762' } }, - to: { route: { id: '/users/[id]' }, url: { pathname: '/users/7762' } }, - }); - - expect(mockedStartTransaction).toHaveBeenCalledTimes(0); - }); - - it('starts a navigation transaction if the raw navigation origin and destination are not equal', () => { - // eslint-disable-next-line deprecation/deprecation - svelteKitRoutingInstrumentation(mockedStartTransaction, false, true); - - navigating.set({ - from: { route: { id: '/users/[id]' }, url: { pathname: '/users/7762' } }, - to: { route: { id: '/users/[id]' }, url: { pathname: '/users/223412' } }, - }); - - expect(mockedStartTransaction).toHaveBeenCalledTimes(1); - expect(mockedStartTransaction).toHaveBeenCalledWith({ - name: '/users/[id]', - op: 'navigation', - origin: 'auto.navigation.sveltekit', - attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route' }, - tags: { - 'routing.instrumentation': '@sentry/sveltekit', - }, - }); - - // eslint-disable-next-line deprecation/deprecation - expect(returnedTransaction?.startChild).toHaveBeenCalledWith({ - op: 'ui.sveltekit.routing', - origin: 'auto.ui.sveltekit', - description: 'SvelteKit Route Change', - }); - - // eslint-disable-next-line deprecation/deprecation - expect(returnedTransaction?.setTag).toHaveBeenCalledWith('from', '/users/[id]'); - }); - - it('falls back to `window.location.pathname` to determine the raw origin', () => { - // eslint-disable-next-line deprecation/deprecation - svelteKitRoutingInstrumentation(mockedStartTransaction, false, true); - - // window.location.pathame is "/" in tests - - navigating.set({ - to: { route: {}, url: { pathname: '/' } }, - }); - - expect(mockedStartTransaction).toHaveBeenCalledTimes(0); - }); - }); -}); diff --git a/packages/tracing-internal/src/browser/browserTracingIntegration.ts b/packages/tracing-internal/src/browser/browserTracingIntegration.ts index aaa4ba341036..3686b064a474 100644 --- a/packages/tracing-internal/src/browser/browserTracingIntegration.ts +++ b/packages/tracing-internal/src/browser/browserTracingIntegration.ts @@ -385,7 +385,7 @@ export const browserTracingIntegration = ((_options: Partial { ); setCurrentClient(client); - // pageload transactions are created as part of the BrowserTracing integration's initialization + // pageload transactions are created as part of the browserTracingIntegration's initialization client.init(); const transaction = getActiveTransaction() as IdleTransaction; @@ -705,7 +705,7 @@ describe('browserTracingIntegration', () => { ); setCurrentClient(client); - // pageload transactions are created as part of the BrowserTracing integration's initialization + // pageload transactions are created as part of the browserTracingIntegration's initialization client.init(); const transaction = getActiveTransaction() as IdleTransaction; @@ -731,7 +731,7 @@ describe('browserTracingIntegration', () => { ); setCurrentClient(client); - // pageload transactions are created as part of the BrowserTracing integration's initialization + // pageload transactions are created as part of the browserTracingIntegration's initialization client.init(); // this is what is used to get the span name - JSDOM does not update this on it's own! diff --git a/packages/tracing/src/index.ts b/packages/tracing/src/index.ts index 2887963e1149..c8f9132edc29 100644 --- a/packages/tracing/src/index.ts +++ b/packages/tracing/src/index.ts @@ -5,7 +5,6 @@ import type { import { Apollo, BROWSER_TRACING_INTEGRATION_ID as BROWSER_TRACING_INTEGRATION_ID_T, - BrowserTracing as BrowserTracingT, Express, GraphQL, IdleTransaction as IdleTransactionT, @@ -25,32 +24,6 @@ import { stripUrlQueryAndFragment as stripUrlQueryAndFragmentT, } from '@sentry-internal/tracing'; -// BrowserTracing is already exported as part of `Integrations` below (and for the moment will remain so for -// backwards compatibility), but that interferes with treeshaking, so we also export it separately -// here. -/** - * @deprecated `@sentry/tracing` has been deprecated and will be moved to to `@sentry/node`, `@sentry/browser`, or your framework SDK in the next major version. - * `BrowserTracing` can be imported from `@sentry/browser` or your framework SDK - * - * import { BrowserTracing } from '@sentry/browser'; - * new BrowserTracing() - */ -// eslint-disable-next-line deprecation/deprecation -export const BrowserTracing = BrowserTracingT; - -// BrowserTracing is already exported as part of `Integrations` below (and for the moment will remain so for -// backwards compatibility), but that interferes with treeshaking, so we also export it separately -// here. -/** - * @deprecated `@sentry/tracing` has been deprecated and will be moved to to `@sentry/node`, `@sentry/browser`, or your framework SDK in the next major version. - * `BrowserTracing` can be imported from `@sentry/browser` or your framework SDK - * - * import { BrowserTracing } from '@sentry/browser'; - * new BrowserTracing() - */ -// eslint-disable-next-line deprecation/deprecation -export type BrowserTracing = BrowserTracingT; - /** * @deprecated `@sentry/tracing` has been deprecated and will be moved to to `@sentry/node`, `@sentry/browser`, or your framework SDK in the next major version. */ @@ -156,15 +129,6 @@ export type SpanStatus = SpanStatusT; export type RequestInstrumentationOptions = RequestInstrumentationOptionsT; export const Integrations = { - /** - * @deprecated `@sentry/tracing` has been deprecated and will be moved to to `@sentry/node`, `@sentry/browser`, or your framework SDK in the next major version. - * `BrowserTracing` can be imported from `@sentry/browser` or your framework SDK - * - * import { BrowserTracing } from '@sentry/browser'; - * new BrowserTracing() - */ - // eslint-disable-next-line deprecation/deprecation - BrowserTracing: BrowserTracing, /** * @deprecated `@sentry/tracing` has been deprecated and will be moved to to `@sentry/node`, `@sentry/browser`, or your framework SDK in the next major version. * `Apollo` can be imported from `@sentry/node` diff --git a/packages/tracing/test/index.test.ts b/packages/tracing/test/index.test.ts index ea35353868ca..94943132eda2 100644 --- a/packages/tracing/test/index.test.ts +++ b/packages/tracing/test/index.test.ts @@ -1,6 +1,6 @@ import { getCurrentHub } from '@sentry/core'; -import { BrowserTracing, Integrations } from '../src'; +import { Integrations } from '../src'; describe('index', () => { it('patches the global hub to add an implementation for `Hub.startTransaction` as a side effect', () => { @@ -14,20 +14,8 @@ describe('index', () => { describe('Integrations', () => { it('is exported correctly', () => { Object.keys(Integrations).forEach(key => { - // Skip BrowserTracing because it doesn't have a static id field. - if (key === 'BrowserTracing') { - return; - } - - expect(Integrations[key as keyof Omit].id).toStrictEqual( - expect.any(String), - ); + expect(Integrations[key].id).toStrictEqual(expect.any(String)); }); }); - - it('contains BrowserTracing', () => { - // eslint-disable-next-line deprecation/deprecation - expect(Integrations.BrowserTracing).toEqual(BrowserTracing); - }); }); }); diff --git a/packages/types/src/client.ts b/packages/types/src/client.ts index 62956f0c00d0..466ca3da6fa5 100644 --- a/packages/types/src/client.ts +++ b/packages/types/src/client.ts @@ -254,12 +254,12 @@ export interface Client { ): void; /** - * A hook for BrowserTracing to trigger a span start for a page load. + * A hook for the browser tracing integrations to trigger a span start for a page load. */ on(hook: 'startPageLoadSpan', callback: (options: StartSpanOptions) => void): void; /** - * A hook for BrowserTracing to trigger a span for a navigation. + * A hook for browser tracing integrations to trigger a span for a navigation. */ on(hook: 'startNavigationSpan', callback: (options: StartSpanOptions) => void): void; @@ -335,12 +335,12 @@ export interface Client { emit(hook: 'beforeSendFeedback', feedback: FeedbackEvent, options?: { includeReplay?: boolean }): void; /** - * Emit a hook event for BrowserTracing to trigger a span start for a page load. + * Emit a hook event for browser tracing integrations to trigger a span start for a page load. */ emit(hook: 'startPageLoadSpan', options: StartSpanOptions): void; /** - * Emit a hook event for BrowserTracing to trigger a span for a navigation. + * Emit a hook event for browser tracing integrations to trigger a span for a navigation. */ emit(hook: 'startNavigationSpan', options: StartSpanOptions): void; diff --git a/packages/vue/src/browserTracingIntegration.ts b/packages/vue/src/browserTracingIntegration.ts index d78bdd992d6b..e3d178628724 100644 --- a/packages/vue/src/browserTracingIntegration.ts +++ b/packages/vue/src/browserTracingIntegration.ts @@ -44,7 +44,7 @@ type VueBrowserTracingIntegrationOptions = Parameters Date: Wed, 21 Feb 2024 15:41:28 +0000 Subject: [PATCH 29/44] . --- packages/browser/test/unit/index.bundle.feedback.test.ts | 2 +- packages/browser/test/unit/index.bundle.replay.test.ts | 2 +- packages/browser/test/unit/index.bundle.test.ts | 2 +- packages/integration-shims/src/BrowserTracing.ts | 2 +- packages/tracing/test/index.test.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/browser/test/unit/index.bundle.feedback.test.ts b/packages/browser/test/unit/index.bundle.feedback.test.ts index 68db782291bd..726a0338b7a7 100644 --- a/packages/browser/test/unit/index.bundle.feedback.test.ts +++ b/packages/browser/test/unit/index.bundle.feedback.test.ts @@ -18,7 +18,7 @@ describe('index.bundle.feedback', () => { expect(TracingReplayBundle.Replay).toBe(ReplayShim); expect(TracingReplayBundle.replayIntegration).toBe(replayIntegrationShim); - expect(TracingReplayBundle.browserTracingIntegration).toBe(BrowserTracingShim); + expect(TracingReplayBundle.browserTracingIntegration()).toBeInstanceOf(BrowserTracingShim); expect(TracingReplayBundle.Feedback).toBe(Feedback); expect(TracingReplayBundle.feedbackIntegration).toBe(feedbackIntegration); diff --git a/packages/browser/test/unit/index.bundle.replay.test.ts b/packages/browser/test/unit/index.bundle.replay.test.ts index c3ee1d413522..aa291909110d 100644 --- a/packages/browser/test/unit/index.bundle.replay.test.ts +++ b/packages/browser/test/unit/index.bundle.replay.test.ts @@ -18,7 +18,7 @@ describe('index.bundle.replay', () => { expect(TracingReplayBundle.Replay).toBe(Replay); expect(TracingReplayBundle.replayIntegration).toBe(replayIntegration); - expect(TracingReplayBundle.browserTracingIntegration).toBe(BrowserTracingShim); + expect(TracingReplayBundle.browserTracingIntegration()).toBe(BrowserTracingShim); expect(TracingReplayBundle.Feedback).toBe(FeedbackShim); expect(TracingReplayBundle.feedbackIntegration).toBe(feedbackIntegrationShim); diff --git a/packages/browser/test/unit/index.bundle.test.ts b/packages/browser/test/unit/index.bundle.test.ts index 686e82ddef68..94733643ab6d 100644 --- a/packages/browser/test/unit/index.bundle.test.ts +++ b/packages/browser/test/unit/index.bundle.test.ts @@ -19,7 +19,7 @@ describe('index.bundle', () => { expect(TracingBundle.Replay).toBe(ReplayShim); expect(TracingBundle.replayIntegration).toBe(replayIntegrationShim); - expect(TracingBundle.browserTracingIntegration).toBe(BrowserTracingShim); + expect(TracingBundle.browserTracingIntegration()).toBe(BrowserTracingShim); expect(TracingBundle.Feedback).toBe(FeedbackShim); expect(TracingBundle.feedbackIntegration).toBe(feedbackIntegrationShim); diff --git a/packages/integration-shims/src/BrowserTracing.ts b/packages/integration-shims/src/BrowserTracing.ts index 1c68faf30469..50b91b984952 100644 --- a/packages/integration-shims/src/BrowserTracing.ts +++ b/packages/integration-shims/src/BrowserTracing.ts @@ -41,7 +41,7 @@ class BrowserTracingShim implements Integration { * It is needed in order for the CDN bundles to continue working when users add/remove tracing * from it, without changing their config. This is necessary for the loader mechanism. */ -function browserTracingIntegrationShim(_options: unknown): Integration { +function browserTracingIntegrationShim(_options?: unknown): Integration { // eslint-disable-next-line deprecation/deprecation return new BrowserTracingShim({}); } diff --git a/packages/tracing/test/index.test.ts b/packages/tracing/test/index.test.ts index 94943132eda2..d094f43128b0 100644 --- a/packages/tracing/test/index.test.ts +++ b/packages/tracing/test/index.test.ts @@ -14,7 +14,7 @@ describe('index', () => { describe('Integrations', () => { it('is exported correctly', () => { Object.keys(Integrations).forEach(key => { - expect(Integrations[key].id).toStrictEqual(expect.any(String)); + expect((Integrations as any)[key].id).toStrictEqual(expect.any(String)); }); }); }); From 46942eb4cccb3cb71e123156e01aba3d8fb9577f Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 21 Feb 2024 15:45:59 +0000 Subject: [PATCH 30/44] . --- packages/browser/test/unit/index.bundle.replay.test.ts | 2 +- packages/browser/test/unit/index.bundle.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/browser/test/unit/index.bundle.replay.test.ts b/packages/browser/test/unit/index.bundle.replay.test.ts index aa291909110d..f653f3722ce8 100644 --- a/packages/browser/test/unit/index.bundle.replay.test.ts +++ b/packages/browser/test/unit/index.bundle.replay.test.ts @@ -18,7 +18,7 @@ describe('index.bundle.replay', () => { expect(TracingReplayBundle.Replay).toBe(Replay); expect(TracingReplayBundle.replayIntegration).toBe(replayIntegration); - expect(TracingReplayBundle.browserTracingIntegration()).toBe(BrowserTracingShim); + expect(TracingReplayBundle.browserTracingIntegration()).toBeInstanceOf(BrowserTracingShim); expect(TracingReplayBundle.Feedback).toBe(FeedbackShim); expect(TracingReplayBundle.feedbackIntegration).toBe(feedbackIntegrationShim); diff --git a/packages/browser/test/unit/index.bundle.test.ts b/packages/browser/test/unit/index.bundle.test.ts index 94733643ab6d..f141117a173b 100644 --- a/packages/browser/test/unit/index.bundle.test.ts +++ b/packages/browser/test/unit/index.bundle.test.ts @@ -19,7 +19,7 @@ describe('index.bundle', () => { expect(TracingBundle.Replay).toBe(ReplayShim); expect(TracingBundle.replayIntegration).toBe(replayIntegrationShim); - expect(TracingBundle.browserTracingIntegration()).toBe(BrowserTracingShim); + expect(TracingBundle.browserTracingIntegration()).toBeInstanceOf(BrowserTracingShim); expect(TracingBundle.Feedback).toBe(FeedbackShim); expect(TracingBundle.feedbackIntegration).toBe(feedbackIntegrationShim); From a2acf461cb0d2ed0f0d8c23996d984f2003f5d0f Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 21 Feb 2024 15:55:42 +0000 Subject: [PATCH 31/44] . --- .../browser/browserTracingIntegration.test.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts b/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts index af2ea293da8a..b2f8859a1a06 100644 --- a/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts +++ b/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts @@ -1,5 +1,5 @@ +import type { IdleTransaction } from '@sentry/core'; import { - IdleTransaction, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, @@ -680,13 +680,19 @@ describe('browserTracingIntegration', () => { // pageload transactions are created as part of the browserTracingIntegration's initialization client.init(); + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction() as IdleTransaction; + // eslint-disable-next-line deprecation/deprecation const dynamicSamplingContext = transaction.getDynamicSamplingContext()!; expect(transaction).toBeDefined(); + // eslint-disable-next-line deprecation/deprecation expect(transaction.op).toBe('pageload'); + // eslint-disable-next-line deprecation/deprecation expect(transaction.traceId).toEqual('12312012123120121231201212312012'); + // eslint-disable-next-line deprecation/deprecation expect(transaction.parentSpanId).toEqual('1121201211212012'); + // eslint-disable-next-line deprecation/deprecation expect(transaction.sampled).toBe(false); expect(dynamicSamplingContext).toBeDefined(); expect(dynamicSamplingContext).toStrictEqual({ release: '2.1.14' }); @@ -708,13 +714,19 @@ describe('browserTracingIntegration', () => { // pageload transactions are created as part of the browserTracingIntegration's initialization client.init(); + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction() as IdleTransaction; + // eslint-disable-next-line deprecation/deprecation const dynamicSamplingContext = transaction.getDynamicSamplingContext()!; expect(transaction).toBeDefined(); + // eslint-disable-next-line deprecation/deprecation expect(transaction.op).toBe('pageload'); + // eslint-disable-next-line deprecation/deprecation expect(transaction.traceId).toEqual('12312012123120121231201212312012'); + // eslint-disable-next-line deprecation/deprecation expect(transaction.parentSpanId).toEqual('1121201211212012'); + // eslint-disable-next-line deprecation/deprecation expect(transaction.sampled).toBe(false); expect(dynamicSamplingContext).toStrictEqual({}); }); @@ -740,12 +752,17 @@ describe('browserTracingIntegration', () => { WINDOW.history.pushState({}, '', '/navigation-test'); + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction() as IdleTransaction; + // eslint-disable-next-line deprecation/deprecation const dynamicSamplingContext = transaction.getDynamicSamplingContext()!; expect(transaction).toBeDefined(); + // eslint-disable-next-line deprecation/deprecation expect(transaction.op).toBe('navigation'); + // eslint-disable-next-line deprecation/deprecation expect(transaction.traceId).not.toEqual('12312012123120121231201212312012'); + // eslint-disable-next-line deprecation/deprecation expect(transaction.parentSpanId).toBeUndefined(); expect(dynamicSamplingContext).toMatchObject({ trace_id: expect.not.stringMatching('12312012123120121231201212312012'), @@ -767,10 +784,12 @@ describe('browserTracingIntegration', () => { client.init(); const mockFinish = jest.fn(); + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction() as IdleTransaction; transaction.sendAutoFinishSignal(); transaction.end = mockFinish; + // eslint-disable-next-line deprecation/deprecation const span = transaction.startChild(); // activities = 1 span.end(); // activities = 0 @@ -792,10 +811,12 @@ describe('browserTracingIntegration', () => { client.init(); const mockFinish = jest.fn(); + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction() as IdleTransaction; transaction.sendAutoFinishSignal(); transaction.end = mockFinish; + // eslint-disable-next-line deprecation/deprecation const span = transaction.startChild(); // activities = 1 span.end(); // activities = 0 @@ -806,7 +827,8 @@ describe('browserTracingIntegration', () => { }); // TODO(lforst): I cannot manage to get this test to pass. - it.skip('heartbeatInterval can be a custom value', () => { + /* + it('heartbeatInterval can be a custom value', () => { jest.useFakeTimers(); const interval = 200; @@ -822,6 +844,7 @@ describe('browserTracingIntegration', () => { client.init(); const mockFinish = jest.fn(); + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction() as IdleTransaction; transaction.sendAutoFinishSignal(); transaction.end = mockFinish; @@ -833,4 +856,5 @@ describe('browserTracingIntegration', () => { jest.advanceTimersByTime(interval * 3); expect(mockFinish).toHaveBeenCalledTimes(1); }); + */ }); From b6ad00c52e96655ebd6af2a073cd6ed194d5d7b6 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 21 Feb 2024 16:03:22 +0000 Subject: [PATCH 32/44] remove BrowserTracing browser integration tests --- .../backgroundtab-custom/init.js | 9 -- .../backgroundtab-custom/subject.js | 16 --- .../backgroundtab-custom/template.html | 10 -- .../backgroundtab-custom/test.ts | 37 ------ .../backgroundtab-pageload/subject.js | 8 -- .../backgroundtab-pageload/template.html | 9 -- .../backgroundtab-pageload/test.ts | 21 ---- .../browsertracing/http-timings/init.js | 16 --- .../browsertracing/http-timings/subject.js | 1 - .../browsertracing/http-timings/test.ts | 58 --------- .../suites/tracing/browsertracing/init.js | 9 -- .../interactions/assets/script.js | 17 --- .../browsertracing/interactions/init.js | 17 --- .../browsertracing/interactions/template.html | 12 -- .../browsertracing/interactions/test.ts | 114 ------------------ .../long-tasks-disabled/assets/script.js | 12 -- .../long-tasks-disabled/init.js | 9 -- .../long-tasks-disabled/template.html | 10 -- .../long-tasks-disabled/test.ts | 23 ---- .../long-tasks-enabled/assets/script.js | 12 -- .../browsertracing/long-tasks-enabled/init.js | 13 -- .../long-tasks-enabled/template.html | 10 -- .../browsertracing/long-tasks-enabled/test.ts | 38 ------ .../tracing/browsertracing/meta/init.js | 10 -- .../tracing/browsertracing/meta/template.html | 11 -- .../tracing/browsertracing/meta/test.ts | 96 --------------- .../tracing/browsertracing/navigation/test.ts | 51 -------- .../tracing/browsertracing/pageload/init.js | 10 -- .../tracing/browsertracing/pageload/test.ts | 24 ---- .../browsertracing/pageloadDelayed/init.js | 13 -- .../browsertracing/pageloadDelayed/test.ts | 26 ---- .../pageloadWithHeartbeatTimeout/init.js | 14 --- .../pageloadWithHeartbeatTimeout/test.ts | 26 ---- .../customTargets/init.js | 10 -- .../customTargets/subject.js | 1 - .../customTargets/test.ts | 33 ----- .../defaultTargetsMatch/init.js | 9 -- .../defaultTargetsMatch/subject.js | 1 - .../defaultTargetsMatch/test.ts | 29 ----- .../defaultTargetsNoMatch/init.js | 9 -- .../defaultTargetsNoMatch/subject.js | 1 - .../defaultTargetsNoMatch/test.ts | 29 ----- 42 files changed, 884 deletions(-) delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/subject.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/template.html delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/subject.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/template.html delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/subject.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/assets/script.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/template.html delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/assets/script.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/template.html delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/assets/script.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/template.html delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/template.html delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/navigation/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageload/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageload/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadDelayed/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadDelayed/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadWithHeartbeatTimeout/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadWithHeartbeatTimeout/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/subject.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/subject.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/subject.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/test.ts diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/init.js deleted file mode 100644 index 3b1080df6fb4..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/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({ idleTimeout: 9000, startTransactionOnPageLoad: false })], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/subject.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/subject.js deleted file mode 100644 index e40426fdbe26..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/subject.js +++ /dev/null @@ -1,16 +0,0 @@ -document.getElementById('go-background').addEventListener('click', () => { - Object.defineProperty(document, 'hidden', { value: true, writable: true }); - const ev = document.createEvent('Event'); - ev.initEvent('visibilitychange'); - document.dispatchEvent(ev); -}); - -document.getElementById('start-span').addEventListener('click', () => { - const span = Sentry.startInactiveSpan({ name: 'test-span' }); - window.span = span; - Sentry.getCurrentScope().setSpan(span); -}); - -window.getSpanJson = () => { - return Sentry.spanToJSON(window.span); -}; diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/template.html b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/template.html deleted file mode 100644 index 772158d31f51..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/template.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/test.ts deleted file mode 100644 index fad37e85d6b4..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-custom/test.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { expect } from '@playwright/test'; -import type { SpanJSON } from '@sentry/types'; - -import { sentryTest } from '../../../../utils/fixtures'; -import { shouldSkipTracingTest } from '../../../../utils/helpers'; - -sentryTest('should finish a custom transaction when the page goes background', async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestPath({ testDir: __dirname }); - page.goto(url); - - await page.locator('#start-span').click(); - const spanJsonBefore: SpanJSON = await page.evaluate('window.getSpanJson()'); - - const id_before = spanJsonBefore.span_id; - const description_before = spanJsonBefore.description; - const status_before = spanJsonBefore.status; - - expect(description_before).toBe('test-span'); - expect(status_before).toBeUndefined(); - - await page.locator('#go-background').click(); - const spanJsonAfter: SpanJSON = await page.evaluate('window.getSpanJson()'); - - const id_after = spanJsonAfter.span_id; - const description_after = spanJsonAfter.description; - const status_after = spanJsonAfter.status; - const data_after = spanJsonAfter.data; - - expect(id_before).toBe(id_after); - expect(description_after).toBe(description_before); - expect(status_after).toBe('cancelled'); - expect(data_after?.['sentry.cancellation_reason']).toBe('document.hidden'); -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/subject.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/subject.js deleted file mode 100644 index b657f38ac009..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/subject.js +++ /dev/null @@ -1,8 +0,0 @@ -document.getElementById('go-background').addEventListener('click', () => { - setTimeout(() => { - Object.defineProperty(document, 'hidden', { value: true, writable: true }); - const ev = document.createEvent('Event'); - ev.initEvent('visibilitychange'); - document.dispatchEvent(ev); - }, 250); -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/template.html b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/template.html deleted file mode 100644 index 31cfc73ec3c3..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/template.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/test.ts deleted file mode 100644 index 1feda2e850e5..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/backgroundtab-pageload/test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { expect } from '@playwright/test'; -import type { Event } from '@sentry/types'; - -import { sentryTest } from '../../../../utils/fixtures'; -import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; - -sentryTest('should finish pageload transaction when the page goes background', async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - const url = await getLocalTestPath({ testDir: __dirname }); - - await page.goto(url); - await page.locator('#go-background').click(); - - const pageloadTransaction = await getFirstSentryEnvelopeRequest(page); - - expect(pageloadTransaction.contexts?.trace?.op).toBe('pageload'); - expect(pageloadTransaction.contexts?.trace?.status).toBe('cancelled'); - expect(pageloadTransaction.contexts?.trace?.data?.['sentry.cancellation_reason']).toBe('document.hidden'); -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/init.js deleted file mode 100644 index e32d09a13fab..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/init.js +++ /dev/null @@ -1,16 +0,0 @@ -import * as Sentry from '@sentry/browser'; - -window.Sentry = Sentry; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [ - Sentry.browserTracingIntegration({ - idleTimeout: 1000, - _experiments: { - enableHTTPTimings: true, - }, - }), - ], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/subject.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/subject.js deleted file mode 100644 index f62499b1e9c5..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/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/http-timings/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/test.ts deleted file mode 100644 index b6da7522d82c..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/http-timings/test.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { expect } from '@playwright/test'; -import type { SerializedEvent } from '@sentry/types'; - -import { sentryTest } from '../../../../utils/fixtures'; -import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../../utils/helpers'; - -sentryTest('should create fetch spans with http timing @firefox', async ({ browserName, getLocalTestPath, page }) => { - const supportedBrowsers = ['chromium', 'firefox']; - - if (shouldSkipTracingTest() || !supportedBrowsers.includes(browserName)) { - sentryTest.skip(); - } - await page.route('http://example.com/*', async route => { - const request = route.request(); - const postData = await request.postDataJSON(); - - await route.fulfill({ - status: 200, - contentType: 'application/json', - body: JSON.stringify(Object.assign({ id: 1 }, postData)), - }); - }); - - const url = await getLocalTestPath({ testDir: __dirname }); - - const envelopes = await getMultipleSentryEnvelopeRequests(page, 2, { url, timeout: 10000 }); - const tracingEvent = envelopes[envelopes.length - 1]; // last envelope contains tracing data on all browsers - - // eslint-disable-next-line deprecation/deprecation - const requestSpans = tracingEvent.spans?.filter(({ op }) => op === 'http.client'); - - expect(requestSpans).toHaveLength(3); - - await page.pause(); - requestSpans?.forEach((span, index) => - expect(span).toMatchObject({ - description: `GET http://example.com/${index}`, - parent_span_id: tracingEvent.contexts?.trace?.span_id, - span_id: expect.any(String), - start_timestamp: expect.any(Number), - timestamp: expect.any(Number), - trace_id: tracingEvent.contexts?.trace?.trace_id, - data: expect.objectContaining({ - 'http.request.redirect_start': expect.any(Number), - 'http.request.fetch_start': expect.any(Number), - 'http.request.domain_lookup_start': expect.any(Number), - 'http.request.domain_lookup_end': expect.any(Number), - 'http.request.connect_start': expect.any(Number), - 'http.request.secure_connection_start': expect.any(Number), - 'http.request.connection_end': expect.any(Number), - 'http.request.request_start': expect.any(Number), - 'http.request.response_start': expect.any(Number), - 'http.request.response_end': expect.any(Number), - 'network.protocol.version': expect.any(String), - }), - }), - ); -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/init.js deleted file mode 100644 index 83076460599f..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/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()], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/assets/script.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/assets/script.js deleted file mode 100644 index a37a2c70ad27..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/assets/script.js +++ /dev/null @@ -1,17 +0,0 @@ -const delay = e => { - const startTime = Date.now(); - - function getElasped() { - const time = Date.now(); - return time - startTime; - } - - while (getElasped() < 70) { - // - } - - e.target.classList.add('clicked'); -}; - -document.querySelector('[data-test-id=interaction-button]').addEventListener('click', delay); -document.querySelector('[data-test-id=annotated-button]').addEventListener('click', delay); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/init.js deleted file mode 100644 index cb9e47548c4a..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/init.js +++ /dev/null @@ -1,17 +0,0 @@ -import * as Sentry from '@sentry/browser'; - -window.Sentry = Sentry; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [ - Sentry.browserTracingIntegration({ - idleTimeout: 1000, - _experiments: { - enableInteractions: true, - enableLongTask: false, - }, - }), - ], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/template.html b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/template.html deleted file mode 100644 index 3357fb20a94e..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/template.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - -
Rendered Before Long Task
- - - - - diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/test.ts deleted file mode 100644 index fa9d2889bae3..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/interactions/test.ts +++ /dev/null @@ -1,114 +0,0 @@ -import type { Route } from '@playwright/test'; -import { expect } from '@playwright/test'; -import type { SerializedEvent, Span, SpanContext, Transaction } from '@sentry/types'; - -import { sentryTest } from '../../../../utils/fixtures'; -import { - getFirstSentryEnvelopeRequest, - getMultipleSentryEnvelopeRequests, - shouldSkipTracingTest, -} from '../../../../utils/helpers'; - -type TransactionJSON = ReturnType & { - spans: ReturnType[]; - contexts: SpanContext; - platform: string; - type: string; -}; - -const wait = (time: number) => new Promise(res => setTimeout(res, time)); - -sentryTest('should capture interaction transaction. @firefox', async ({ browserName, getLocalTestPath, page }) => { - const supportedBrowsers = ['chromium', 'firefox']; - - if (shouldSkipTracingTest() || !supportedBrowsers.includes(browserName)) { - sentryTest.skip(); - } - - await page.route('**/path/to/script.js', (route: Route) => route.fulfill({ path: `${__dirname}/assets/script.js` })); - - const url = await getLocalTestPath({ testDir: __dirname }); - - await page.goto(url); - await getFirstSentryEnvelopeRequest(page); - - await page.locator('[data-test-id=interaction-button]').click(); - await page.locator('.clicked[data-test-id=interaction-button]').isVisible(); - - const envelopes = await getMultipleSentryEnvelopeRequests(page, 1); - expect(envelopes).toHaveLength(1); - - const eventData = envelopes[0]; - - expect(eventData.contexts).toMatchObject({ trace: { op: 'ui.action.click' } }); - expect(eventData.platform).toBe('javascript'); - expect(eventData.type).toBe('transaction'); - expect(eventData.spans).toHaveLength(1); - - const interactionSpan = eventData.spans![0]; - expect(interactionSpan.op).toBe('ui.interaction.click'); - expect(interactionSpan.description).toBe('body > button.clicked'); - expect(interactionSpan.timestamp).toBeDefined(); - - const interactionSpanDuration = (interactionSpan.timestamp! - interactionSpan.start_timestamp) * 1000; - expect(interactionSpanDuration).toBeGreaterThan(65); - expect(interactionSpanDuration).toBeLessThan(200); -}); - -sentryTest( - 'should create only one transaction per interaction @firefox', - async ({ browserName, getLocalTestPath, page }) => { - const supportedBrowsers = ['chromium', 'firefox']; - - if (shouldSkipTracingTest() || !supportedBrowsers.includes(browserName)) { - sentryTest.skip(); - } - - await page.route('**/path/to/script.js', (route: Route) => - route.fulfill({ path: `${__dirname}/assets/script.js` }), - ); - - const url = await getLocalTestPath({ testDir: __dirname }); - await page.goto(url); - await getFirstSentryEnvelopeRequest(page); - - for (let i = 0; i < 4; i++) { - await wait(100); - await page.locator('[data-test-id=interaction-button]').click(); - const envelope = await getMultipleSentryEnvelopeRequests(page, 1); - expect(envelope[0].spans).toHaveLength(1); - } - }, -); - -sentryTest( - 'should use the component name for a clicked element when it is available', - async ({ browserName, getLocalTestPath, page }) => { - const supportedBrowsers = ['chromium', 'firefox']; - - if (shouldSkipTracingTest() || !supportedBrowsers.includes(browserName)) { - sentryTest.skip(); - } - - await page.route('**/path/to/script.js', (route: Route) => - route.fulfill({ path: `${__dirname}/assets/script.js` }), - ); - - const url = await getLocalTestPath({ testDir: __dirname }); - - await page.goto(url); - await getFirstSentryEnvelopeRequest(page); - - await page.locator('[data-test-id=annotated-button]').click(); - - const envelopes = await getMultipleSentryEnvelopeRequests(page, 1); - expect(envelopes).toHaveLength(1); - const eventData = envelopes[0]; - - expect(eventData.spans).toHaveLength(1); - - const interactionSpan = eventData.spans![0]; - expect(interactionSpan.op).toBe('ui.interaction.click'); - expect(interactionSpan.description).toBe('body > AnnotatedButton'); - }, -); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/assets/script.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/assets/script.js deleted file mode 100644 index 9ac3d6fb33d2..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/assets/script.js +++ /dev/null @@ -1,12 +0,0 @@ -(() => { - const startTime = Date.now(); - - function getElasped() { - const time = Date.now(); - return time - startTime; - } - - while (getElasped() < 101) { - // - } -})(); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/init.js deleted file mode 100644 index bde12a1304ed..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/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({ enableLongTask: false, idleTimeout: 9000 })], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/template.html b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/template.html deleted file mode 100644 index 5c3a14114991..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/template.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - -
Rendered Before Long Task
- - - diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/test.ts deleted file mode 100644 index 1f7bb54bb36a..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-disabled/test.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type { Route } from '@playwright/test'; -import { expect } from '@playwright/test'; -import type { Event } from '@sentry/types'; - -import { sentryTest } from '../../../../utils/fixtures'; -import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; - -sentryTest('should not capture long task when flag is disabled.', async ({ browserName, getLocalTestPath, page }) => { - // Long tasks only work on chrome - if (shouldSkipTracingTest() || browserName !== 'chromium') { - sentryTest.skip(); - } - - await page.route('**/path/to/script.js', (route: Route) => route.fulfill({ path: `${__dirname}/assets/script.js` })); - - const url = await getLocalTestPath({ testDir: __dirname }); - - const eventData = await getFirstSentryEnvelopeRequest(page, url); - // eslint-disable-next-line deprecation/deprecation - const uiSpans = eventData.spans?.filter(({ op }) => op?.startsWith('ui')); - - expect(uiSpans?.length).toBe(0); -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/assets/script.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/assets/script.js deleted file mode 100644 index 5a2aef02028d..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/assets/script.js +++ /dev/null @@ -1,12 +0,0 @@ -(() => { - const startTime = Date.now(); - - function getElasped() { - const time = Date.now(); - return time - startTime; - } - - while (getElasped() < 105) { - // - } -})(); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/init.js deleted file mode 100644 index ad1d8832b228..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/init.js +++ /dev/null @@ -1,13 +0,0 @@ -import * as Sentry from '@sentry/browser'; - -window.Sentry = Sentry; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [ - Sentry.browserTracingIntegration({ - idleTimeout: 9000, - }), - ], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/template.html b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/template.html deleted file mode 100644 index 5c3a14114991..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/template.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - -
Rendered Before Long Task
- - - diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/test.ts deleted file mode 100644 index 32819fd784e0..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/long-tasks-enabled/test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { Route } from '@playwright/test'; -import { expect } from '@playwright/test'; -import type { Event } from '@sentry/types'; - -import { sentryTest } from '../../../../utils/fixtures'; -import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; - -sentryTest('should capture long task.', async ({ browserName, getLocalTestPath, page }) => { - // Long tasks only work on chrome - if (shouldSkipTracingTest() || browserName !== 'chromium') { - sentryTest.skip(); - } - - await page.route('**/path/to/script.js', (route: Route) => route.fulfill({ path: `${__dirname}/assets/script.js` })); - - const url = await getLocalTestPath({ testDir: __dirname }); - - const eventData = await getFirstSentryEnvelopeRequest(page, url); - // eslint-disable-next-line deprecation/deprecation - const uiSpans = eventData.spans?.filter(({ op }) => op?.startsWith('ui')); - - expect(uiSpans?.length).toBeGreaterThan(0); - - const [firstUISpan] = uiSpans || []; - expect(firstUISpan).toEqual( - expect.objectContaining({ - op: 'ui.long-task', - description: 'Main UI thread blocked', - parent_span_id: eventData.contexts?.trace?.span_id, - }), - ); - const start = (firstUISpan as Event)['start_timestamp'] ?? 0; - const end = (firstUISpan as Event)['timestamp'] ?? 0; - const duration = end - start; - - expect(duration).toBeGreaterThanOrEqual(0.1); - expect(duration).toBeLessThanOrEqual(0.15); -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/init.js deleted file mode 100644 index d4c7810ef518..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/init.js +++ /dev/null @@ -1,10 +0,0 @@ -import * as Sentry from '@sentry/browser'; - -window.Sentry = Sentry; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [Sentry.browserTracingIntegration()], - tracesSampleRate: 1, - environment: 'staging', -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/template.html b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/template.html deleted file mode 100644 index 09984cb0c488..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/template.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/test.ts deleted file mode 100644 index ae89fd383cbb..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/meta/test.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { expect } from '@playwright/test'; -import type { Event, EventEnvelopeHeaders } from '@sentry/types'; - -import { sentryTest } from '../../../../utils/fixtures'; -import { - envelopeHeaderRequestParser, - getFirstSentryEnvelopeRequest, - shouldSkipTracingTest, -} from '../../../../utils/helpers'; - -sentryTest( - 'should create a pageload transaction based on `sentry-trace` ', - async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestPath({ testDir: __dirname }); - - const eventData = await getFirstSentryEnvelopeRequest(page, url); - - expect(eventData.contexts?.trace).toMatchObject({ - op: 'pageload', - parent_span_id: '1121201211212012', - trace_id: '12312012123120121231201212312012', - }); - - expect(eventData.spans?.length).toBeGreaterThan(0); - }, -); - -sentryTest( - 'should pick up `baggage` tag, propagate the content in transaction and not add own data', - async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestPath({ testDir: __dirname }); - - const envHeader = await getFirstSentryEnvelopeRequest(page, url, envelopeHeaderRequestParser); - - expect(envHeader.trace).toBeDefined(); - expect(envHeader.trace).toEqual({ - release: '2.1.12', - sample_rate: '0.3232', - trace_id: '123', - public_key: 'public', - }); - }, -); - -sentryTest( - "should create a navigation that's not influenced by `sentry-trace` ", - async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestPath({ testDir: __dirname }); - - const pageloadRequest = await getFirstSentryEnvelopeRequest(page, url); - const navigationRequest = await getFirstSentryEnvelopeRequest(page, `${url}#foo`); - - expect(pageloadRequest.contexts?.trace).toMatchObject({ - op: 'pageload', - parent_span_id: '1121201211212012', - trace_id: '12312012123120121231201212312012', - }); - - expect(navigationRequest.contexts?.trace?.op).toBe('navigation'); - expect(navigationRequest.contexts?.trace?.trace_id).toBeDefined(); - expect(navigationRequest.contexts?.trace?.trace_id).not.toBe(pageloadRequest.contexts?.trace?.trace_id); - - const pageloadSpans = pageloadRequest.spans; - const navigationSpans = navigationRequest.spans; - - const pageloadSpanId = pageloadRequest.contexts?.trace?.span_id; - const navigationSpanId = navigationRequest.contexts?.trace?.span_id; - - expect(pageloadSpanId).toBeDefined(); - expect(navigationSpanId).toBeDefined(); - - pageloadSpans?.forEach(span => - expect(span).toMatchObject({ - parent_span_id: pageloadSpanId, - }), - ); - - navigationSpans?.forEach(span => - expect(span).toMatchObject({ - parent_span_id: navigationSpanId, - }), - ); - }, -); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/navigation/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/navigation/test.ts deleted file mode 100644 index 5a46a65a4392..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/navigation/test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { expect } from '@playwright/test'; -import type { Event } from '@sentry/types'; - -import { sentryTest } from '../../../../utils/fixtures'; -import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; - -sentryTest('should create a navigation transaction on page navigation', async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestPath({ testDir: __dirname }); - - const pageloadRequest = await getFirstSentryEnvelopeRequest(page, url); - const navigationRequest = await getFirstSentryEnvelopeRequest(page, `${url}#foo`); - - expect(pageloadRequest.contexts?.trace?.op).toBe('pageload'); - expect(navigationRequest.contexts?.trace?.op).toBe('navigation'); - - expect(navigationRequest.transaction_info?.source).toEqual('url'); - - const pageloadTraceId = pageloadRequest.contexts?.trace?.trace_id; - const navigationTraceId = navigationRequest.contexts?.trace?.trace_id; - - expect(pageloadTraceId).toBeDefined(); - expect(navigationTraceId).toBeDefined(); - expect(pageloadTraceId).not.toEqual(navigationTraceId); - - const pageloadSpans = pageloadRequest.spans; - const navigationSpans = navigationRequest.spans; - - const pageloadSpanId = pageloadRequest.contexts?.trace?.span_id; - const navigationSpanId = navigationRequest.contexts?.trace?.span_id; - - expect(pageloadSpanId).toBeDefined(); - expect(navigationSpanId).toBeDefined(); - - pageloadSpans?.forEach(span => - expect(span).toMatchObject({ - parent_span_id: pageloadSpanId, - }), - ); - - navigationSpans?.forEach(span => - expect(span).toMatchObject({ - parent_span_id: navigationSpanId, - }), - ); - - expect(pageloadSpanId).not.toEqual(navigationSpanId); -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageload/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageload/init.js deleted file mode 100644 index 1f0b64911a75..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageload/init.js +++ /dev/null @@ -1,10 +0,0 @@ -import * as Sentry from '@sentry/browser'; - -window.Sentry = Sentry; -window._testBaseTimestamp = performance.timeOrigin / 1000; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [Sentry.browserTracingIntegration()], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageload/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageload/test.ts deleted file mode 100644 index 6a186b63b02a..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageload/test.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { expect } from '@playwright/test'; -import type { Event } from '@sentry/types'; - -import { sentryTest } from '../../../../utils/fixtures'; -import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; - -sentryTest('should create a pageload transaction', async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestPath({ testDir: __dirname }); - - const eventData = await getFirstSentryEnvelopeRequest(page, url); - const timeOrigin = await page.evaluate('window._testBaseTimestamp'); - - const { start_timestamp: startTimestamp } = eventData; - - expect(startTimestamp).toBeCloseTo(timeOrigin, 1); - - expect(eventData.contexts?.trace?.op).toBe('pageload'); - expect(eventData.spans?.length).toBeGreaterThan(0); - expect(eventData.transaction_info?.source).toEqual('url'); -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadDelayed/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadDelayed/init.js deleted file mode 100644 index 2c5a44a7f76d..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadDelayed/init.js +++ /dev/null @@ -1,13 +0,0 @@ -import * as Sentry from '@sentry/browser'; - -window.Sentry = Sentry; -window._testBaseTimestamp = performance.timeOrigin / 1000; - -setTimeout(() => { - window._testTimeoutTimestamp = (performance.timeOrigin + performance.now()) / 1000; - Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [Sentry.browserTracingIntegration()], - tracesSampleRate: 1, - }); -}, 250); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadDelayed/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadDelayed/test.ts deleted file mode 100644 index 882c08d23c5e..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadDelayed/test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { expect } from '@playwright/test'; -import type { Event } from '@sentry/types'; - -import { sentryTest } from '../../../../utils/fixtures'; -import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; - -sentryTest('should create a pageload transaction when initialized delayed', async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestPath({ testDir: __dirname }); - - const eventData = await getFirstSentryEnvelopeRequest(page, url); - const timeOrigin = await page.evaluate('window._testBaseTimestamp'); - const timeoutTimestamp = await page.evaluate('window._testTimeoutTimestamp'); - - const { start_timestamp: startTimestamp } = eventData; - - expect(startTimestamp).toBeCloseTo(timeOrigin, 1); - expect(startTimestamp).toBeLessThan(timeoutTimestamp); - - expect(eventData.contexts?.trace?.op).toBe('pageload'); - expect(eventData.spans?.length).toBeGreaterThan(0); - expect(eventData.transaction_info?.source).toEqual('url'); -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadWithHeartbeatTimeout/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadWithHeartbeatTimeout/init.js deleted file mode 100644 index 8b12fe807d7b..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadWithHeartbeatTimeout/init.js +++ /dev/null @@ -1,14 +0,0 @@ -import * as Sentry from '@sentry/browser'; -import { startSpanManual } from '@sentry/browser'; - -window.Sentry = Sentry; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - integrations: [Sentry.browserTracingIntegration()], - tracesSampleRate: 1, -}); - -setTimeout(() => { - startSpanManual({ name: 'pageload-child-span' }, () => {}); -}, 200); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadWithHeartbeatTimeout/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadWithHeartbeatTimeout/test.ts deleted file mode 100644 index ead37d6f8662..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/pageloadWithHeartbeatTimeout/test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { expect } from '@playwright/test'; -import type { SerializedEvent } from '@sentry/types'; - -import { sentryTest } from '../../../../utils/fixtures'; -import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; - -// This tests asserts that the pageload transaction will finish itself after about 15 seconds (3x5s of heartbeats) if it -// has a child span without adding any additional ones or finishing any of them finishing. All of the child spans that -// are still running should have the status "cancelled". -sentryTest( - 'should send a pageload transaction terminated via heartbeat timeout', - async ({ getLocalTestPath, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestPath({ testDir: __dirname }); - - const eventData = await getFirstSentryEnvelopeRequest(page, url); - - expect(eventData.contexts?.trace?.op).toBe('pageload'); - expect( - eventData.spans?.find(span => span.description === 'pageload-child-span' && span.status === 'cancelled'), - ).toBeDefined(); - }, -); 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 deleted file mode 100644 index 7cd076a052e5..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/init.js +++ /dev/null @@ -1,10 +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: ['http://example.com'], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/subject.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/subject.js deleted file mode 100644 index f62499b1e9c5..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/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/customTargets/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/test.ts deleted file mode 100644 index fb6e9e540c46..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/customTargets/test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { expect } from '@playwright/test'; - -import { sentryTest } from '../../../../../utils/fixtures'; -import { shouldSkipTracingTest } from '../../../../../utils/helpers'; - -sentryTest( - 'should attach `sentry-trace` and `baggage` header to request matching tracePropagationTargets', - 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 deleted file mode 100644 index 83076460599f..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/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()], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/subject.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/subject.js deleted file mode 100644 index 7e662b55c333..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/subject.js +++ /dev/null @@ -1 +0,0 @@ -fetch('/0').then(fetch('/1').then(fetch('/2'))); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/test.ts deleted file mode 100644 index f9f9af3ddb47..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsMatch/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { expect } from '@playwright/test'; - -import { sentryTest } from '../../../../../utils/fixtures'; -import { shouldSkipTracingTest } from '../../../../../utils/helpers'; - -sentryTest( - 'should attach `sentry-trace` and `baggage` header to same-origin requests when no tracePropagationTargets are defined', - async ({ getLocalTestUrl, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestUrl({ testDir: __dirname }); - - const requests = ( - await Promise.all([page.goto(url), Promise.all([0, 1, 2].map(idx => page.waitForRequest(`**/${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/defaultTargetsNoMatch/init.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/init.js deleted file mode 100644 index 83076460599f..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/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()], - tracesSampleRate: 1, -}); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/subject.js b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/subject.js deleted file mode 100644 index f62499b1e9c5..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/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/defaultTargetsNoMatch/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/test.ts deleted file mode 100644 index 6739b7ce3621..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browsertracing/tracePropagationTargets/defaultTargetsNoMatch/test.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { expect } from '@playwright/test'; - -import { sentryTest } from '../../../../../utils/fixtures'; -import { shouldSkipTracingTest } from '../../../../../utils/helpers'; - -sentryTest( - 'should not attach `sentry-trace` and `baggage` header to cross-origin requests when no tracePropagationTargets are defined', - async ({ getLocalTestUrl, page }) => { - if (shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const url = await getLocalTestUrl({ testDir: __dirname }); - - const requests = ( - await Promise.all([page.goto(url), Promise.all([0, 1, 2].map(idx => page.waitForRequest(`**/${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), - }); - } - }, -); From 5c7af00b4306f6adae1d14477c47c78176a994ca Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 22 Feb 2024 10:21:45 +0000 Subject: [PATCH 33/44] fixing --- .../suites/public-api/startSpan/init.js | 5 ++--- .../suites/public-api/startTransaction/init.js | 5 ++--- .../long-tasks-disabled/test.ts | 5 ++--- .../browserTracingIntegration/long-tasks-enabled/test.ts | 5 ++--- .../tracing/metrics/pageload-browser-spans/test.ts | 5 ++--- .../tracing/metrics/pageload-resource-spans/test.ts | 5 ++--- .../suites/tracing/request/fetch/test.ts | 5 ++--- .../suites/tracing/request/xhr/test.ts | 5 ++--- .../test/browser/browserTracingIntegration.test.ts | 9 +++------ 9 files changed, 19 insertions(+), 30 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/public-api/startSpan/init.js b/dev-packages/browser-integration-tests/suites/public-api/startSpan/init.js index b0bf1e869254..d6e849bc7cae 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/startSpan/init.js +++ b/dev-packages/browser-integration-tests/suites/public-api/startSpan/init.js @@ -1,7 +1,6 @@ -/* eslint-disable no-unused-vars */ import * as Sentry from '@sentry/browser'; -// biome-ignore lint/nursery/noUnusedImports: Need to import tracing for side effect -import * as _ from '@sentry/tracing'; + +Sentry.addTracingExtensions(); window.Sentry = Sentry; diff --git a/dev-packages/browser-integration-tests/suites/public-api/startTransaction/init.js b/dev-packages/browser-integration-tests/suites/public-api/startTransaction/init.js index e1903e2cc268..1c155f323586 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/startTransaction/init.js +++ b/dev-packages/browser-integration-tests/suites/public-api/startTransaction/init.js @@ -1,7 +1,6 @@ -/* eslint-disable no-unused-vars */ import * as Sentry from '@sentry/browser'; -// biome-ignore lint/nursery/noUnusedImports: Need to import tracing for side effect -import * as _ from '@sentry/tracing'; + +Sentry.addTracingExtensions(); window.Sentry = Sentry; diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-tasks-disabled/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-tasks-disabled/test.ts index 1f7bb54bb36a..d460d2883afd 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-tasks-disabled/test.ts +++ b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-tasks-disabled/test.ts @@ -1,6 +1,6 @@ import type { Route } from '@playwright/test'; import { expect } from '@playwright/test'; -import type { Event } from '@sentry/types'; +import type { SerializedEvent } from '@sentry/types'; import { sentryTest } from '../../../../utils/fixtures'; import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; @@ -15,8 +15,7 @@ sentryTest('should not capture long task when flag is disabled.', async ({ brows const url = await getLocalTestPath({ testDir: __dirname }); - const eventData = await getFirstSentryEnvelopeRequest(page, url); - // eslint-disable-next-line deprecation/deprecation + const eventData = await getFirstSentryEnvelopeRequest(page, url); const uiSpans = eventData.spans?.filter(({ op }) => op?.startsWith('ui')); expect(uiSpans?.length).toBe(0); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-tasks-enabled/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-tasks-enabled/test.ts index 32819fd784e0..ae8ec66fb1a6 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-tasks-enabled/test.ts +++ b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-tasks-enabled/test.ts @@ -1,6 +1,6 @@ import type { Route } from '@playwright/test'; import { expect } from '@playwright/test'; -import type { Event } from '@sentry/types'; +import type { Event, SerializedEvent } from '@sentry/types'; import { sentryTest } from '../../../../utils/fixtures'; import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; @@ -15,8 +15,7 @@ sentryTest('should capture long task.', async ({ browserName, getLocalTestPath, const url = await getLocalTestPath({ testDir: __dirname }); - const eventData = await getFirstSentryEnvelopeRequest(page, url); - // eslint-disable-next-line deprecation/deprecation + const eventData = await getFirstSentryEnvelopeRequest(page, url); const uiSpans = eventData.spans?.filter(({ op }) => op?.startsWith('ui')); expect(uiSpans?.length).toBeGreaterThan(0); diff --git a/dev-packages/browser-integration-tests/suites/tracing/metrics/pageload-browser-spans/test.ts b/dev-packages/browser-integration-tests/suites/tracing/metrics/pageload-browser-spans/test.ts index 504ac975621e..0730d2ba4645 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/metrics/pageload-browser-spans/test.ts +++ b/dev-packages/browser-integration-tests/suites/tracing/metrics/pageload-browser-spans/test.ts @@ -1,5 +1,5 @@ import { expect } from '@playwright/test'; -import type { Event } from '@sentry/types'; +import type { SerializedEvent } from '@sentry/types'; import { sentryTest } from '../../../../utils/fixtures'; import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; @@ -11,8 +11,7 @@ sentryTest('should add browser-related spans to pageload transaction', async ({ const url = await getLocalTestPath({ testDir: __dirname }); - const eventData = await getFirstSentryEnvelopeRequest(page, url); - // eslint-disable-next-line deprecation/deprecation + const eventData = await getFirstSentryEnvelopeRequest(page, url); const browserSpans = eventData.spans?.filter(({ op }) => op === 'browser'); // Spans `connect`, `cache` and `DNS` are not always inside `pageload` transaction. diff --git a/dev-packages/browser-integration-tests/suites/tracing/metrics/pageload-resource-spans/test.ts b/dev-packages/browser-integration-tests/suites/tracing/metrics/pageload-resource-spans/test.ts index 9ce848384f7b..40159d39ea25 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/metrics/pageload-resource-spans/test.ts +++ b/dev-packages/browser-integration-tests/suites/tracing/metrics/pageload-resource-spans/test.ts @@ -1,6 +1,6 @@ import type { Route } from '@playwright/test'; import { expect } from '@playwright/test'; -import type { Event } from '@sentry/types'; +import type { SerializedEvent } from '@sentry/types'; import { sentryTest } from '../../../../utils/fixtures'; import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; @@ -17,8 +17,7 @@ sentryTest('should add resource spans to pageload transaction', async ({ getLoca const url = await getLocalTestPath({ testDir: __dirname }); - const eventData = await getFirstSentryEnvelopeRequest(page, url); - // eslint-disable-next-line deprecation/deprecation + const eventData = await getFirstSentryEnvelopeRequest(page, url); const resourceSpans = eventData.spans?.filter(({ op }) => op?.startsWith('resource')); // Webkit 16.0 (which is linked to Playwright 1.27.1) consistently creates 2 consectutive spans for `css`, diff --git a/dev-packages/browser-integration-tests/suites/tracing/request/fetch/test.ts b/dev-packages/browser-integration-tests/suites/tracing/request/fetch/test.ts index 7bffc0131b2f..ab4c29906f5c 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/request/fetch/test.ts +++ b/dev-packages/browser-integration-tests/suites/tracing/request/fetch/test.ts @@ -1,5 +1,5 @@ import { expect } from '@playwright/test'; -import type { Event } from '@sentry/types'; +import type { SerializedEvent } from '@sentry/types'; import { sentryTest } from '../../../../utils/fixtures'; import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../../utils/helpers'; @@ -21,10 +21,9 @@ sentryTest('should create spans for multiple fetch requests', async ({ getLocalT // If we are on FF or webkit: // 1st envelope contains CORS error // 2nd envelope contains the tracing data we want to check here - const envelopes = await getMultipleSentryEnvelopeRequests(page, 2, { url, timeout: 10000 }); + const envelopes = await getMultipleSentryEnvelopeRequests(page, 2, { url, timeout: 10000 }); const tracingEvent = envelopes[envelopes.length - 1]; // last envelope contains tracing data on all browsers - // eslint-disable-next-line deprecation/deprecation const requestSpans = tracingEvent.spans?.filter(({ op }) => op === 'http.client'); expect(requestSpans).toHaveLength(3); diff --git a/dev-packages/browser-integration-tests/suites/tracing/request/xhr/test.ts b/dev-packages/browser-integration-tests/suites/tracing/request/xhr/test.ts index d1c64e253e71..bd4ee0bbb003 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/request/xhr/test.ts +++ b/dev-packages/browser-integration-tests/suites/tracing/request/xhr/test.ts @@ -1,5 +1,5 @@ import { expect } from '@playwright/test'; -import type { Event } from '@sentry/types'; +import type { SerializedEvent } from '@sentry/types'; import { sentryTest } from '../../../../utils/fixtures'; import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; @@ -11,8 +11,7 @@ sentryTest('should create spans for multiple XHR requests', async ({ getLocalTes const url = await getLocalTestPath({ testDir: __dirname }); - const eventData = await getFirstSentryEnvelopeRequest(page, url); - // eslint-disable-next-line deprecation/deprecation + const eventData = await getFirstSentryEnvelopeRequest(page, url); const requestSpans = eventData.spans?.filter(({ op }) => op === 'http.client'); expect(requestSpans).toHaveLength(3); diff --git a/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts b/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts index b2f8859a1a06..1e29fa8528b6 100644 --- a/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts +++ b/packages/tracing-internal/test/browser/browserTracingIntegration.test.ts @@ -686,8 +686,7 @@ describe('browserTracingIntegration', () => { const dynamicSamplingContext = transaction.getDynamicSamplingContext()!; expect(transaction).toBeDefined(); - // eslint-disable-next-line deprecation/deprecation - expect(transaction.op).toBe('pageload'); + expect(spanToJSON(transaction).op).toBe('pageload'); // eslint-disable-next-line deprecation/deprecation expect(transaction.traceId).toEqual('12312012123120121231201212312012'); // eslint-disable-next-line deprecation/deprecation @@ -720,8 +719,7 @@ describe('browserTracingIntegration', () => { const dynamicSamplingContext = transaction.getDynamicSamplingContext()!; expect(transaction).toBeDefined(); - // eslint-disable-next-line deprecation/deprecation - expect(transaction.op).toBe('pageload'); + expect(spanToJSON(transaction).op).toBe('pageload'); // eslint-disable-next-line deprecation/deprecation expect(transaction.traceId).toEqual('12312012123120121231201212312012'); // eslint-disable-next-line deprecation/deprecation @@ -758,8 +756,7 @@ describe('browserTracingIntegration', () => { const dynamicSamplingContext = transaction.getDynamicSamplingContext()!; expect(transaction).toBeDefined(); - // eslint-disable-next-line deprecation/deprecation - expect(transaction.op).toBe('navigation'); + expect(spanToJSON(transaction).op).toBe('navigation'); // eslint-disable-next-line deprecation/deprecation expect(transaction.traceId).not.toEqual('12312012123120121231201212312012'); // eslint-disable-next-line deprecation/deprecation From d83615245b183692edfcb8a08f37e61137bac277 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 22 Feb 2024 10:33:26 +0000 Subject: [PATCH 34/44] lint --- .../test/unit/index.bundle.tracing.replay.feedback.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/browser/test/unit/index.bundle.tracing.replay.feedback.test.ts b/packages/browser/test/unit/index.bundle.tracing.replay.feedback.test.ts index ab01c77478c6..962934f064f8 100644 --- a/packages/browser/test/unit/index.bundle.tracing.replay.feedback.test.ts +++ b/packages/browser/test/unit/index.bundle.tracing.replay.feedback.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable deprecation/deprecation */ import { browserTracingIntegration } from '@sentry-internal/tracing'; import { Feedback, Replay, feedbackIntegration, replayIntegration } from '@sentry/browser'; From 46ae773df28e7aa2eb09a1aaa353b12bbc0ff134 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 22 Feb 2024 11:36:00 +0000 Subject: [PATCH 35/44] god be on my side in these challenging times --- packages/browser/src/index.bundle.feedback.ts | 18 ++++++------ packages/browser/src/index.bundle.replay.ts | 16 +++++----- .../index.bundle.tracing.replay.feedback.ts | 3 ++ .../src/index.bundle.tracing.replay.ts | 8 +++-- packages/browser/src/index.bundle.tracing.ts | 22 +++++++++----- packages/browser/src/index.bundle.ts | 29 ++++++++++--------- .../test/unit/index.bundle.feedback.test.ts | 6 +--- .../test/unit/index.bundle.replay.test.ts | 6 +--- .../browser/test/unit/index.bundle.test.ts | 10 +++---- .../unit/index.bundle.tracing.replay.test.ts | 5 +--- .../test/unit/index.bundle.tracing.test.ts | 8 ++--- .../integration-shims/src/BrowserTracing.ts | 12 ++------ packages/integration-shims/src/Feedback.ts | 7 ++--- packages/integration-shims/src/Replay.ts | 7 ++--- packages/integration-shims/src/index.ts | 14 ++++----- 15 files changed, 82 insertions(+), 89 deletions(-) diff --git a/packages/browser/src/index.bundle.feedback.ts b/packages/browser/src/index.bundle.feedback.ts index d4c8e8bb1613..7cb0501e1a92 100644 --- a/packages/browser/src/index.bundle.feedback.ts +++ b/packages/browser/src/index.bundle.feedback.ts @@ -1,25 +1,25 @@ // This is exported so the loader does not fail when switching off Replay/Tracing import { Feedback, feedbackIntegration } from '@sentry-internal/feedback'; import { - Replay, - addTracingExtensions, - browserTracingIntegration, - replayIntegration, + ReplayShim, + addTracingExtensionsShim, + browserTracingIntegrationShim, + replayIntegrationShim, } from '@sentry-internal/integration-shims'; import * as Sentry from './index.bundle.base'; // TODO (v8): Remove this as it was only needed for backwards compatibility // eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.Replay = Replay; +Sentry.Integrations.Replay = ReplayShim; export * from './index.bundle.base'; export { - browserTracingIntegration, - addTracingExtensions, + browserTracingIntegrationShim as browserTracingIntegration, + addTracingExtensionsShim as addTracingExtensions, // eslint-disable-next-line deprecation/deprecation - Replay, - replayIntegration, + ReplayShim as Replay, + replayIntegrationShim as replayIntegration, // eslint-disable-next-line deprecation/deprecation Feedback, feedbackIntegration, diff --git a/packages/browser/src/index.bundle.replay.ts b/packages/browser/src/index.bundle.replay.ts index cca0ba280642..71baed234eba 100644 --- a/packages/browser/src/index.bundle.replay.ts +++ b/packages/browser/src/index.bundle.replay.ts @@ -1,9 +1,9 @@ // This is exported so the loader does not fail when switching off Replay/Tracing import { - Feedback, - addTracingExtensions, - browserTracingIntegration, - feedbackIntegration, + FeedbackShim, + addTracingExtensionsShim, + browserTracingIntegrationShim, + feedbackIntegrationShim, } from '@sentry-internal/integration-shims'; import { Replay, replayIntegration } from '@sentry/replay'; @@ -15,13 +15,13 @@ Sentry.Integrations.Replay = Replay; export * from './index.bundle.base'; export { - browserTracingIntegration, - addTracingExtensions, + browserTracingIntegrationShim as browserTracingIntegration, + addTracingExtensionsShim as addTracingExtensions, // eslint-disable-next-line deprecation/deprecation Replay, replayIntegration, // eslint-disable-next-line deprecation/deprecation - Feedback, - feedbackIntegration, + FeedbackShim as Feedback, + feedbackIntegrationShim as feedbackIntegration, }; // Note: We do not export a shim for `Span` here, as that is quite complex and would blow up the bundle diff --git a/packages/browser/src/index.bundle.tracing.replay.feedback.ts b/packages/browser/src/index.bundle.tracing.replay.feedback.ts index fd6efc3824f4..eab59019dafd 100644 --- a/packages/browser/src/index.bundle.tracing.replay.feedback.ts +++ b/packages/browser/src/index.bundle.tracing.replay.feedback.ts @@ -1,4 +1,5 @@ import { Feedback, feedbackIntegration } from '@sentry-internal/feedback'; +import { BrowserTracingShim } from '@sentry-internal/integration-shims'; import { addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing'; import { Replay, replayIntegration } from '@sentry/replay'; @@ -20,6 +21,8 @@ export { Replay, feedbackIntegration, replayIntegration, + // eslint-disable-next-line deprecation/deprecation + BrowserTracingShim as BrowserTracing, browserTracingIntegration, addExtensionMethods, }; diff --git a/packages/browser/src/index.bundle.tracing.replay.ts b/packages/browser/src/index.bundle.tracing.replay.ts index dee51666e460..8ff83643988e 100644 --- a/packages/browser/src/index.bundle.tracing.replay.ts +++ b/packages/browser/src/index.bundle.tracing.replay.ts @@ -1,4 +1,4 @@ -import { Feedback, feedbackIntegration } from '@sentry-internal/integration-shims'; +import { BrowserTracingShim, FeedbackShim, feedbackIntegrationShim } from '@sentry-internal/integration-shims'; import { addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing'; import { Replay, replayIntegration } from '@sentry/replay'; @@ -15,11 +15,13 @@ addExtensionMethods(); export { // eslint-disable-next-line deprecation/deprecation - Feedback, + FeedbackShim as Feedback, // eslint-disable-next-line deprecation/deprecation Replay, replayIntegration, - feedbackIntegration, + feedbackIntegrationShim as feedbackIntegration, + // eslint-disable-next-line deprecation/deprecation + BrowserTracingShim as BrowserTracing, browserTracingIntegration, addExtensionMethods, }; diff --git a/packages/browser/src/index.bundle.tracing.ts b/packages/browser/src/index.bundle.tracing.ts index 20c15fc11066..525dd6a5b3b2 100644 --- a/packages/browser/src/index.bundle.tracing.ts +++ b/packages/browser/src/index.bundle.tracing.ts @@ -1,25 +1,33 @@ // This is exported so the loader does not fail when switching off Replay -import { Feedback, Replay, feedbackIntegration, replayIntegration } from '@sentry-internal/integration-shims'; +import { + BrowserTracingShim, + FeedbackShim, + ReplayShim, + feedbackIntegrationShim, + replayIntegrationShim, +} from '@sentry-internal/integration-shims'; import { addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing'; import * as Sentry from './index.bundle.base'; -// TODO (v8): Remove this as it was only needed for backwards compatibility +// TODO(v8): Remove this as it was only needed for backwards compatibility // We want replay to be available under Sentry.Replay, to be consistent // with the NPM package version. // eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.Replay = Replay; +Sentry.Integrations.Replay = ReplayShim; // We are patching the global object with our hub extension methods addExtensionMethods(); export { // eslint-disable-next-line deprecation/deprecation - Feedback, + FeedbackShim as Feedback, // eslint-disable-next-line deprecation/deprecation - Replay, - feedbackIntegration, - replayIntegration, + ReplayShim as Replay, + feedbackIntegrationShim as feedbackIntegration, + replayIntegrationShim as replayIntegration, + // eslint-disable-next-line deprecation/deprecation + BrowserTracingShim as BrowserTracing, browserTracingIntegration, addExtensionMethods, }; diff --git a/packages/browser/src/index.bundle.ts b/packages/browser/src/index.bundle.ts index 69a41826afe5..97b4da50fc64 100644 --- a/packages/browser/src/index.bundle.ts +++ b/packages/browser/src/index.bundle.ts @@ -1,28 +1,31 @@ // This is exported so the loader does not fail when switching off Replay/Tracing import { - Feedback, - Replay, - addTracingExtensions, - browserTracingIntegration, - feedbackIntegration, - replayIntegration, + BrowserTracingShim, + FeedbackShim, + ReplayShim, + addTracingExtensionsShim, + browserTracingIntegrationShim, + feedbackIntegrationShim, + replayIntegrationShim, } from '@sentry-internal/integration-shims'; import * as Sentry from './index.bundle.base'; // TODO (v8): Remove this as it was only needed for backwards compatibility // eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.Replay = Replay; +Sentry.Integrations.Replay = ReplayShim; export * from './index.bundle.base'; export { - addTracingExtensions, // eslint-disable-next-line deprecation/deprecation - Replay, + BrowserTracingShim as BrowserTracing, + addTracingExtensionsShim as addTracingExtensions, // eslint-disable-next-line deprecation/deprecation - Feedback, - browserTracingIntegration, - feedbackIntegration, - replayIntegration, + ReplayShim as Replay, + // eslint-disable-next-line deprecation/deprecation + FeedbackShim as Feedback, + browserTracingIntegrationShim as browserTracingIntegration, + feedbackIntegrationShim as feedbackIntegration, + replayIntegrationShim as replayIntegration, }; // Note: We do not export a shim for `Span` here, as that is quite complex and would blow up the bundle diff --git a/packages/browser/test/unit/index.bundle.feedback.test.ts b/packages/browser/test/unit/index.bundle.feedback.test.ts index 726a0338b7a7..a480c4453b47 100644 --- a/packages/browser/test/unit/index.bundle.feedback.test.ts +++ b/packages/browser/test/unit/index.bundle.feedback.test.ts @@ -1,9 +1,5 @@ /* eslint-disable deprecation/deprecation */ -import { - BrowserTracing as BrowserTracingShim, - Replay as ReplayShim, - replayIntegration as replayIntegrationShim, -} from '@sentry-internal/integration-shims'; +import { BrowserTracingShim, ReplayShim, replayIntegrationShim } from '@sentry-internal/integration-shims'; import { Feedback, feedbackIntegration } from '@sentry/browser'; import * as TracingReplayBundle from '../../src/index.bundle.feedback'; diff --git a/packages/browser/test/unit/index.bundle.replay.test.ts b/packages/browser/test/unit/index.bundle.replay.test.ts index f653f3722ce8..3f620f1f692c 100644 --- a/packages/browser/test/unit/index.bundle.replay.test.ts +++ b/packages/browser/test/unit/index.bundle.replay.test.ts @@ -1,9 +1,5 @@ /* eslint-disable deprecation/deprecation */ -import { - BrowserTracing as BrowserTracingShim, - Feedback as FeedbackShim, - feedbackIntegration as feedbackIntegrationShim, -} from '@sentry-internal/integration-shims'; +import { BrowserTracingShim, FeedbackShim, feedbackIntegrationShim } from '@sentry-internal/integration-shims'; import { Replay, replayIntegration } from '@sentry/browser'; import * as TracingReplayBundle from '../../src/index.bundle.replay'; diff --git a/packages/browser/test/unit/index.bundle.test.ts b/packages/browser/test/unit/index.bundle.test.ts index f141117a173b..80b4b39a7174 100644 --- a/packages/browser/test/unit/index.bundle.test.ts +++ b/packages/browser/test/unit/index.bundle.test.ts @@ -1,10 +1,10 @@ /* eslint-disable deprecation/deprecation */ import { - BrowserTracing as BrowserTracingShim, - Feedback as FeedbackShim, - Replay as ReplayShim, - feedbackIntegration as feedbackIntegrationShim, - replayIntegration as replayIntegrationShim, + BrowserTracingShim, + FeedbackShim, + ReplayShim, + feedbackIntegrationShim, + replayIntegrationShim, } from '@sentry-internal/integration-shims'; import * as TracingBundle from '../../src/index.bundle'; diff --git a/packages/browser/test/unit/index.bundle.tracing.replay.test.ts b/packages/browser/test/unit/index.bundle.tracing.replay.test.ts index 039d899d51a0..a90eac6cbe60 100644 --- a/packages/browser/test/unit/index.bundle.tracing.replay.test.ts +++ b/packages/browser/test/unit/index.bundle.tracing.replay.test.ts @@ -1,8 +1,5 @@ /* eslint-disable deprecation/deprecation */ -import { - Feedback as FeedbackShim, - feedbackIntegration as feedbackIntegrationShim, -} from '@sentry-internal/integration-shims'; +import { FeedbackShim, feedbackIntegrationShim } from '@sentry-internal/integration-shims'; import { browserTracingIntegration } from '@sentry-internal/tracing'; import { Replay, replayIntegration } from '@sentry/browser'; diff --git a/packages/browser/test/unit/index.bundle.tracing.test.ts b/packages/browser/test/unit/index.bundle.tracing.test.ts index a2bf52b65710..0f8257ee4ad0 100644 --- a/packages/browser/test/unit/index.bundle.tracing.test.ts +++ b/packages/browser/test/unit/index.bundle.tracing.test.ts @@ -1,9 +1,9 @@ /* eslint-disable deprecation/deprecation */ import { - Feedback as FeedbackShim, - Replay as ReplayShim, - feedbackIntegration as feedbackIntegrationShim, - replayIntegration as replayIntegrationShim, + FeedbackShim, + ReplayShim, + feedbackIntegrationShim, + replayIntegrationShim, } from '@sentry-internal/integration-shims'; import { browserTracingIntegration } from '@sentry-internal/tracing'; diff --git a/packages/integration-shims/src/BrowserTracing.ts b/packages/integration-shims/src/BrowserTracing.ts index 50b91b984952..adc7d873a3ab 100644 --- a/packages/integration-shims/src/BrowserTracing.ts +++ b/packages/integration-shims/src/BrowserTracing.ts @@ -8,7 +8,7 @@ import { consoleSandbox } from '@sentry/utils'; * * @deprecated Use `browserTracingIntegration()` instead. */ -class BrowserTracingShim implements Integration { +export class BrowserTracingShim implements Integration { /** * @inheritDoc */ @@ -41,18 +41,12 @@ class BrowserTracingShim implements Integration { * It is needed in order for the CDN bundles to continue working when users add/remove tracing * from it, without changing their config. This is necessary for the loader mechanism. */ -function browserTracingIntegrationShim(_options?: unknown): Integration { +export function browserTracingIntegrationShim(_options?: unknown): Integration { // eslint-disable-next-line deprecation/deprecation return new BrowserTracingShim({}); } -export { - // eslint-disable-next-line deprecation/deprecation - BrowserTracingShim as BrowserTracing, - browserTracingIntegrationShim as browserTracingIntegration, -}; - /** Shim function */ -export function addTracingExtensions(): void { +export function addTracingExtensionsShim(): void { // noop } diff --git a/packages/integration-shims/src/Feedback.ts b/packages/integration-shims/src/Feedback.ts index 7b717e3a4e3b..419071d2bd26 100644 --- a/packages/integration-shims/src/Feedback.ts +++ b/packages/integration-shims/src/Feedback.ts @@ -8,7 +8,7 @@ import { consoleSandbox } from '@sentry/utils'; * * @deprecated Use `feedbackIntegration()` instead. */ -class FeedbackShim implements Integration { +export class FeedbackShim implements Integration { /** * @inheritDoc */ @@ -75,10 +75,7 @@ class FeedbackShim implements Integration { * It is needed in order for the CDN bundles to continue working when users add/remove feedback * from it, without changing their config. This is necessary for the loader mechanism. */ -export function feedbackIntegration(_options: unknown): Integration { +export function feedbackIntegrationShim(_options: unknown): Integration { // eslint-disable-next-line deprecation/deprecation return new FeedbackShim({}); } - -// eslint-disable-next-line deprecation/deprecation -export { FeedbackShim as Feedback }; diff --git a/packages/integration-shims/src/Replay.ts b/packages/integration-shims/src/Replay.ts index 3bcc6c3e6563..ddebdbb14402 100644 --- a/packages/integration-shims/src/Replay.ts +++ b/packages/integration-shims/src/Replay.ts @@ -8,7 +8,7 @@ import { consoleSandbox } from '@sentry/utils'; * * @deprecated Use `replayIntegration()` instead. */ -class ReplayShim implements Integration { +export class ReplayShim implements Integration { /** * @inheritDoc */ @@ -56,10 +56,7 @@ class ReplayShim implements Integration { * It is needed in order for the CDN bundles to continue working when users add/remove replay * from it, without changing their config. This is necessary for the loader mechanism. */ -export function replayIntegration(_options: unknown): Integration { +export function replayIntegrationShim(_options: unknown): Integration { // eslint-disable-next-line deprecation/deprecation return new ReplayShim({}); } - -// eslint-disable-next-line deprecation/deprecation -export { ReplayShim as Replay }; diff --git a/packages/integration-shims/src/index.ts b/packages/integration-shims/src/index.ts index bffdf82c99f7..f069866bd257 100644 --- a/packages/integration-shims/src/index.ts +++ b/packages/integration-shims/src/index.ts @@ -1,18 +1,18 @@ export { // eslint-disable-next-line deprecation/deprecation - Feedback, - feedbackIntegration, + FeedbackShim, + feedbackIntegrationShim, } from './Feedback'; export { // eslint-disable-next-line deprecation/deprecation - Replay, - replayIntegration, + ReplayShim, + replayIntegrationShim, } from './Replay'; export { // eslint-disable-next-line deprecation/deprecation - BrowserTracing, - browserTracingIntegration, - addTracingExtensions, + BrowserTracingShim, + browserTracingIntegrationShim, + addTracingExtensionsShim, } from './BrowserTracing'; From a0407606b892332a81b82868acca32bad0af2c4f Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 22 Feb 2024 12:11:04 +0000 Subject: [PATCH 36/44] undo bold changes --- .../suites/public-api/startSpan/init.js | 5 +++-- .../suites/public-api/startTransaction/init.js | 5 +++-- packages/browser/src/index.bundle.feedback.ts | 6 ++++++ packages/browser/src/index.bundle.replay.ts | 6 ++++++ .../browser/src/index.bundle.tracing.replay.feedback.ts | 3 +++ packages/browser/src/index.bundle.tracing.replay.ts | 3 +++ packages/browser/src/index.bundle.tracing.ts | 3 +++ packages/browser/src/index.bundle.ts | 3 +++ 8 files changed, 30 insertions(+), 4 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/public-api/startSpan/init.js b/dev-packages/browser-integration-tests/suites/public-api/startSpan/init.js index d6e849bc7cae..b0bf1e869254 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/startSpan/init.js +++ b/dev-packages/browser-integration-tests/suites/public-api/startSpan/init.js @@ -1,6 +1,7 @@ +/* eslint-disable no-unused-vars */ import * as Sentry from '@sentry/browser'; - -Sentry.addTracingExtensions(); +// biome-ignore lint/nursery/noUnusedImports: Need to import tracing for side effect +import * as _ from '@sentry/tracing'; window.Sentry = Sentry; diff --git a/dev-packages/browser-integration-tests/suites/public-api/startTransaction/init.js b/dev-packages/browser-integration-tests/suites/public-api/startTransaction/init.js index 1c155f323586..e1903e2cc268 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/startTransaction/init.js +++ b/dev-packages/browser-integration-tests/suites/public-api/startTransaction/init.js @@ -1,6 +1,7 @@ +/* eslint-disable no-unused-vars */ import * as Sentry from '@sentry/browser'; - -Sentry.addTracingExtensions(); +// biome-ignore lint/nursery/noUnusedImports: Need to import tracing for side effect +import * as _ from '@sentry/tracing'; window.Sentry = Sentry; diff --git a/packages/browser/src/index.bundle.feedback.ts b/packages/browser/src/index.bundle.feedback.ts index 7cb0501e1a92..c58bc727631f 100644 --- a/packages/browser/src/index.bundle.feedback.ts +++ b/packages/browser/src/index.bundle.feedback.ts @@ -1,6 +1,7 @@ // This is exported so the loader does not fail when switching off Replay/Tracing import { Feedback, feedbackIntegration } from '@sentry-internal/feedback'; import { + BrowserTracingShim, ReplayShim, addTracingExtensionsShim, browserTracingIntegrationShim, @@ -13,8 +14,13 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = ReplayShim; +// eslint-disable-next-line deprecation/deprecation +Sentry.Integrations.BrowserTracing = BrowserTracingShim; + export * from './index.bundle.base'; export { + // eslint-disable-next-line deprecation/deprecation + BrowserTracingShim as BrowserTracing, browserTracingIntegrationShim as browserTracingIntegration, addTracingExtensionsShim as addTracingExtensions, // eslint-disable-next-line deprecation/deprecation diff --git a/packages/browser/src/index.bundle.replay.ts b/packages/browser/src/index.bundle.replay.ts index 71baed234eba..1faee95c698e 100644 --- a/packages/browser/src/index.bundle.replay.ts +++ b/packages/browser/src/index.bundle.replay.ts @@ -1,5 +1,6 @@ // This is exported so the loader does not fail when switching off Replay/Tracing import { + BrowserTracingShim, FeedbackShim, addTracingExtensionsShim, browserTracingIntegrationShim, @@ -13,8 +14,13 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; +// eslint-disable-next-line deprecation/deprecation +Sentry.Integrations.BrowserTracing = BrowserTracingShim; + export * from './index.bundle.base'; export { + // eslint-disable-next-line deprecation/deprecation + BrowserTracingShim as BrowserTracing, browserTracingIntegrationShim as browserTracingIntegration, addTracingExtensionsShim as addTracingExtensions, // eslint-disable-next-line deprecation/deprecation diff --git a/packages/browser/src/index.bundle.tracing.replay.feedback.ts b/packages/browser/src/index.bundle.tracing.replay.feedback.ts index eab59019dafd..274b03f4d991 100644 --- a/packages/browser/src/index.bundle.tracing.replay.feedback.ts +++ b/packages/browser/src/index.bundle.tracing.replay.feedback.ts @@ -11,6 +11,9 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; +// eslint-disable-next-line deprecation/deprecation +Sentry.Integrations.BrowserTracing = BrowserTracingShim; + // We are patching the global object with our hub extension methods addExtensionMethods(); diff --git a/packages/browser/src/index.bundle.tracing.replay.ts b/packages/browser/src/index.bundle.tracing.replay.ts index 8ff83643988e..86c50e3e6db8 100644 --- a/packages/browser/src/index.bundle.tracing.replay.ts +++ b/packages/browser/src/index.bundle.tracing.replay.ts @@ -10,6 +10,9 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; +// eslint-disable-next-line deprecation/deprecation +Sentry.Integrations.BrowserTracing = BrowserTracingShim; + // We are patching the global object with our hub extension methods addExtensionMethods(); diff --git a/packages/browser/src/index.bundle.tracing.ts b/packages/browser/src/index.bundle.tracing.ts index 525dd6a5b3b2..a75db13342d1 100644 --- a/packages/browser/src/index.bundle.tracing.ts +++ b/packages/browser/src/index.bundle.tracing.ts @@ -16,6 +16,9 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = ReplayShim; +// eslint-disable-next-line deprecation/deprecation +Sentry.Integrations.BrowserTracing = BrowserTracingShim; + // We are patching the global object with our hub extension methods addExtensionMethods(); diff --git a/packages/browser/src/index.bundle.ts b/packages/browser/src/index.bundle.ts index 97b4da50fc64..4c693da586cc 100644 --- a/packages/browser/src/index.bundle.ts +++ b/packages/browser/src/index.bundle.ts @@ -15,6 +15,9 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = ReplayShim; +// eslint-disable-next-line deprecation/deprecation +Sentry.Integrations.BrowserTracing = BrowserTracingShim; + export * from './index.bundle.base'; export { // eslint-disable-next-line deprecation/deprecation From 3d630b615e23bfd812e84ecda9c6c850dd0d3c5c Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 22 Feb 2024 15:50:55 +0000 Subject: [PATCH 37/44] test(browser-integration): Sync loader script fixture --- dev-packages/browser-integration-tests/fixtures/loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-packages/browser-integration-tests/fixtures/loader.js b/dev-packages/browser-integration-tests/fixtures/loader.js index d35fd69458a4..660243e0c7a6 100644 --- a/dev-packages/browser-integration-tests/fixtures/loader.js +++ b/dev-packages/browser-integration-tests/fixtures/loader.js @@ -1,4 +1,4 @@ -!function(n,e,t,r,i,o,a,c,u){for(var s=u,f=0;f-1){s&&"no"===document.scripts[f].getAttribute("data-lazy")&&(s=!1);break}var p=[];function d(n){return"e"in n}function l(n){return"p"in n}function _(n){return"f"in n}var v=[];function y(n){s&&(d(n)||l(n)||_(n)&&n.f.indexOf("capture")>-1||_(n)&&n.f.indexOf("showReportDialog")>-1)&&L(),v.push(n)}function h(){y({e:[].slice.call(arguments)})}function E(n){y({p:n})}function O(){try{n.SENTRY_SDK_SOURCE="loader";var e=n[i],o=e.init;e.init=function(i){n.removeEventListener(t,h),n.removeEventListener(r,E);var a=c;for(var u in i)Object.prototype.hasOwnProperty.call(i,u)&&(a[u]=i[u]);!function(n,e){var t=n.integrations||[];if(!Array.isArray(t))return;var r=t.map((function(n){return n.name}));n.tracesSampleRate&&-1===r.indexOf("BrowserTracing")&&t.push(new e.BrowserTracing);(n.replaysSessionSampleRate||n.replaysOnErrorSampleRate)&&-1===r.indexOf("Replay")&&t.push(new e.Replay);n.integrations=t}(a,e),o(a)},setTimeout((function(){return function(e){try{"function"==typeof n.sentryOnLoad&&(n.sentryOnLoad(),n.sentryOnLoad=void 0);for(var t=0;t-1){u&&"no"===document.scripts[f].getAttribute("data-lazy")&&(u=!1);break}var p=[];function l(n){return"e"in n}function d(n){return"p"in n}function _(n){return"f"in n}var v=[];function y(n){u&&(l(n)||d(n)||_(n)&&n.f.indexOf("capture")>-1||_(n)&&n.f.indexOf("showReportDialog")>-1)&&m(),v.push(n)}function g(){y({e:[].slice.call(arguments)})}function h(n){y({p:n})}function E(){try{n.SENTRY_SDK_SOURCE="loader";var e=n[i],o=e.init;e.init=function(i){n.removeEventListener(r,g),n.removeEventListener(t,h);var a=c;for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(a[s]=i[s]);!function(n,e){var r=n.integrations||[];if(!Array.isArray(r))return;var t=r.map((function(n){return n.name}));n.tracesSampleRate&&-1===t.indexOf("BrowserTracing")&&(e.browserTracingIntegration?r.push(e.browserTracingIntegration()):r.push(new e.BrowserTracing));(n.replaysSessionSampleRate||n.replaysOnErrorSampleRate)&&-1===t.indexOf("Replay")&&(e.replayIntegration?r.push(e.replayIntegration()):r.push(new e.Replay));n.integrations=r}(a,e),o(a)},setTimeout((function(){return function(e){try{"function"==typeof n.sentryOnLoad&&(n.sentryOnLoad(),n.sentryOnLoad=void 0);for(var r=0;r Date: Thu, 22 Feb 2024 19:47:09 +0000 Subject: [PATCH 38/44] sync --- dev-packages/browser-integration-tests/fixtures/loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-packages/browser-integration-tests/fixtures/loader.js b/dev-packages/browser-integration-tests/fixtures/loader.js index 660243e0c7a6..2f4705810b2f 100644 --- a/dev-packages/browser-integration-tests/fixtures/loader.js +++ b/dev-packages/browser-integration-tests/fixtures/loader.js @@ -1,4 +1,4 @@ -!function(n,e,r,t,i,o,a,c,s){for(var u=s,f=0;f-1){u&&"no"===document.scripts[f].getAttribute("data-lazy")&&(u=!1);break}var p=[];function l(n){return"e"in n}function d(n){return"p"in n}function _(n){return"f"in n}var v=[];function y(n){u&&(l(n)||d(n)||_(n)&&n.f.indexOf("capture")>-1||_(n)&&n.f.indexOf("showReportDialog")>-1)&&m(),v.push(n)}function g(){y({e:[].slice.call(arguments)})}function h(n){y({p:n})}function E(){try{n.SENTRY_SDK_SOURCE="loader";var e=n[i],o=e.init;e.init=function(i){n.removeEventListener(r,g),n.removeEventListener(t,h);var a=c;for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(a[s]=i[s]);!function(n,e){var r=n.integrations||[];if(!Array.isArray(r))return;var t=r.map((function(n){return n.name}));n.tracesSampleRate&&-1===t.indexOf("BrowserTracing")&&(e.browserTracingIntegration?r.push(e.browserTracingIntegration()):r.push(new e.BrowserTracing));(n.replaysSessionSampleRate||n.replaysOnErrorSampleRate)&&-1===t.indexOf("Replay")&&(e.replayIntegration?r.push(e.replayIntegration()):r.push(new e.Replay));n.integrations=r}(a,e),o(a)},setTimeout((function(){return function(e){try{"function"==typeof n.sentryOnLoad&&(n.sentryOnLoad(),n.sentryOnLoad=void 0);for(var r=0;r-1){u&&"no"===document.scripts[f].getAttribute("data-lazy")&&(u=!1);break}var p=[];function l(n){return"e"in n}function d(n){return"p"in n}function _(n){return"f"in n}var v=[];function y(n){u&&(l(n)||d(n)||_(n)&&n.f.indexOf("capture")>-1||_(n)&&n.f.indexOf("showReportDialog")>-1)&&m(),v.push(n)}function g(){y({e:[].slice.call(arguments)})}function h(n){y({p:n})}function E(){try{n.SENTRY_SDK_SOURCE="loader";var e=n[i],o=e.init;e.init=function(i){n.removeEventListener(r,g),n.removeEventListener(t,h);var a=c;for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(a[s]=i[s]);!function(n,e){var r=n.integrations||[];if(!Array.isArray(r))return;var t=r.map((function(n){return n.name}));n.tracesSampleRate&&-1===t.indexOf("BrowserTracing")&&(e.BrowserTracing?r.push(new e.BrowserTracing):e.browserTracingIntegration&&r.push(e.browserTracingIntegration()));(n.replaysSessionSampleRate||n.replaysOnErrorSampleRate)&&-1===t.indexOf("Replay")&&(e.Replay?r.push(new e.Replay):e.replayIntegration&&r.push(e.replayIntegration()));n.integrations=r}(a,e),o(a)},setTimeout((function(){return function(e){try{"function"==typeof n.sentryOnLoad&&(n.sentryOnLoad(),n.sentryOnLoad=void 0);for(var r=0;r Date: Thu, 22 Feb 2024 20:46:04 +0000 Subject: [PATCH 39/44] dayum --- packages/browser/src/index.bundle.feedback.ts | 6 ------ packages/browser/src/index.bundle.replay.ts | 6 ------ .../src/index.bundle.tracing.replay.feedback.ts | 6 ------ .../browser/src/index.bundle.tracing.replay.ts | 7 +------ packages/browser/src/index.bundle.tracing.ts | 6 ------ packages/browser/src/index.bundle.ts | 6 ------ packages/integration-shims/src/BrowserTracing.ts | 4 +--- packages/integration-shims/src/index.ts | 2 -- yarn.lock | 15 ++++----------- 9 files changed, 6 insertions(+), 52 deletions(-) diff --git a/packages/browser/src/index.bundle.feedback.ts b/packages/browser/src/index.bundle.feedback.ts index c58bc727631f..7cb0501e1a92 100644 --- a/packages/browser/src/index.bundle.feedback.ts +++ b/packages/browser/src/index.bundle.feedback.ts @@ -1,7 +1,6 @@ // This is exported so the loader does not fail when switching off Replay/Tracing import { Feedback, feedbackIntegration } from '@sentry-internal/feedback'; import { - BrowserTracingShim, ReplayShim, addTracingExtensionsShim, browserTracingIntegrationShim, @@ -14,13 +13,8 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = ReplayShim; -// eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.BrowserTracing = BrowserTracingShim; - export * from './index.bundle.base'; export { - // eslint-disable-next-line deprecation/deprecation - BrowserTracingShim as BrowserTracing, browserTracingIntegrationShim as browserTracingIntegration, addTracingExtensionsShim as addTracingExtensions, // eslint-disable-next-line deprecation/deprecation diff --git a/packages/browser/src/index.bundle.replay.ts b/packages/browser/src/index.bundle.replay.ts index 1faee95c698e..71baed234eba 100644 --- a/packages/browser/src/index.bundle.replay.ts +++ b/packages/browser/src/index.bundle.replay.ts @@ -1,6 +1,5 @@ // This is exported so the loader does not fail when switching off Replay/Tracing import { - BrowserTracingShim, FeedbackShim, addTracingExtensionsShim, browserTracingIntegrationShim, @@ -14,13 +13,8 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; -// eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.BrowserTracing = BrowserTracingShim; - export * from './index.bundle.base'; export { - // eslint-disable-next-line deprecation/deprecation - BrowserTracingShim as BrowserTracing, browserTracingIntegrationShim as browserTracingIntegration, addTracingExtensionsShim as addTracingExtensions, // eslint-disable-next-line deprecation/deprecation diff --git a/packages/browser/src/index.bundle.tracing.replay.feedback.ts b/packages/browser/src/index.bundle.tracing.replay.feedback.ts index 274b03f4d991..fd6efc3824f4 100644 --- a/packages/browser/src/index.bundle.tracing.replay.feedback.ts +++ b/packages/browser/src/index.bundle.tracing.replay.feedback.ts @@ -1,5 +1,4 @@ import { Feedback, feedbackIntegration } from '@sentry-internal/feedback'; -import { BrowserTracingShim } from '@sentry-internal/integration-shims'; import { addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing'; import { Replay, replayIntegration } from '@sentry/replay'; @@ -11,9 +10,6 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; -// eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.BrowserTracing = BrowserTracingShim; - // We are patching the global object with our hub extension methods addExtensionMethods(); @@ -24,8 +20,6 @@ export { Replay, feedbackIntegration, replayIntegration, - // eslint-disable-next-line deprecation/deprecation - BrowserTracingShim as BrowserTracing, browserTracingIntegration, addExtensionMethods, }; diff --git a/packages/browser/src/index.bundle.tracing.replay.ts b/packages/browser/src/index.bundle.tracing.replay.ts index 86c50e3e6db8..07180e5ea983 100644 --- a/packages/browser/src/index.bundle.tracing.replay.ts +++ b/packages/browser/src/index.bundle.tracing.replay.ts @@ -1,4 +1,4 @@ -import { BrowserTracingShim, FeedbackShim, feedbackIntegrationShim } from '@sentry-internal/integration-shims'; +import { FeedbackShim, feedbackIntegrationShim } from '@sentry-internal/integration-shims'; import { addExtensionMethods, browserTracingIntegration } from '@sentry-internal/tracing'; import { Replay, replayIntegration } from '@sentry/replay'; @@ -10,9 +10,6 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = Replay; -// eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.BrowserTracing = BrowserTracingShim; - // We are patching the global object with our hub extension methods addExtensionMethods(); @@ -23,8 +20,6 @@ export { Replay, replayIntegration, feedbackIntegrationShim as feedbackIntegration, - // eslint-disable-next-line deprecation/deprecation - BrowserTracingShim as BrowserTracing, browserTracingIntegration, addExtensionMethods, }; diff --git a/packages/browser/src/index.bundle.tracing.ts b/packages/browser/src/index.bundle.tracing.ts index a75db13342d1..9eb61ba11ad6 100644 --- a/packages/browser/src/index.bundle.tracing.ts +++ b/packages/browser/src/index.bundle.tracing.ts @@ -1,6 +1,5 @@ // This is exported so the loader does not fail when switching off Replay import { - BrowserTracingShim, FeedbackShim, ReplayShim, feedbackIntegrationShim, @@ -16,9 +15,6 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = ReplayShim; -// eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.BrowserTracing = BrowserTracingShim; - // We are patching the global object with our hub extension methods addExtensionMethods(); @@ -29,8 +25,6 @@ export { ReplayShim as Replay, feedbackIntegrationShim as feedbackIntegration, replayIntegrationShim as replayIntegration, - // eslint-disable-next-line deprecation/deprecation - BrowserTracingShim as BrowserTracing, browserTracingIntegration, addExtensionMethods, }; diff --git a/packages/browser/src/index.bundle.ts b/packages/browser/src/index.bundle.ts index 4c693da586cc..b113bd56d142 100644 --- a/packages/browser/src/index.bundle.ts +++ b/packages/browser/src/index.bundle.ts @@ -1,6 +1,5 @@ // This is exported so the loader does not fail when switching off Replay/Tracing import { - BrowserTracingShim, FeedbackShim, ReplayShim, addTracingExtensionsShim, @@ -15,13 +14,8 @@ import * as Sentry from './index.bundle.base'; // eslint-disable-next-line deprecation/deprecation Sentry.Integrations.Replay = ReplayShim; -// eslint-disable-next-line deprecation/deprecation -Sentry.Integrations.BrowserTracing = BrowserTracingShim; - export * from './index.bundle.base'; export { - // eslint-disable-next-line deprecation/deprecation - BrowserTracingShim as BrowserTracing, addTracingExtensionsShim as addTracingExtensions, // eslint-disable-next-line deprecation/deprecation ReplayShim as Replay, diff --git a/packages/integration-shims/src/BrowserTracing.ts b/packages/integration-shims/src/BrowserTracing.ts index adc7d873a3ab..9ffa0ac40a1b 100644 --- a/packages/integration-shims/src/BrowserTracing.ts +++ b/packages/integration-shims/src/BrowserTracing.ts @@ -5,10 +5,8 @@ import { consoleSandbox } from '@sentry/utils'; * This is a shim for the BrowserTracing integration. * It is needed in order for the CDN bundles to continue working when users add/remove tracing * from it, without changing their config. This is necessary for the loader mechanism. - * - * @deprecated Use `browserTracingIntegration()` instead. */ -export class BrowserTracingShim implements Integration { +class BrowserTracingShim implements Integration { /** * @inheritDoc */ diff --git a/packages/integration-shims/src/index.ts b/packages/integration-shims/src/index.ts index f069866bd257..64124f4a93cc 100644 --- a/packages/integration-shims/src/index.ts +++ b/packages/integration-shims/src/index.ts @@ -11,8 +11,6 @@ export { } from './Replay'; export { - // eslint-disable-next-line deprecation/deprecation - BrowserTracingShim, browserTracingIntegrationShim, addTracingExtensionsShim, } from './BrowserTracing'; diff --git a/yarn.lock b/yarn.lock index 4129f1dc7db5..4b7fce9c5a1e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5183,17 +5183,10 @@ resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.21.tgz#5de5a2385a35309427f6011992b544514d559aa1" integrity sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g== -"@prisma/client@3.15.2": - version "3.15.2" - resolved "https://registry.yarnpkg.com/@prisma/client/-/client-3.15.2.tgz#2181398147afc79bfe0d83c03a88dc45b49bd365" - integrity sha512-ErqtwhX12ubPhU4d++30uFY/rPcyvjk+mdifaZO5SeM21zS3t4jQrscy8+6IyB0GIYshl5ldTq6JSBo1d63i8w== - dependencies: - "@prisma/engines-version" "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" - -"@prisma/engines-version@3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e": - version "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" - resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz#bf5e2373ca68ce7556b967cb4965a7095e93fe53" - integrity sha512-e3k2Vd606efd1ZYy2NQKkT4C/pn31nehyLhVug6To/q8JT8FpiMrDy7zmm3KLF0L98NOQQcutaVtAPhzKhzn9w== +"@prisma/client@5.9.1": + version "5.9.1" + resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.9.1.tgz#d92bd2f7f006e0316cb4fda9d73f235965cf2c64" + integrity sha512-caSOnG4kxcSkhqC/2ShV7rEoWwd3XrftokxJqOCMVvia4NYV/TPtJlS9C2os3Igxw/Qyxumj9GBQzcStzECvtQ== "@prisma/instrumentation@5.9.0": version "5.9.0" From b1755c9b69dc24b8c6bf290acc60db12b57ba769 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 22 Feb 2024 21:37:34 +0000 Subject: [PATCH 40/44] . --- .../test/unit/index.bundle.feedback.test.ts | 4 +- .../test/unit/index.bundle.replay.test.ts | 4 +- .../browser/test/unit/index.bundle.test.ts | 3 -- packages/integration-shims/package.json | 1 + .../integration-shims/src/BrowserTracing.ts | 45 ++++--------------- 5 files changed, 12 insertions(+), 45 deletions(-) diff --git a/packages/browser/test/unit/index.bundle.feedback.test.ts b/packages/browser/test/unit/index.bundle.feedback.test.ts index a480c4453b47..91475a34bb02 100644 --- a/packages/browser/test/unit/index.bundle.feedback.test.ts +++ b/packages/browser/test/unit/index.bundle.feedback.test.ts @@ -1,5 +1,5 @@ /* eslint-disable deprecation/deprecation */ -import { BrowserTracingShim, ReplayShim, replayIntegrationShim } from '@sentry-internal/integration-shims'; +import { ReplayShim, replayIntegrationShim } from '@sentry-internal/integration-shims'; import { Feedback, feedbackIntegration } from '@sentry/browser'; import * as TracingReplayBundle from '../../src/index.bundle.feedback'; @@ -14,8 +14,6 @@ describe('index.bundle.feedback', () => { expect(TracingReplayBundle.Replay).toBe(ReplayShim); expect(TracingReplayBundle.replayIntegration).toBe(replayIntegrationShim); - expect(TracingReplayBundle.browserTracingIntegration()).toBeInstanceOf(BrowserTracingShim); - expect(TracingReplayBundle.Feedback).toBe(Feedback); expect(TracingReplayBundle.feedbackIntegration).toBe(feedbackIntegration); }); diff --git a/packages/browser/test/unit/index.bundle.replay.test.ts b/packages/browser/test/unit/index.bundle.replay.test.ts index 3f620f1f692c..a40daa2ea0d6 100644 --- a/packages/browser/test/unit/index.bundle.replay.test.ts +++ b/packages/browser/test/unit/index.bundle.replay.test.ts @@ -1,5 +1,5 @@ /* eslint-disable deprecation/deprecation */ -import { BrowserTracingShim, FeedbackShim, feedbackIntegrationShim } from '@sentry-internal/integration-shims'; +import { FeedbackShim, feedbackIntegrationShim } from '@sentry-internal/integration-shims'; import { Replay, replayIntegration } from '@sentry/browser'; import * as TracingReplayBundle from '../../src/index.bundle.replay'; @@ -14,8 +14,6 @@ describe('index.bundle.replay', () => { expect(TracingReplayBundle.Replay).toBe(Replay); expect(TracingReplayBundle.replayIntegration).toBe(replayIntegration); - expect(TracingReplayBundle.browserTracingIntegration()).toBeInstanceOf(BrowserTracingShim); - expect(TracingReplayBundle.Feedback).toBe(FeedbackShim); expect(TracingReplayBundle.feedbackIntegration).toBe(feedbackIntegrationShim); }); diff --git a/packages/browser/test/unit/index.bundle.test.ts b/packages/browser/test/unit/index.bundle.test.ts index 80b4b39a7174..bf498477c73c 100644 --- a/packages/browser/test/unit/index.bundle.test.ts +++ b/packages/browser/test/unit/index.bundle.test.ts @@ -1,6 +1,5 @@ /* eslint-disable deprecation/deprecation */ import { - BrowserTracingShim, FeedbackShim, ReplayShim, feedbackIntegrationShim, @@ -19,8 +18,6 @@ describe('index.bundle', () => { expect(TracingBundle.Replay).toBe(ReplayShim); expect(TracingBundle.replayIntegration).toBe(replayIntegrationShim); - expect(TracingBundle.browserTracingIntegration()).toBeInstanceOf(BrowserTracingShim); - expect(TracingBundle.Feedback).toBe(FeedbackShim); expect(TracingBundle.feedbackIntegration).toBe(feedbackIntegrationShim); }); diff --git a/packages/integration-shims/package.json b/packages/integration-shims/package.json index 5bc5f40f039d..3d2c599058c8 100644 --- a/packages/integration-shims/package.json +++ b/packages/integration-shims/package.json @@ -39,6 +39,7 @@ "url": "https://github.com/getsentry/sentry-javascript/issues" }, "dependencies": { + "@sentry/core": "7.100.0", "@sentry/types": "7.100.0", "@sentry/utils": "7.100.0" }, diff --git a/packages/integration-shims/src/BrowserTracing.ts b/packages/integration-shims/src/BrowserTracing.ts index 9ffa0ac40a1b..e717e93260c8 100644 --- a/packages/integration-shims/src/BrowserTracing.ts +++ b/packages/integration-shims/src/BrowserTracing.ts @@ -1,4 +1,4 @@ -import type { Integration } from '@sentry/types'; +import { defineIntegration } from '@sentry/core'; import { consoleSandbox } from '@sentry/utils'; /** @@ -6,43 +6,16 @@ import { consoleSandbox } from '@sentry/utils'; * It is needed in order for the CDN bundles to continue working when users add/remove tracing * from it, without changing their config. This is necessary for the loader mechanism. */ -class BrowserTracingShim implements Integration { - /** - * @inheritDoc - */ - public static id: string = 'BrowserTracing'; +export const browserTracingIntegrationShim = defineIntegration((_options?: unknown) => { + consoleSandbox(() => { + // eslint-disable-next-line no-console + console.warn('You are using new BrowserTracing() even though this bundle does not include tracing.'); + }); - /** - * @inheritDoc - */ - public name: string; - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - public constructor(_options: any) { - // eslint-disable-next-line deprecation/deprecation - this.name = BrowserTracingShim.id; - - consoleSandbox(() => { - // eslint-disable-next-line no-console - console.warn('You are using new BrowserTracing() even though this bundle does not include tracing.'); - }); - } - - /** jsdoc */ - public setupOnce(): void { - // noop + return { + name: 'BrowserTracing' } -} - -/** - * This is a shim for the BrowserTracing integration. - * It is needed in order for the CDN bundles to continue working when users add/remove tracing - * from it, without changing their config. This is necessary for the loader mechanism. - */ -export function browserTracingIntegrationShim(_options?: unknown): Integration { - // eslint-disable-next-line deprecation/deprecation - return new BrowserTracingShim({}); -} +}) /** Shim function */ export function addTracingExtensionsShim(): void { From 0dd2b99fae0a52956b00d79311578b507c1dfacd Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 23 Feb 2024 07:31:17 +0000 Subject: [PATCH 41/44] Remove unnecessary tests --- .../browserTracingIntegrationHashShim/init.js | 12 ------- .../template.html | 9 ----- .../browserTracingIntegrationHashShim/test.ts | 36 ------------------- .../suites/tracing/browserTracingShim/init.js | 12 ------- .../tracing/browserTracingShim/template.html | 9 ----- .../suites/tracing/browserTracingShim/test.ts | 33 ----------------- 6 files changed, 111 deletions(-) delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/template.html delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/test.ts delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/template.html delete mode 100644 dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/test.ts diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/init.js b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/init.js deleted file mode 100644 index d7cfd52aedcc..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/init.js +++ /dev/null @@ -1,12 +0,0 @@ -import * as Sentry from '@sentry/browser'; - -window.Sentry = Sentry; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - sampleRate: 1, - integrations: [Sentry.browserTracingIntegration()], -}); - -// This should not fail -Sentry.addTracingExtensions(); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/template.html b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/template.html deleted file mode 100644 index 2b3e2f0b27b4..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/template.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/test.ts deleted file mode 100644 index e37181ee815b..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationHashShim/test.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { expect } from '@playwright/test'; - -import { sentryTest } from '../../../utils/fixtures'; -import { shouldSkipTracingTest } from '../../../utils/helpers'; - -sentryTest( - 'exports a shim Integrations.BrowserTracing integration for non-tracing bundles', - async ({ getLocalTestPath, page }) => { - // Skip in tracing tests - if (!shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const consoleMessages: string[] = []; - page.on('console', msg => consoleMessages.push(msg.text())); - - let requestCount = 0; - await page.route('https://dsn.ingest.sentry.io/**/*', route => { - requestCount++; - return route.fulfill({ - status: 200, - contentType: 'application/json', - body: JSON.stringify({ id: 'test-id' }), - }); - }); - - const url = await getLocalTestPath({ testDir: __dirname }); - - await page.goto(url); - - expect(requestCount).toBe(0); - expect(consoleMessages).toEqual([ - 'You are using new BrowserTracing() even though this bundle does not include tracing.', - ]); - }, -); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js b/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js deleted file mode 100644 index d7cfd52aedcc..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/init.js +++ /dev/null @@ -1,12 +0,0 @@ -import * as Sentry from '@sentry/browser'; - -window.Sentry = Sentry; - -Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', - sampleRate: 1, - integrations: [Sentry.browserTracingIntegration()], -}); - -// This should not fail -Sentry.addTracingExtensions(); diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/template.html b/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/template.html deleted file mode 100644 index 2b3e2f0b27b4..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/template.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/test.ts deleted file mode 100644 index 7b6027694734..000000000000 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingShim/test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { expect } from '@playwright/test'; - -import { sentryTest } from '../../../utils/fixtures'; -import { shouldSkipTracingTest } from '../../../utils/helpers'; - -sentryTest('exports a shim BrowserTracing integration for non-tracing bundles', async ({ getLocalTestPath, page }) => { - // Skip in tracing tests - if (!shouldSkipTracingTest()) { - sentryTest.skip(); - } - - const consoleMessages: string[] = []; - page.on('console', msg => consoleMessages.push(msg.text())); - - let requestCount = 0; - await page.route('https://dsn.ingest.sentry.io/**/*', route => { - requestCount++; - return route.fulfill({ - status: 200, - contentType: 'application/json', - body: JSON.stringify({ id: 'test-id' }), - }); - }); - - const url = await getLocalTestPath({ testDir: __dirname }); - - await page.goto(url); - - expect(requestCount).toBe(0); - expect(consoleMessages).toEqual([ - 'You are using new BrowserTracing() even though this bundle does not include tracing.', - ]); -}); From 30ac18d826ff5f759a88b6a2ee3f29182b95038d Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 23 Feb 2024 07:38:12 +0000 Subject: [PATCH 42/44] . --- packages/integration-shims/src/BrowserTracing.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/integration-shims/src/BrowserTracing.ts b/packages/integration-shims/src/BrowserTracing.ts index e717e93260c8..32841d842718 100644 --- a/packages/integration-shims/src/BrowserTracing.ts +++ b/packages/integration-shims/src/BrowserTracing.ts @@ -13,9 +13,9 @@ export const browserTracingIntegrationShim = defineIntegration((_options?: unkno }); return { - name: 'BrowserTracing' - } -}) + name: 'BrowserTracing', + }; +}); /** Shim function */ export function addTracingExtensionsShim(): void { From e70dfb60e2681c1274eb09ae9f4915e4f7c89839 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 23 Feb 2024 07:44:59 +0000 Subject: [PATCH 43/44] rip --- .../suites/tracing/browserTracingIntegrationShim/init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationShim/init.js b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationShim/init.js index e8ba5702cff8..d7cfd52aedcc 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationShim/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegrationShim/init.js @@ -5,7 +5,7 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', sampleRate: 1, - integrations: [new Sentry.browserTracingIntegration()], + integrations: [Sentry.browserTracingIntegration()], }); // This should not fail From 1ffe69f0f603c3d2737413a47e48595696fe0be5 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 23 Feb 2024 08:08:59 +0000 Subject: [PATCH 44/44] merge artifact --- .../browser-integration-tests/suites/tracing/metrics/init.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/tracing/metrics/init.js b/dev-packages/browser-integration-tests/suites/tracing/metrics/init.js index d7725bdaf4eb..ad1d8832b228 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/metrics/init.js +++ b/dev-packages/browser-integration-tests/suites/tracing/metrics/init.js @@ -5,11 +5,7 @@ window.Sentry = Sentry; Sentry.init({ dsn: 'https://public@dsn.ingest.sentry.io/1337', integrations: [ -<<<<<<< HEAD Sentry.browserTracingIntegration({ -======= - new Sentry.BrowserTracing({ ->>>>>>> origin/develop idleTimeout: 9000, }), ],