sentry-javascript: [React Router] Transaction unexpectedly ended early, cancelling spans from componentDidMount()

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/react

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

https://sentry.io/organizations/testorg-az/performance/application-monitoring-javascript:755fa61c341044a19a38b718efff2b35/?project=5808623&query=sdk.version%3A7.17.3&referrer=performance-transaction-summary&statsPeriod=30d&transaction=%2Fproducts&unselectedSeries=p100()

Steps to Reproduce

  1. 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()
  2. Go to https://application-monitoring-react-dot-sales-engineering-sf.appspot.com/products
  3. Open devtools
  4. (optional) set breakpoint in idletransaction.tx - will eventually point you to reactrouterv6.tsx: handleNavigation() and _useEffect()
  5. Reload page
  6. Inspect console log (Debug level)
  7. Get transaction ID from Network tab and plug into search in /products transaction of this project

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.client span (GET https://…/products) of the transaction is cut short even though corresponding backend transaction is ~ 2 seconds. Screen Shot 2022-12-07 at 9 10 28 PM

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (8 by maintainers)

Most upvoted comments

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

It turns out there are some older dependencies somewhere that cause https://github.com/facebook/create-react-app/issues/11565 which meant it wasn’t working with my default node (v18). It’s now working with node v16 but this should probably be documented somewhere!

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 + useEffect calls updatePageloadTransaction and later handleNavigation.

https://github.com/getsentry/sentry-javascript/blob/2fa11eb54f13b305dbee35687539748614583d6e/packages/react/src/reactrouterv6.tsx#L189-L201

The problem is that it calls handleNavigation with isBaseLocation == true and 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?