Skip to content

Commit db28484

Browse files
committed
fix(nextjs|sveltekit): Ensure we can pass browserTracingIntegration
1 parent cfaa9be commit db28484

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

packages/nextjs/src/client/browserTracingIntegration.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
startBrowserTracingNavigationSpan,
66
startBrowserTracingPageLoadSpan,
77
} from '@sentry/react';
8-
import type { Integration, StartSpanOptions } from '@sentry/types';
8+
import type { StartSpanOptions } from '@sentry/types';
99
import { nextRouterInstrumentation } from '../index.client';
1010

1111
/**
@@ -42,7 +42,7 @@ export class BrowserTracing extends OriginalBrowserTracing {
4242
*/
4343
export function browserTracingIntegration(
4444
options?: Parameters<typeof originalBrowserTracingIntegration>[0],
45-
): Integration {
45+
): ReturnType<typeof originalBrowserTracingIntegration> {
4646
const browserTracingIntegrationInstance = originalBrowserTracingIntegration({
4747
// eslint-disable-next-line deprecation/deprecation
4848
tracingOrigins:
@@ -63,6 +63,10 @@ export function browserTracingIntegration(
6363

6464
return {
6565
...browserTracingIntegrationInstance,
66+
options: {
67+
...browserTracingIntegrationInstance.options,
68+
...options,
69+
},
6670
afterAllSetup(client) {
6771
const startPageloadCallback = (startSpanOptions: StartSpanOptions): void => {
6872
startBrowserTracingPageLoadSpan(client, startSpanOptions);

packages/nextjs/test/clientSdk.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('Client init()', () => {
143143
it('forces correct router instrumentation if user provides `browserTracingIntegration`', () => {
144144
init({
145145
dsn: TEST_DSN,
146-
integrations: [browserTracingIntegration({ finalTimeout: 10 })],
146+
integrations: [browserTracingIntegration({ finalTimeout: 10, instrumentNavigation: false })],
147147
enableTracing: true,
148148
});
149149

@@ -158,6 +158,8 @@ describe('Client init()', () => {
158158

159159
// This shows that the user-configured options are still here
160160
expect(integration?.options?.finalTimeout).toEqual(10);
161+
expect(integration?.options.instrumentNavigation).toBe(false);
162+
expect(integration?.options.instrumentPageLoad).toBe(true);
161163

162164
// it is the svelte kit variety
163165
expect(getActiveSpan()).toBeDefined();
@@ -187,10 +189,10 @@ describe('Client init()', () => {
187189

188190
expect(browserTracingIntegration?.options).toEqual(
189191
expect.objectContaining({
192+
startTransactionOnPageLoad: true,
193+
startTransactionOnLocationChange: false,
190194
// eslint-disable-next-line deprecation/deprecation
191195
routingInstrumentation: nextRouterInstrumentation,
192-
// This proves it's still the user's copy
193-
startTransactionOnLocationChange: false,
194196
}),
195197
);
196198
});

packages/sveltekit/src/client/browserTracingIntegration.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
startBrowserTracingPageLoadSpan,
1010
startInactiveSpan,
1111
} from '@sentry/svelte';
12-
import type { Client, Integration, Span } from '@sentry/types';
12+
import type { Client, Span } from '@sentry/types';
1313
import { svelteKitRoutingInstrumentation } from './router';
1414

1515
/**
@@ -36,7 +36,7 @@ export class BrowserTracing extends OriginalBrowserTracing {
3636
*/
3737
export function browserTracingIntegration(
3838
options: Parameters<typeof originalBrowserTracingIntegration>[0] = {},
39-
): Integration {
39+
): ReturnType<typeof originalBrowserTracingIntegration> {
4040
const integration = {
4141
...originalBrowserTracingIntegration({
4242
...options,
@@ -47,6 +47,10 @@ export function browserTracingIntegration(
4747

4848
return {
4949
...integration,
50+
options: {
51+
...integration.options,
52+
...options,
53+
},
5054
afterAllSetup: client => {
5155
integration.afterAllSetup(client);
5256

packages/sveltekit/test/client/sdk.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('Sentry client SDK', () => {
9999
init({
100100
dsn: 'https://[email protected]/1337',
101101
// eslint-disable-next-line deprecation/deprecation
102-
integrations: [new BrowserTracing({ finalTimeout: 10 })],
102+
integrations: [new BrowserTracing({ finalTimeout: 10, startTransactionOnLocationChange: false })],
103103
enableTracing: true,
104104
});
105105

@@ -118,12 +118,14 @@ describe('Sentry client SDK', () => {
118118
// But we force the routing instrumentation to be ours
119119
// eslint-disable-next-line deprecation/deprecation
120120
expect(options.routingInstrumentation).toEqual(svelteKitRoutingInstrumentation);
121+
expect(options.startTransactionOnPageLoad).toEqual(true);
122+
expect(options.startTransactionOnLocationChange).toEqual(false);
121123
});
122124

123125
it('Merges a user-provided browserTracingIntegration with the automatically added one', () => {
124126
init({
125127
dsn: 'https://[email protected]/1337',
126-
integrations: [browserTracingIntegration({ finalTimeout: 10 })],
128+
integrations: [browserTracingIntegration({ finalTimeout: 10, instrumentNavigation: false })],
127129
enableTracing: true,
128130
});
129131

@@ -140,6 +142,8 @@ describe('Sentry client SDK', () => {
140142

141143
// This shows that the user-configured options are still here
142144
expect(options?.finalTimeout).toEqual(10);
145+
expect(options?.instrumentPageLoad).toEqual(true);
146+
expect(options?.instrumentNavigation).toEqual(false);
143147

144148
// it is the svelte kit variety
145149
expect(getActiveSpan()).toBeDefined();

0 commit comments

Comments
 (0)