-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(react): Add react-router-v6 integration. #5042
Conversation
size-limit report 📦
|
packages/react/src/reactrouterv6.tsx
Outdated
instrumentationOptions.useLocation = useLocation; | ||
instrumentationOptions.useNavigationType = useNavigationType; | ||
instrumentationOptions.matchRoutes = matchRoutes; | ||
instrumentationOptions.createRoutesFromChildren = createRoutesFromChildren; | ||
|
||
instrumentationOptions.customStartTransaction = customStartTransaction; | ||
instrumentationOptions.startTransactionOnLocationChange = startTransactionOnLocationChange; | ||
instrumentationOptions.startTransactionOnPageLoad = startTransactionOnPageLoad; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's lift these up into individual variables instead of being under the instrumentationOptions
object. This way we save on bundle size because otherwise object keys like customStartTransaction
or startTransactionOnLocationChange
cannot be minified.
instrumentationOptions.useLocation = useLocation; | |
instrumentationOptions.useNavigationType = useNavigationType; | |
instrumentationOptions.matchRoutes = matchRoutes; | |
instrumentationOptions.createRoutesFromChildren = createRoutesFromChildren; | |
instrumentationOptions.customStartTransaction = customStartTransaction; | |
instrumentationOptions.startTransactionOnLocationChange = startTransactionOnLocationChange; | |
instrumentationOptions.startTransactionOnPageLoad = startTransactionOnPageLoad; | |
useLocation = useLocation; | |
useNavigationType = useNavigationType; | |
matchRoutes = matchRoutes; | |
createRoutesFromChildren = createRoutesFromChildren; | |
customStartTransaction = customStartTransaction; | |
startTransactionOnLocationChange = startTransactionOnLocationChange; | |
startTransactionOnPageLoad = startTransactionOnPageLoad; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Can we add another test case around parameterized paths? Specifically with multi-parameter paths like orgs/:orgid/teams/:teamid
packages/react/src/reactrouterv6.tsx
Outdated
'routing.instrumentation': 'react-router-v6', | ||
}; | ||
|
||
export function withSentryV6<P extends Record<string, any>, R extends React.FC<P>>(Routes: R): R { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call this withSentryReactRouterV6Routing
. It's way longer, but it makes it very clear what is happening to users (+ will all get minified in the end anyway).
startTransactionOnPageLoad = true, | ||
startTransactionOnLocationChange = true, | ||
): void => { | ||
_useEffect = useEffect; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we start the transaction here and just update the transaction name in the useeffect call?
Also, is there a way we can listen directly onto history
instead of using useEffect
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to start pageload transaction on init 👍
Tried to find a simple solution to access history
but it doesn't look possible without risking reliability (as they're encouraging to use useNavigate
and useLocation
hooks in v6, so even if we try to use global history, they may conflict?). Combining them with useEffect
seems to be the most reliable, but can dig deeper if you like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - no worries, let's keep using the hooks then!
packages/react/src/reactrouterv6.tsx
Outdated
const transactionName = getTransactionName(routes, location, _matchRoutes); | ||
|
||
activeTransaction = _customStartTransaction({ | ||
name: transactionName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const transactionName = getTransactionName(routes, location, _matchRoutes); | |
activeTransaction = _customStartTransaction({ | |
name: transactionName, | |
activeTransaction = _customStartTransaction({ | |
name: getTransactionName(routes, location, _matchRoutes), |
packages/react/src/reactrouterv6.tsx
Outdated
!_matchRoutes || | ||
!_customStartTransaction | ||
) { | ||
// Log warning? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we should log something here
Co-authored-by: Abhijeet Prasad <[email protected]>
@@ -0,0 +1,177 @@ | |||
import { Transaction, TransactionContext } from '@sentry/types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make sure we attribute to whom this implementation was inspired/based on?
We will also need a docs PR for this! |
Tracing integration for [`[email protected]`](https://reactrouter.com/docs/en/v6) This implementation will provide a HoC that wraps [`<Routes>`](https://reactrouter.com/docs/en/v6/api#routes-and-route) which replaced `<Switch>` from `[email protected]`.
Is there a way to use this integration with |
Tracing integration for
[email protected]
This implementation will provide a HoC that wraps
<Routes>
which replaced<Switch>
from[email protected]
.This approach is similar to @wontondon's solution here.
Usage example:
Resolves: #4118