@@ -12,6 +12,7 @@ import React from 'react';
1212import ReactDOM from 'react-dom' ;
1313import Reflux from 'reflux' ;
1414import * as Router from 'react-router' ;
15+ import { createMemoryHistory } from 'history' ;
1516import * as Sentry from '@sentry/browser' ;
1617import { ExtraErrorData } from '@sentry/integrations' ;
1718import { Integrations } from '@sentry/apm' ;
@@ -73,6 +74,7 @@ const config = ConfigStore.getConfig();
7374const tracesSampleRate = config ? config . apmSampling : 0 ;
7475
7576const appRoutes = Router . createRoutes ( routes ( ) ) ;
77+ const createLocation = createMemoryHistory ( ) . createLocation ;
7678
7779Sentry . init ( {
7880 ...window . __SENTRY__OPTIONS ,
@@ -83,9 +85,22 @@ Sentry.init({
8385 // for JavaScript transactions, set the transaction name based on the current window.location
8486 // object against the application react-router routes
8587
88+ let prevTransactionName = event . transaction ;
89+
90+ if ( typeof prevTransactionName === 'string' ) {
91+ if ( prevTransactionName . startsWith ( '/' ) ) {
92+ return event ;
93+ }
94+ } else {
95+ prevTransactionName = window . location . pathname ;
96+ }
97+
8698 const transactionName : string | undefined = await new Promise ( function ( resolve ) {
8799 Router . match (
88- { routes : appRoutes , location : window . location } ,
100+ {
101+ routes : appRoutes ,
102+ location : createLocation ( prevTransactionName ) ,
103+ } ,
89104 ( error , _redirectLocation , renderProps ) => {
90105 if ( error ) {
91106 return resolve ( undefined ) ;
@@ -99,6 +114,14 @@ Sentry.init({
99114
100115 if ( typeof transactionName === 'string' && transactionName . length ) {
101116 event . transaction = transactionName ;
117+
118+ if ( event . tags ) {
119+ event . tags [ 'ui.route' ] = transactionName ;
120+ } else {
121+ event . tags = {
122+ 'ui.route' : transactionName ,
123+ } ;
124+ }
102125 }
103126 }
104127
0 commit comments