Skip to content
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

feat(nextjs): Always add browserTracingIntegration #13324

Merged
merged 7 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading