Skip to content

Commit 88105c4

Browse files
committed
refactor client integrations code to match server integrations code
1 parent acef63c commit 88105c4

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

packages/nextjs/src/index.client.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { configureScope, init as reactInit, Integrations } from '@sentry/react';
2-
import { BrowserTracing, defaultRequestInstrumentationOptions } from '@sentry/tracing';
2+
import { BrowserTracing, defaultRequestInstrumentationOptions, hasTracingEnabled } from '@sentry/tracing';
33
import { EventProcessor } from '@sentry/types';
44

55
import { nextRouterInstrumentation } from './performance/client';
66
import { buildMetadata } from './utils/metadata';
77
import { NextjsOptions } from './utils/nextjsOptions';
8-
import { addOrUpdateIntegration, UserIntegrations } from './utils/userIntegrations';
8+
import { addOrUpdateIntegration } from './utils/userIntegrations';
99

1010
export * from '@sentry/react';
1111
export { nextRouterInstrumentation } from './performance/client';
@@ -32,21 +32,9 @@ declare const __SENTRY_TRACING__: boolean;
3232
export function init(options: NextjsOptions): void {
3333
buildMetadata(options, ['nextjs', 'react']);
3434
options.environment = options.environment || process.env.NODE_ENV;
35+
addClientIntegrations(options);
3536

36-
let integrations = options.integrations;
37-
38-
// Guard below evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false"
39-
if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
40-
// Only add BrowserTracing if a tracesSampleRate or tracesSampler is set
41-
if (options.tracesSampleRate !== undefined || options.tracesSampler !== undefined) {
42-
integrations = createClientIntegrations(options.integrations);
43-
}
44-
}
45-
46-
reactInit({
47-
...options,
48-
integrations,
49-
});
37+
reactInit(options);
5038

5139
configureScope(scope => {
5240
scope.setTag('runtime', 'browser');
@@ -57,14 +45,24 @@ export function init(options: NextjsOptions): void {
5745
});
5846
}
5947

60-
function createClientIntegrations(userIntegrations: UserIntegrations = []): UserIntegrations {
61-
const defaultBrowserTracingIntegration = new BrowserTracing({
62-
// eslint-disable-next-line deprecation/deprecation
63-
tracingOrigins: [...defaultRequestInstrumentationOptions.tracingOrigins, /^(api\/)/],
64-
routingInstrumentation: nextRouterInstrumentation,
65-
});
48+
function addClientIntegrations(options: NextjsOptions): void {
49+
let integrations = options.integrations || [];
6650

67-
return addOrUpdateIntegration(defaultBrowserTracingIntegration, userIntegrations, {
68-
'options.routingInstrumentation': nextRouterInstrumentation,
69-
});
51+
// This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", in which case everything inside
52+
// will get treeshaken away
53+
if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
54+
if (hasTracingEnabled(options)) {
55+
const defaultBrowserTracingIntegration = new BrowserTracing({
56+
// eslint-disable-next-line deprecation/deprecation
57+
tracingOrigins: [...defaultRequestInstrumentationOptions.tracingOrigins, /^(api\/)/],
58+
routingInstrumentation: nextRouterInstrumentation,
59+
});
60+
61+
integrations = addOrUpdateIntegration(defaultBrowserTracingIntegration, integrations, {
62+
'options.routingInstrumentation': nextRouterInstrumentation,
63+
});
64+
}
65+
}
66+
67+
options.integrations = integrations;
7068
}

packages/nextjs/test/index.client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('Client init()', () => {
6363
},
6464
},
6565
environment: 'test',
66-
integrations: undefined,
66+
integrations: [],
6767
}),
6868
);
6969
});

0 commit comments

Comments
 (0)