Skip to content

Commit

Permalink
feat(nextjs): Always add browserTracingIntegration (#13324)
Browse files Browse the repository at this point in the history
closes #13012

ref: #13323
  • Loading branch information
s1gr1d committed Aug 13, 2024
1 parent 0e7c492 commit 70e1815
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
11 changes: 4 additions & 7 deletions packages/nextjs/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
Expand Down
21 changes: 8 additions & 13 deletions packages/nextjs/test/clientSdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,33 +130,28 @@ describe('Client init()', () => {
});

describe('browserTracingIntegration()', () => {
it('adds `browserTracingIntegration()` integration if `tracesSampleRate` is set', () => {
it('adds the browserTracingIntegration when `__SENTRY_TRACING__` is not set', () => {
const client = init({
dsn: TEST_DSN,
tracesSampleRate: 1.0,
});

const browserTracingIntegration = client?.getIntegrationByName('BrowserTracing');
expect(browserTracingIntegration?.name).toBe('BrowserTracing');
expect(browserTracingIntegration).toBeDefined();
});

it('adds `browserTracingIntegration()` integration if `tracesSampler` is set', () => {
const client = init({
dsn: TEST_DSN,
tracesSampler: () => true,
});
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 browserTracingIntegration = client?.getIntegrationByName('BrowserTracing');
expect(browserTracingIntegration?.name).toBe('BrowserTracing');
});

it('does not add `browserTracingIntegration()` integration if tracing not enabled in SDK', () => {
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__;
});
});
});
Expand Down

0 comments on commit 70e1815

Please sign in to comment.