Skip to content

feat(nextjs): Always add browserTracingIntegration #13324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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)', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: Instead of modifying this test I would simplify this one and the one above to simply assert that the integration was added. No point to test an invariant imo.

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
Loading