sentry-javascript: [React Router] Transaction unexpectedly ended early, cancelling spans from componentDidMount()
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which package are you using?
SDK Version
7.17.3 - but tested on 7.23.0 with same result
Framework Version
17.0.2 (react-router-dom: 6.4.3)
Link to Sentry event
Steps to Reproduce
- Examine our project’s SDK configuration index.js#L60-65 and index.js#L104
0.1 Examine code that initiates span that gets cut short before it finishes: Products.js#L39 - called from
componentDidMount() - Go to https://application-monitoring-react-dot-sales-engineering-sf.appspot.com/products
- Open devtools
- (optional) set breakpoint in idletransaction.tx - will eventually point you to reactrouterv6.tsx: handleNavigation() and _useEffect()
- Reload page
- Inspect console log (Debug level)
- Get transaction ID from Network tab and plug into search in /products transaction of this project
- Internal ticket: https://getsentry.atlassian.net/browse/FEEDBACK-1679
Expected Result
Transaction runs its course and does not finish prematurely before http.client span (GET https://…/products) is complete.
Actual Result
- Logs show “[Tracing] cancelling span since transaction ended early”
- In Sentry UI the last
http.clientspan (GET https://…/products) of the transaction is cut short even though corresponding backend transaction is ~ 2 seconds.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 18 (8 by maintainers)
Great! Opened a PR now. @timfish, @lforst - Could you take a look please?
I’ll take a look at this today!
Verified fix in our app 👍
@timfish
thank you for pointing this out Tim, we should use Volta or document it like you suggested.
@onurtemizkan Please let me know if there’s is anything I can help with investigating this.
When the the page is first loaded, in
reactrouterv6.tsx,SentryRoutes+useEffectcallsupdatePageloadTransactionand laterhandleNavigation.https://github.com/getsentry/sentry-javascript/blob/2fa11eb54f13b305dbee35687539748614583d6e/packages/react/src/reactrouterv6.tsx#L189-L201
The problem is that it calls
handleNavigationwithisBaseLocation == trueand that causes the transaction to be finished.This logic doesn’t seem correct to me but it’s been there since v7.0
https://github.com/getsentry/sentry-javascript/blob/2fa11eb54f13b305dbee35687539748614583d6e/packages/react/src/reactrouterv6.tsx#L130-L143
@onurtemizkan have you got any idea?