Skip to content

Commit

Permalink
feat(nextjs): Always add browserTracingIntegration
Browse files Browse the repository at this point in the history
  • Loading branch information
s1gr1d committed Aug 12, 2024
1 parent 69a5e8e commit bb82206
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
9 changes: 3 additions & 6 deletions packages/nextjs/src/client/index.ts
Original file line number Diff line number Diff line change
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
17 changes: 16 additions & 1 deletion packages/nextjs/test/clientSdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
});
});
});
Expand Down

0 comments on commit bb82206

Please sign in to comment.