Skip to content

Commit f47d11f

Browse files
authored
feat(browser): Deprecate BrowserTracing integration (#10493)
There is a proper replacement for all of them now. Depends on: * #10491 * #10489 * #10488
1 parent 1a4b6e6 commit f47d11f

26 files changed

+190
-23
lines changed

MIGRATION.md

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,122 @@ npx @sentry/migr8@latest
1010
This will let you select which updates to run, and automatically update your code. Make sure to still review all code
1111
changes!
1212

13+
## Depreacted `BrowserTracing` integration
14+
15+
The `BrowserTracing` integration, together with the custom routing instrumentations passed to it, are deprecated in v8.
16+
Instead, you should use `Sentry.browserTracingIntegration()`.
17+
18+
Package-specific browser tracing integrations are available directly. In most cases, there is a single integration
19+
provided for each package, which will make sure to set up performance tracing correctly for the given SDK. For react, we
20+
provide multiple integrations to cover different router integrations:
21+
22+
### `@sentry/browser`, `@sentry/svelte`, `@sentry/gatsby`
23+
24+
```js
25+
import * as Sentry from '@sentry/browser';
26+
27+
Sentry.init({
28+
integrations: [Sentry.browserTracingIntegration()],
29+
});
30+
```
31+
32+
### `@sentry/react`
33+
34+
```js
35+
import * as Sentry from '@sentry/react';
36+
37+
Sentry.init({
38+
integrations: [
39+
// No react router
40+
Sentry.browserTracingIntegration(),
41+
// OR, if you are using react router, instead use one of the following:
42+
Sentry.reactRouterV6BrowserTracingIntegration({
43+
useEffect,
44+
useLocation,
45+
useNavigationType,
46+
createRoutesFromChildren,
47+
matchRoutes,
48+
stripBasename,
49+
}),
50+
Sentry.reactRouterV5BrowserTracingIntegration({
51+
history,
52+
}),
53+
Sentry.reactRouterV4BrowserTracingIntegration({
54+
history,
55+
}),
56+
Sentry.reactRouterV3BrowserTracingIntegration({
57+
history,
58+
routes,
59+
match,
60+
}),
61+
],
62+
});
63+
```
64+
65+
### `@sentry/vue`
66+
67+
```js
68+
import * as Sentry from '@sentry/vue';
69+
70+
Sentry.init({
71+
integrations: [
72+
Sentry.browserTracingIntegration({
73+
// pass router in, if applicable
74+
router,
75+
}),
76+
],
77+
});
78+
```
79+
80+
### `@sentry/angular` & `@sentry/angular-ivy`
81+
82+
```js
83+
import * as Sentry from '@sentry/angular';
84+
85+
Sentry.init({
86+
integrations: [Sentry.browserTracingIntegration()],
87+
});
88+
89+
// You still need to add the Trace Service like before!
90+
```
91+
92+
### `@sentry/remix`
93+
94+
```js
95+
import * as Sentry from '@sentry/remix';
96+
97+
Sentry.init({
98+
integrations: [
99+
Sentry.browserTracingIntegration({
100+
useEffect,
101+
useLocation,
102+
useMatches,
103+
}),
104+
],
105+
});
106+
```
107+
108+
### `@sentry/nextjs`, `@sentry/astro`, `@sentry/sveltekit`
109+
110+
Browser tracing is automatically set up for you in these packages. If you need to customize the options, you can do it
111+
like this:
112+
113+
```js
114+
import * as Sentry from '@sentry/nextjs';
115+
116+
Sentry.init({
117+
integrations: [
118+
Sentry.browserTracingIntegration({
119+
// add custom options here
120+
}),
121+
],
122+
});
123+
```
124+
125+
### `@sentry/ember`
126+
127+
Browser tracing is automatically set up for you. You can configure it as before through configuration.
128+
13129
## Deprecated `transactionContext` passed to `tracesSampler`
14130

15131
Instead of an `transactionContext` being passed to the `tracesSampler` callback, the callback will directly receive
@@ -43,6 +159,7 @@ The following list shows how integrations should be migrated:
43159

44160
| Old | New | Packages |
45161
| ---------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------- |
162+
| `new BrowserTracing()` | `browserTracingIntegration()` | `@sentry/browser` |
46163
| `new InboundFilters()` | `inboundFiltersIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
47164
| `new FunctionToString()` | `functionToStringIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
48165
| `new LinkedErrors()` | `linkedErrorsIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
@@ -75,8 +192,8 @@ The following list shows how integrations should be migrated:
75192
| `new OnUncaughtException()` | `onUncaughtExceptionIntegration()` | `@sentry/node` |
76193
| `new OnUnhandledRejection()` | `onUnhandledRejectionIntegration()` | `@sentry/node` |
77194
| `new LocalVariables()` | `localVariablesIntegration()` | `@sentry/node` |
78-
| `new Spotlight()` | `spotlightIntergation()` | `@sentry/node` |
79-
| `new Anr()` | `anrIntergation()` | `@sentry/node` |
195+
| `new Spotlight()` | `spotlightIntegration()` | `@sentry/node` |
196+
| `new Anr()` | `anrIntegration()` | `@sentry/node` |
80197
| `new Hapi()` | `hapiIntegration()` | `@sentry/node` |
81198
| `new Undici()` | `nativeNodeFetchIntegration()` | `@sentry/node` |
82199
| `new Http()` | `httpIntegration()` | `@sentry/node` |

packages/astro/src/client/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BrowserOptions } from '@sentry/browser';
22
import {
3-
BrowserTracing,
3+
browserTracingIntegration,
44
getDefaultIntegrations as getBrowserDefaultIntegrations,
55
init as initBrowserSdk,
66
setTag,
@@ -34,7 +34,7 @@ function getDefaultIntegrations(options: BrowserOptions): Integration[] | undefi
3434
// in which case everything inside will get treeshaken away
3535
if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
3636
if (hasTracingEnabled(options)) {
37-
return [...getBrowserDefaultIntegrations(options), new BrowserTracing()];
37+
return [...getBrowserDefaultIntegrations(options), browserTracingIntegration()];
3838
}
3939
}
4040

packages/astro/test/client/sdk.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ describe('Sentry client SDK', () => {
104104
it('Overrides the automatically default BrowserTracing instance with a a user-provided BrowserTracing instance', () => {
105105
init({
106106
dsn: 'https://[email protected]/1337',
107+
// eslint-disable-next-line deprecation/deprecation
107108
integrations: [new BrowserTracing({ finalTimeout: 10, startTransactionOnLocationChange: false })],
108109
enableTracing: true,
109110
});
110111

111112
const integrationsToInit = browserInit.mock.calls[0][0]?.defaultIntegrations;
112113

114+
// eslint-disable-next-line deprecation/deprecation
113115
const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing') as BrowserTracing;
114116
const options = browserTracing.options;
115117

@@ -120,7 +122,7 @@ describe('Sentry client SDK', () => {
120122
expect(options.finalTimeout).toEqual(10);
121123
});
122124

123-
it('Overrides the automatically default BrowserTracing instance with a a user-provided browserTracingIntergation instance', () => {
125+
it('Overrides the automatically default BrowserTracing instance with a a user-provided browserTracingIntegration instance', () => {
124126
init({
125127
dsn: 'https://[email protected]/1337',
126128
integrations: [

packages/browser/src/helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ export function bundleBrowserTracingIntegration(
201201
options: Parameters<typeof browserTracingIntegration>[0] = {},
202202
): Integration {
203203
// Migrate some options from the old integration to the new one
204+
// eslint-disable-next-line deprecation/deprecation
204205
const opts: ConstructorParameters<typeof BrowserTracing>[0] = options;
205206

206207
if (typeof options.markBackgroundSpan === 'boolean') {
@@ -215,5 +216,6 @@ export function bundleBrowserTracingIntegration(
215216
opts.startTransactionOnLocationChange = options.instrumentNavigation;
216217
}
217218

219+
// eslint-disable-next-line deprecation/deprecation
218220
return new BrowserTracing(opts);
219221
}

packages/browser/src/index.bundle.feedback.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import * as Sentry from './index.bundle.base';
1414
// eslint-disable-next-line deprecation/deprecation
1515
Sentry.Integrations.Replay = Replay;
1616

17+
// eslint-disable-next-line deprecation/deprecation
1718
Sentry.Integrations.BrowserTracing = BrowserTracing;
1819

1920
export * from './index.bundle.base';
2021
export {
22+
// eslint-disable-next-line deprecation/deprecation
2123
BrowserTracing,
2224
browserTracingIntegration,
2325
addTracingExtensions,

packages/browser/src/index.bundle.replay.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import * as Sentry from './index.bundle.base';
1414
// eslint-disable-next-line deprecation/deprecation
1515
Sentry.Integrations.Replay = Replay;
1616

17+
// eslint-disable-next-line deprecation/deprecation
1718
Sentry.Integrations.BrowserTracing = BrowserTracing;
1819

1920
export * from './index.bundle.base';
2021
export {
22+
// eslint-disable-next-line deprecation/deprecation
2123
BrowserTracing,
2224
browserTracingIntegration,
2325
addTracingExtensions,

packages/browser/src/index.bundle.tracing.replay.feedback.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as Sentry from './index.bundle.base';
1111
// eslint-disable-next-line deprecation/deprecation
1212
Sentry.Integrations.Replay = Replay;
1313

14+
// eslint-disable-next-line deprecation/deprecation
1415
Sentry.Integrations.BrowserTracing = BrowserTracing;
1516

1617
// We are patching the global object with our hub extension methods
@@ -23,6 +24,7 @@ export {
2324
Replay,
2425
feedbackIntegration,
2526
replayIntegration,
27+
// eslint-disable-next-line deprecation/deprecation
2628
BrowserTracing,
2729
browserTracingIntegration,
2830
Span,

packages/browser/src/index.bundle.tracing.replay.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as Sentry from './index.bundle.base';
1111
// eslint-disable-next-line deprecation/deprecation
1212
Sentry.Integrations.Replay = Replay;
1313

14+
// eslint-disable-next-line deprecation/deprecation
1415
Sentry.Integrations.BrowserTracing = BrowserTracing;
1516

1617
// We are patching the global object with our hub extension methods
@@ -23,6 +24,7 @@ export {
2324
Replay,
2425
replayIntegration,
2526
feedbackIntegration,
27+
// eslint-disable-next-line deprecation/deprecation
2628
BrowserTracing,
2729
browserTracingIntegration,
2830
Span,

packages/browser/src/index.bundle.tracing.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as Sentry from './index.bundle.base';
1111
// eslint-disable-next-line deprecation/deprecation
1212
Sentry.Integrations.Replay = Replay;
1313

14+
// eslint-disable-next-line deprecation/deprecation
1415
Sentry.Integrations.BrowserTracing = BrowserTracing;
1516

1617
// We are patching the global object with our hub extension methods
@@ -23,6 +24,7 @@ export {
2324
Replay,
2425
feedbackIntegration,
2526
replayIntegration,
27+
// eslint-disable-next-line deprecation/deprecation
2628
BrowserTracing,
2729
browserTracingIntegration,
2830
Span,

packages/browser/src/index.bundle.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import * as Sentry from './index.bundle.base';
1515
// eslint-disable-next-line deprecation/deprecation
1616
Sentry.Integrations.Replay = Replay;
1717

18+
// eslint-disable-next-line deprecation/deprecation
1819
Sentry.Integrations.BrowserTracing = BrowserTracing;
1920

2021
export * from './index.bundle.base';
2122
export {
23+
// eslint-disable-next-line deprecation/deprecation
2224
BrowserTracing,
2325
addTracingExtensions,
2426
// eslint-disable-next-line deprecation/deprecation

packages/browser/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export {
5454
} from '@sentry-internal/feedback';
5555

5656
export {
57+
// eslint-disable-next-line deprecation/deprecation
5758
BrowserTracing,
5859
defaultRequestInstrumentationOptions,
5960
instrumentOutgoingRequests,

packages/deno/src/integrations/globalhandlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const globalHandlersIntegration = defineIntegration(_globalHandlersIntegr
4848

4949
/**
5050
* Global handlers.
51-
* @deprecated Use `globalHandlersIntergation()` instead.
51+
* @deprecated Use `globalHandlersIntegration()` instead.
5252
*/
5353
// eslint-disable-next-line deprecation/deprecation
5454
export const GlobalHandlers = convertIntegrationFnToClass(

packages/ember/addon/instance-initializers/sentry-performance.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ export function _instrumentEmberRouter(
109109
return;
110110
}
111111

112-
if (url && browserTracingOptions.startTransactionOnPageLoad !== false) {
112+
if (
113+
url &&
114+
browserTracingOptions.startTransactionOnPageLoad !== false &&
115+
browserTracingOptions.instrumentPageLoad !== false
116+
) {
113117
const routeInfo = routerService.recognize(url);
114118
Sentry.startBrowserTracingPageLoadSpan(client, {
115119
name: `route:${routeInfo.name}`,
@@ -132,7 +136,10 @@ export function _instrumentEmberRouter(
132136
getBackburner().off('end', finishActiveTransaction);
133137
};
134138

135-
if (browserTracingOptions.startTransactionOnLocationChange === false) {
139+
if (
140+
browserTracingOptions.startTransactionOnLocationChange === false &&
141+
browserTracingOptions.instrumentNavigation === false
142+
) {
136143
return;
137144
}
138145

packages/ember/addon/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import type { BrowserOptions, BrowserTracing } from '@sentry/browser';
1+
import type { BrowserOptions, BrowserTracing, browserTracingIntegration } from '@sentry/browser';
22
import type { Transaction, TransactionContext } from '@sentry/types';
33

4-
type BrowserTracingOptions = ConstructorParameters<typeof BrowserTracing>[0];
4+
type BrowserTracingOptions = Parameters<typeof browserTracingIntegration>[0] &
5+
// eslint-disable-next-line deprecation/deprecation
6+
ConstructorParameters<typeof BrowserTracing>[0];
57

68
export type EmberSentryConfig = {
79
sentry: BrowserOptions & { browserTracingOptions?: BrowserTracingOptions };

packages/gatsby/src/utils/integrations.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { hasTracingEnabled } from '@sentry/core';
2-
import { BrowserTracing } from '@sentry/react';
2+
import { browserTracingIntegration } from '@sentry/react';
33
import type { Integration } from '@sentry/types';
44

55
import type { GatsbyOptions } from './types';
@@ -31,8 +31,8 @@ export function getIntegrationsFromOptions(options: GatsbyOptions): UserIntegrat
3131
* @param isTracingEnabled Whether the user has enabled tracing.
3232
*/
3333
function getIntegrationsFromArray(userIntegrations: Integration[], isTracingEnabled: boolean): Integration[] {
34-
if (isTracingEnabled && !userIntegrations.some(integration => integration.name === BrowserTracing.name)) {
35-
userIntegrations.push(new BrowserTracing());
34+
if (isTracingEnabled && !userIntegrations.some(integration => integration.name === 'BrowserTracing')) {
35+
userIntegrations.push(browserTracingIntegration());
3636
}
3737
return userIntegrations;
3838
}

packages/gatsby/test/gatsby-browser.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable @typescript-eslint/no-explicit-any */
33

44
import { onClientEntry } from '../gatsby-browser';
5-
import { BrowserTracing } from '../src/index';
5+
import { browserTracingIntegration } from '../src/index';
66

77
(global as any).__SENTRY_RELEASE__ = '683f3a6ab819d47d23abfca9a914c81f0524d35b';
88
(global as any).__SENTRY_DSN__ = 'https://[email protected]/0';
@@ -141,7 +141,7 @@ describe('onClientEntry', () => {
141141
});
142142

143143
it('only defines a single `BrowserTracing` integration', () => {
144-
const integrations = [new BrowserTracing()];
144+
const integrations = [browserTracingIntegration()];
145145
onClientEntry(undefined, { tracesSampleRate: 0.5, integrations });
146146

147147
expect(sentryInit).toHaveBeenLastCalledWith(

0 commit comments

Comments
 (0)