Skip to content

Commit 9493580

Browse files
authored
feat(v8/react): Delete react router exports (#10532)
ref #10100
1 parent 5022f2f commit 9493580

File tree

9 files changed

+14
-1947
lines changed

9 files changed

+14
-1947
lines changed

dev-packages/e2e-tests/test-applications/standard-frontend-react-tracing-import/src/index.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as Sentry from '@sentry/react';
2-
import { BrowserTracing } from '@sentry/tracing';
32
import React from 'react';
43
import ReactDOM from 'react-dom/client';
54
import {
@@ -18,14 +17,12 @@ Sentry.init({
1817
environment: 'qa', // dynamic sampling bias to keep transactions
1918
dsn: process.env.REACT_APP_E2E_TEST_DSN,
2019
integrations: [
21-
new BrowserTracing({
22-
routingInstrumentation: Sentry.reactRouterV6Instrumentation(
23-
React.useEffect,
24-
useLocation,
25-
useNavigationType,
26-
createRoutesFromChildren,
27-
matchRoutes,
28-
),
20+
Sentry.reactRouterV6BrowserTracingIntegration({
21+
useEffect: React.useEffect,
22+
useLocation,
23+
useNavigationType,
24+
createRoutesFromChildren,
25+
matchRoutes,
2926
}),
3027
],
3128
// We recommend adjusting this value in production, or using tracesSampler

packages/react/src/index.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,13 @@ export { Profiler, withProfiler, useProfiler } from './profiler';
55
export type { ErrorBoundaryProps, FallbackRender } from './errorboundary';
66
export { ErrorBoundary, withErrorBoundary } from './errorboundary';
77
export { createReduxEnhancer } from './redux';
8+
export { reactRouterV3BrowserTracingIntegration } from './reactrouterv3';
89
export {
9-
// eslint-disable-next-line deprecation/deprecation
10-
reactRouterV3Instrumentation,
11-
reactRouterV3BrowserTracingIntegration,
12-
} from './reactrouterv3';
13-
export {
14-
// eslint-disable-next-line deprecation/deprecation
15-
reactRouterV4Instrumentation,
16-
// eslint-disable-next-line deprecation/deprecation
17-
reactRouterV5Instrumentation,
1810
withSentryRouting,
1911
reactRouterV4BrowserTracingIntegration,
2012
reactRouterV5BrowserTracingIntegration,
2113
} from './reactrouter';
2214
export {
23-
// eslint-disable-next-line deprecation/deprecation
24-
reactRouterV6Instrumentation,
2515
reactRouterV6BrowserTracingIntegration,
2616
withSentryReactRouterV6Routing,
2717
wrapUseRoutes,

packages/react/src/reactrouter.tsx

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ export function reactRouterV4BrowserTracingIntegration(
7575
return undefined;
7676
};
7777

78-
// eslint-disable-next-line deprecation/deprecation
79-
const instrumentation = reactRouterV4Instrumentation(history, routes, matchPath);
78+
const instrumentation = createReactRouterInstrumentation(history, 'reactrouter_v4', routes, matchPath);
8079

8180
// Now instrument page load & navigation with correct settings
8281
instrumentation(startPageloadCallback, instrumentPageLoad, false);
@@ -115,8 +114,7 @@ export function reactRouterV5BrowserTracingIntegration(
115114
return undefined;
116115
};
117116

118-
// eslint-disable-next-line deprecation/deprecation
119-
const instrumentation = reactRouterV5Instrumentation(history, routes, matchPath);
117+
const instrumentation = createReactRouterInstrumentation(history, 'reactrouter_v5', routes, matchPath);
120118

121119
// Now instrument page load & navigation with correct settings
122120
instrumentation(startPageloadCallback, options.instrumentPageLoad, false);
@@ -125,28 +123,6 @@ export function reactRouterV5BrowserTracingIntegration(
125123
};
126124
}
127125

128-
/**
129-
* @deprecated Use `browserTracingReactRouterV4()` instead.
130-
*/
131-
export function reactRouterV4Instrumentation(
132-
history: RouterHistory,
133-
routes?: RouteConfig[],
134-
matchPath?: MatchPath,
135-
): ReactRouterInstrumentation {
136-
return createReactRouterInstrumentation(history, 'reactrouter_v4', routes, matchPath);
137-
}
138-
139-
/**
140-
* @deprecated Use `browserTracingReactRouterV5()` instead.
141-
*/
142-
export function reactRouterV5Instrumentation(
143-
history: RouterHistory,
144-
routes?: RouteConfig[],
145-
matchPath?: MatchPath,
146-
): ReactRouterInstrumentation {
147-
return createReactRouterInstrumentation(history, 'reactrouter_v5', routes, matchPath);
148-
}
149-
150126
function createReactRouterInstrumentation(
151127
history: RouterHistory,
152128
instrumentationName: string,

packages/react/src/reactrouterv3.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export function reactRouterV3BrowserTracingIntegration(
7474
return undefined;
7575
};
7676

77-
// eslint-disable-next-line deprecation/deprecation
7877
const instrumentation = reactRouterV3Instrumentation(history, routes, match);
7978

8079
// Now instrument page load & navigation with correct settings
@@ -91,14 +90,8 @@ export function reactRouterV3BrowserTracingIntegration(
9190
* @param history object from the `history` library
9291
* @param routes a list of all routes, should be
9392
* @param match `Router.match` utility
94-
*
95-
* @deprecated Use `reactRouterV3BrowserTracingIntegration()` instead
9693
*/
97-
export function reactRouterV3Instrumentation(
98-
history: HistoryV3,
99-
routes: Route[],
100-
match: Match,
101-
): ReactRouterInstrumentation {
94+
function reactRouterV3Instrumentation(history: HistoryV3, routes: Route[], match: Match): ReactRouterInstrumentation {
10295
return (
10396
startTransaction: (context: TransactionContext) => Transaction | undefined,
10497
startTransactionOnPageLoad: boolean = true,

packages/react/test/reactrouterv3.test.tsx

Lines changed: 0 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { IndexRoute, Route, Router, createMemoryHistory, createRoutes, match } f
1313

1414
import type { Match, Route as RouteType } from '../src/reactrouterv3';
1515
import { reactRouterV3BrowserTracingIntegration } from '../src/reactrouterv3';
16-
import { reactRouterV3Instrumentation } from '../src/reactrouterv3';
1716

1817
// Have to manually set types because we are using package-alias
1918
declare module 'react-router-3' {
@@ -26,219 +25,6 @@ declare module 'react-router-3' {
2625
export const createRoutes: (routes: any) => RouteType[];
2726
}
2827

29-
function createMockStartTransaction(opts: { finish?: jest.FunctionLike; setMetadata?: jest.FunctionLike } = {}) {
30-
const { finish = jest.fn(), setMetadata = jest.fn() } = opts;
31-
return jest.fn().mockReturnValue({
32-
end: finish,
33-
setMetadata,
34-
});
35-
}
36-
37-
describe('reactRouterV3Instrumentation', () => {
38-
const routes = (
39-
<Route path="/" component={({ children }: { children: JSX.Element }) => <div>{children}</div>}>
40-
<IndexRoute component={() => <div>Home</div>} />
41-
<Route path="about" component={() => <div>About</div>} />
42-
<Route path="features" component={() => <div>Features</div>} />
43-
<Route
44-
path="users/:userid"
45-
component={({ params }: { params: Record<string, string> }) => <div>{params.userid}</div>}
46-
/>
47-
<Route path="organizations/">
48-
<Route path=":orgid" component={() => <div>OrgId</div>} />
49-
<Route path=":orgid/v1/:teamid" component={() => <div>Team</div>} />
50-
</Route>
51-
</Route>
52-
);
53-
const history = createMemoryHistory();
54-
55-
const instrumentationRoutes = createRoutes(routes);
56-
// eslint-disable-next-line deprecation/deprecation
57-
const instrumentation = reactRouterV3Instrumentation(history, instrumentationRoutes, match);
58-
59-
it('starts a pageload transaction when instrumentation is started', () => {
60-
const mockStartTransaction = createMockStartTransaction();
61-
instrumentation(mockStartTransaction);
62-
expect(mockStartTransaction).toHaveBeenCalledTimes(1);
63-
expect(mockStartTransaction).toHaveBeenLastCalledWith({
64-
name: '/',
65-
attributes: {
66-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
67-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react.reactrouter_v3',
68-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
69-
},
70-
});
71-
});
72-
73-
it('does not start pageload transaction if option is false', () => {
74-
const mockStartTransaction = createMockStartTransaction();
75-
instrumentation(mockStartTransaction, false);
76-
expect(mockStartTransaction).toHaveBeenCalledTimes(0);
77-
});
78-
79-
it('starts a navigation transaction', () => {
80-
const mockStartTransaction = createMockStartTransaction();
81-
instrumentation(mockStartTransaction);
82-
render(<Router history={history}>{routes}</Router>);
83-
84-
act(() => {
85-
history.push('/about');
86-
});
87-
expect(mockStartTransaction).toHaveBeenCalledTimes(2);
88-
expect(mockStartTransaction).toHaveBeenLastCalledWith({
89-
name: '/about',
90-
attributes: {
91-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
92-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.reactrouter_v3',
93-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
94-
},
95-
});
96-
97-
act(() => {
98-
history.push('/features');
99-
});
100-
expect(mockStartTransaction).toHaveBeenCalledTimes(3);
101-
expect(mockStartTransaction).toHaveBeenLastCalledWith({
102-
name: '/features',
103-
attributes: {
104-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
105-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.reactrouter_v3',
106-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
107-
},
108-
});
109-
});
110-
111-
it('does not start a transaction if option is false', () => {
112-
const mockStartTransaction = createMockStartTransaction();
113-
instrumentation(mockStartTransaction, true, false);
114-
render(<Router history={history}>{routes}</Router>);
115-
expect(mockStartTransaction).toHaveBeenCalledTimes(1);
116-
});
117-
118-
it('only starts a navigation transaction on push', () => {
119-
const mockStartTransaction = createMockStartTransaction();
120-
instrumentation(mockStartTransaction);
121-
render(<Router history={history}>{routes}</Router>);
122-
123-
act(() => {
124-
history.replace('hello');
125-
});
126-
expect(mockStartTransaction).toHaveBeenCalledTimes(1);
127-
});
128-
129-
it('finishes a transaction on navigation', () => {
130-
const mockFinish = jest.fn();
131-
const mockStartTransaction = createMockStartTransaction({ finish: mockFinish });
132-
instrumentation(mockStartTransaction);
133-
render(<Router history={history}>{routes}</Router>);
134-
expect(mockStartTransaction).toHaveBeenCalledTimes(1);
135-
136-
act(() => {
137-
history.push('/features');
138-
});
139-
expect(mockFinish).toHaveBeenCalledTimes(1);
140-
expect(mockStartTransaction).toHaveBeenCalledTimes(2);
141-
});
142-
143-
it('normalizes transaction names', () => {
144-
const mockStartTransaction = createMockStartTransaction();
145-
instrumentation(mockStartTransaction);
146-
const { container } = render(<Router history={history}>{routes}</Router>);
147-
148-
act(() => {
149-
history.push('/users/123');
150-
});
151-
expect(container.innerHTML).toContain('123');
152-
153-
expect(mockStartTransaction).toHaveBeenCalledTimes(2);
154-
expect(mockStartTransaction).toHaveBeenLastCalledWith({
155-
name: '/users/:userid',
156-
attributes: {
157-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
158-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.reactrouter_v3',
159-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
160-
},
161-
});
162-
});
163-
164-
it('normalizes nested transaction names', () => {
165-
const mockStartTransaction = createMockStartTransaction();
166-
instrumentation(mockStartTransaction);
167-
const { container } = render(<Router history={history}>{routes}</Router>);
168-
169-
act(() => {
170-
history.push('/organizations/1234/v1/758');
171-
});
172-
expect(container.innerHTML).toContain('Team');
173-
174-
expect(mockStartTransaction).toHaveBeenCalledTimes(2);
175-
expect(mockStartTransaction).toHaveBeenLastCalledWith({
176-
name: '/organizations/:orgid/v1/:teamid',
177-
attributes: {
178-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
179-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.reactrouter_v3',
180-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
181-
},
182-
});
183-
184-
act(() => {
185-
history.push('/organizations/543');
186-
});
187-
expect(container.innerHTML).toContain('OrgId');
188-
189-
expect(mockStartTransaction).toHaveBeenCalledTimes(3);
190-
expect(mockStartTransaction).toHaveBeenLastCalledWith({
191-
name: '/organizations/:orgid',
192-
attributes: {
193-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
194-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.reactrouter_v3',
195-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
196-
},
197-
});
198-
});
199-
200-
it('sets metadata to url if on an unknown route', () => {
201-
const mockStartTransaction = createMockStartTransaction();
202-
instrumentation(mockStartTransaction);
203-
render(<Router history={history}>{routes}</Router>);
204-
205-
act(() => {
206-
history.push('/organizations/1234/some/other/route');
207-
});
208-
209-
expect(mockStartTransaction).toHaveBeenCalledTimes(2);
210-
expect(mockStartTransaction).toHaveBeenLastCalledWith({
211-
name: '/organizations/1234/some/other/route',
212-
attributes: {
213-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
214-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.reactrouter_v3',
215-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
216-
},
217-
});
218-
});
219-
220-
it('sets metadata to url if no routes are provided', () => {
221-
const fakeRoutes = <div>hello</div>;
222-
const mockStartTransaction = createMockStartTransaction();
223-
// eslint-disable-next-line deprecation/deprecation
224-
const mockInstrumentation = reactRouterV3Instrumentation(history, createRoutes(fakeRoutes), match);
225-
mockInstrumentation(mockStartTransaction);
226-
// We render here with `routes` instead of `fakeRoutes` from above to validate the case
227-
// where users provided the instrumentation with a bad set of routes.
228-
render(<Router history={history}>{routes}</Router>);
229-
230-
expect(mockStartTransaction).toHaveBeenCalledTimes(1);
231-
expect(mockStartTransaction).toHaveBeenLastCalledWith({
232-
name: '/',
233-
attributes: {
234-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
235-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react.reactrouter_v3',
236-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
237-
},
238-
});
239-
});
240-
});
241-
24228
const mockStartBrowserTracingPageLoadSpan = jest.fn();
24329
const mockStartBrowserTracingNavigationSpan = jest.fn();
24430

0 commit comments

Comments
 (0)