Skip to content

Commit 705f919

Browse files
authored
fix(v7): Ensure next & sveltekit correctly handle browserTracingIntegration (#11647)
Fixes #11627
1 parent b5bdd4b commit 705f919

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

Diff for: packages/nextjs/src/client/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import type { EventProcessor, Integration } from '@sentry/types';
1010

1111
import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor';
1212
import { getVercelEnv } from '../common/getVercelEnv';
13-
import { browserTracingIntegration } from './browserTracingIntegration';
14-
import { BrowserTracing } from './browserTracingIntegration';
13+
import { BrowserTracing, browserTracingIntegration } from './browserTracingIntegration';
1514
import { rewriteFramesIntegration } from './rewriteFramesIntegration';
1615
import { applyTunnelRouteOption } from './tunnelRoute';
1716

@@ -107,7 +106,7 @@ function maybeUpdateBrowserTracingIntegration(integrations: Integration[]): Inte
107106
if (isNewBrowserTracingIntegration(browserTracing)) {
108107
const { options } = browserTracing;
109108
// eslint-disable-next-line deprecation/deprecation
110-
integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options);
109+
integrations[integrations.indexOf(browserTracing)] = browserTracingIntegration(options);
111110
}
112111

113112
// If BrowserTracing was added, but it is not our forked version,

Diff for: packages/nextjs/test/clientSdk.test.ts

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BaseClient } from '@sentry/core';
1+
import { BaseClient, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan, spanToJSON } from '@sentry/core';
22
import * as SentryReact from '@sentry/react';
33
import type { BrowserClient } from '@sentry/react';
44
import { browserTracingIntegration } from '@sentry/react';
@@ -149,16 +149,20 @@ describe('Client init()', () => {
149149

150150
const client = getClient<BrowserClient>()!;
151151
// eslint-disable-next-line deprecation/deprecation
152-
const integration = client.getIntegrationByName<BrowserTracing>('BrowserTracing');
152+
const integration = client.getIntegrationByName<ReturnType<typeof browserTracingIntegration>>('BrowserTracing');
153153

154154
expect(integration).toBeDefined();
155-
expect(integration?.options).toEqual(
156-
expect.objectContaining({
157-
// eslint-disable-next-line deprecation/deprecation
158-
routingInstrumentation: nextRouterInstrumentation,
159-
// This proves it's still the user's copy
160-
finalTimeout: 10,
161-
}),
155+
156+
// It is a "new" browser tracing integration
157+
expect(typeof integration?.afterAllSetup).toBe('function');
158+
159+
// This shows that the user-configured options are still here
160+
expect(integration?.options?.finalTimeout).toEqual(10);
161+
162+
// it is the svelte kit variety
163+
expect(getActiveSpan()).toBeDefined();
164+
expect(spanToJSON(getActiveSpan()!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]).toEqual(
165+
'auto.pageload.nextjs.app_router_instrumentation',
162166
);
163167
});
164168

@@ -176,6 +180,11 @@ describe('Client init()', () => {
176180
const browserTracingIntegration = client.getIntegrationByName<BrowserTracing>('BrowserTracing');
177181

178182
expect(browserTracingIntegration).toBeDefined();
183+
184+
// It is a "old" browser tracing integration
185+
// @ts-expect-error this does not exist
186+
expect(typeof browserTracingIntegration!['afterAllSetup']).toBe('undefined');
187+
179188
expect(browserTracingIntegration?.options).toEqual(
180189
expect.objectContaining({
181190
// eslint-disable-next-line deprecation/deprecation

Diff for: packages/sveltekit/src/client/sdk.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function maybeUpdateBrowserTracingIntegration(integrations: Integration[]): Inte
8282
if (isNewBrowserTracingIntegration(browserTracing)) {
8383
const { options } = browserTracing;
8484
// eslint-disable-next-line deprecation/deprecation
85-
integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options);
85+
integrations[integrations.indexOf(browserTracing)] = svelteKitBrowserTracingIntegration(options);
8686
}
8787

8888
// If BrowserTracing was added, but it is not our forked version,

Diff for: packages/sveltekit/test/client/sdk.test.ts

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getClient, getCurrentScope } from '@sentry/core';
1+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan, getClient, getCurrentScope, spanToJSON } from '@sentry/core';
22
import type { BrowserClient } from '@sentry/svelte';
33
import * as SentrySvelte from '@sentry/svelte';
44
import { SDK_VERSION, WINDOW, browserTracingIntegration } from '@sentry/svelte';
@@ -109,6 +109,9 @@ describe('Sentry client SDK', () => {
109109

110110
expect(browserTracing).toBeDefined();
111111

112+
// It is a "old" browser tracing integration
113+
expect(typeof browserTracing['afterAllSetup']).toBe('undefined');
114+
112115
// This shows that the user-configured options are still here
113116
expect(options.finalTimeout).toEqual(10);
114117

@@ -124,18 +127,25 @@ describe('Sentry client SDK', () => {
124127
enableTracing: true,
125128
});
126129

127-
// eslint-disable-next-line deprecation/deprecation
128-
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing') as BrowserTracing;
129-
const options = browserTracing.options;
130+
const browserTracing =
131+
getClient<BrowserClient>()?.getIntegrationByName<ReturnType<typeof browserTracingIntegration>>(
132+
'BrowserTracing',
133+
);
134+
const options = browserTracing?.options;
130135

131136
expect(browserTracing).toBeDefined();
132137

138+
// It is a "new" browser tracing integration
139+
expect(typeof browserTracing?.afterAllSetup).toBe('function');
140+
133141
// This shows that the user-configured options are still here
134-
expect(options.finalTimeout).toEqual(10);
142+
expect(options?.finalTimeout).toEqual(10);
135143

136-
// But we force the routing instrumentation to be ours
137-
// eslint-disable-next-line deprecation/deprecation
138-
expect(options.routingInstrumentation).toEqual(svelteKitRoutingInstrumentation);
144+
// it is the svelte kit variety
145+
expect(getActiveSpan()).toBeDefined();
146+
expect(spanToJSON(getActiveSpan()!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]).toEqual(
147+
'auto.pageload.sveltekit',
148+
);
139149
});
140150
});
141151
});

0 commit comments

Comments
 (0)