From bb822069f4e978c1e9c862bdf7908c2c11090c52 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Mon, 12 Aug 2024 16:43:37 +0200 Subject: [PATCH 1/5] feat(nextjs): Always add browserTracingIntegration --- packages/nextjs/src/client/index.ts | 9 +++------ packages/nextjs/test/clientSdk.test.ts | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/nextjs/src/client/index.ts b/packages/nextjs/src/client/index.ts index 597cc3d4cd91..795019cc0053 100644 --- a/packages/nextjs/src/client/index.ts +++ b/packages/nextjs/src/client/index.ts @@ -48,13 +48,10 @@ export function init(options: BrowserOptions): Client | undefined { function getDefaultIntegrations(options: BrowserOptions): Integration[] { const customDefaultIntegrations = getReactDefaultIntegrations(options); - - // This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", in which case everything inside - // will get treeshaken away + // This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", + // in which case everything inside will get tree-shaken away if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) { - if (hasTracingEnabled(options)) { - customDefaultIntegrations.push(browserTracingIntegration()); - } + customDefaultIntegrations.push(browserTracingIntegration()); } // This value is injected at build time, based on the output directory specified in the build config. Though a default diff --git a/packages/nextjs/test/clientSdk.test.ts b/packages/nextjs/test/clientSdk.test.ts index 169c7cde5bfc..d54953abee4c 100644 --- a/packages/nextjs/test/clientSdk.test.ts +++ b/packages/nextjs/test/clientSdk.test.ts @@ -150,13 +150,28 @@ describe('Client init()', () => { expect(browserTracingIntegration?.name).toBe('BrowserTracing'); }); - it('does not add `browserTracingIntegration()` integration if tracing not enabled in SDK', () => { + it('also adds `browserTracingIntegration()` integration if tracing not enabled in SDK (only build time)', () => { + const client = init({ + dsn: TEST_DSN, + }); + + const browserTracingIntegration = client?.getIntegrationByName('BrowserTracing'); + expect(browserTracingIntegration?.name).toBe('BrowserTracing'); + }); + + it("doesn't add a browserTracingIntegration if `__SENTRY_TRACING__` is set to false", () => { + // @ts-expect-error Test setup for build-time flag + globalThis.__SENTRY_TRACING__ = false; + const client = init({ dsn: TEST_DSN, }); const browserTracingIntegration = client?.getIntegrationByName('BrowserTracing'); expect(browserTracingIntegration).toBeUndefined(); + + // @ts-expect-error Test setup for build-time flag + delete globalThis.__SENTRY_TRACING__; }); }); }); From 9245c632c7b875885bdbfe7aa7436c1728e46870 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Mon, 12 Aug 2024 17:07:04 +0200 Subject: [PATCH 2/5] delete import --- packages/nextjs/src/client/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nextjs/src/client/index.ts b/packages/nextjs/src/client/index.ts index 795019cc0053..a68734a10398 100644 --- a/packages/nextjs/src/client/index.ts +++ b/packages/nextjs/src/client/index.ts @@ -1,4 +1,4 @@ -import { addEventProcessor, applySdkMetadata, hasTracingEnabled } from '@sentry/core'; +import { addEventProcessor, applySdkMetadata } from '@sentry/core'; import type { BrowserOptions } from '@sentry/react'; import { getDefaultIntegrations as getReactDefaultIntegrations, init as reactInit } from '@sentry/react'; import type { Client, EventProcessor, Integration } from '@sentry/types'; From 541a9628d8d957fd73ffc6346acbd34185d5cc2a Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Mon, 12 Aug 2024 17:56:12 +0200 Subject: [PATCH 3/5] simplify tests --- packages/nextjs/test/clientSdk.test.ts | 31 ++++++++------------------ 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/packages/nextjs/test/clientSdk.test.ts b/packages/nextjs/test/clientSdk.test.ts index d54953abee4c..d8b0c97d41df 100644 --- a/packages/nextjs/test/clientSdk.test.ts +++ b/packages/nextjs/test/clientSdk.test.ts @@ -130,33 +130,20 @@ describe('Client init()', () => { }); describe('browserTracingIntegration()', () => { - it('adds `browserTracingIntegration()` integration if `tracesSampleRate` is set', () => { + it.each([ + ['tracesSampleRate', { tracesSampleRate: 0 }], + ['tracesSampleRate', { tracesSampleRate: 1 }], + ['tracesSampler', { tracesSampler: () => true }], + ['enableTracing', { enableTracing: true }], + ['no tracing option set', {}], + ])('adds a browserTracingIntegration if tracing is enabled via %s', (_, tracingOptions) => { const client = init({ dsn: TEST_DSN, - tracesSampleRate: 1.0, + ...tracingOptions, }); const browserTracingIntegration = client?.getIntegrationByName('BrowserTracing'); - expect(browserTracingIntegration?.name).toBe('BrowserTracing'); - }); - - it('adds `browserTracingIntegration()` integration if `tracesSampler` is set', () => { - const client = init({ - dsn: TEST_DSN, - tracesSampler: () => true, - }); - - const browserTracingIntegration = client?.getIntegrationByName('BrowserTracing'); - expect(browserTracingIntegration?.name).toBe('BrowserTracing'); - }); - - it('also adds `browserTracingIntegration()` integration if tracing not enabled in SDK (only build time)', () => { - const client = init({ - dsn: TEST_DSN, - }); - - const browserTracingIntegration = client?.getIntegrationByName('BrowserTracing'); - expect(browserTracingIntegration?.name).toBe('BrowserTracing'); + expect(browserTracingIntegration).toBeDefined(); }); it("doesn't add a browserTracingIntegration if `__SENTRY_TRACING__` is set to false", () => { From 8e3ba1917b091a6bdc2e254fef071748c1523a17 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Mon, 12 Aug 2024 18:04:23 +0200 Subject: [PATCH 4/5] simplify tests 2 --- packages/nextjs/test/clientSdk.test.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/nextjs/test/clientSdk.test.ts b/packages/nextjs/test/clientSdk.test.ts index d8b0c97d41df..ac159564410b 100644 --- a/packages/nextjs/test/clientSdk.test.ts +++ b/packages/nextjs/test/clientSdk.test.ts @@ -130,16 +130,9 @@ describe('Client init()', () => { }); describe('browserTracingIntegration()', () => { - it.each([ - ['tracesSampleRate', { tracesSampleRate: 0 }], - ['tracesSampleRate', { tracesSampleRate: 1 }], - ['tracesSampler', { tracesSampler: () => true }], - ['enableTracing', { enableTracing: true }], - ['no tracing option set', {}], - ])('adds a browserTracingIntegration if tracing is enabled via %s', (_, tracingOptions) => { + it('adds the browserTracingIntegration when `__SENTRY_TRACING__` is not set', () => { const client = init({ dsn: TEST_DSN, - ...tracingOptions, }); const browserTracingIntegration = client?.getIntegrationByName('BrowserTracing'); From 71bdbcbd1eb39fefa30e56015b20ef9cc7660967 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Tue, 13 Aug 2024 10:23:07 +0200 Subject: [PATCH 5/5] modify size limit --- .size-limit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.size-limit.js b/.size-limit.js index 6369aa49e3e9..80aa4c5095ea 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -193,7 +193,7 @@ module.exports = [ import: createImport('init'), ignore: ['next/router', 'next/constants'], gzip: true, - limit: '38.03 KB', + limit: '38.05 KB', }, // SvelteKit SDK (ESM) {