@@ -12,7 +12,6 @@ import React from 'react';
1212import ReactDOM from 'react-dom' ;
1313import Reflux from 'reflux' ;
1414import * as Router from 'react-router' ;
15- import { createMemoryHistory } from 'history' ;
1615import * as Sentry from '@sentry/browser' ;
1716import { ExtraErrorData } from '@sentry/integrations' ;
1817import { Integrations } from '@sentry/apm' ;
@@ -27,8 +26,7 @@ import ConfigStore from 'app/stores/configStore';
2726import Main from 'app/main' ;
2827import ajaxCsrfSetup from 'app/utils/ajaxCsrfSetup' ;
2928import plugins from 'app/plugins' ;
30- import routes from 'app/routes' ;
31- import getRouteStringFromRoutes from 'app/utils/getRouteStringFromRoutes' ;
29+ import { normalizeTransactionName } from 'app/utils/apm' ;
3230
3331function getSentryIntegrations ( hasReplays : boolean = false ) {
3432 const integrations = [
@@ -73,60 +71,12 @@ const tracesSampleRate = config ? config.apmSampling : 0;
7371const hasReplays =
7472 window . __SENTRY__USER && window . __SENTRY__USER . isStaff && ! ! process . env . DISABLE_RR_WEB ;
7573
76- const appRoutes = Router . createRoutes ( routes ( ) ) ;
77- const createLocation = createMemoryHistory ( ) . createLocation ;
78-
7974Sentry . init ( {
8075 ...window . __SENTRY__OPTIONS ,
8176 integrations : getSentryIntegrations ( hasReplays ) ,
8277 tracesSampleRate,
8378 async beforeSend ( event ) {
84- if ( event . type === 'transaction' ) {
85- // For JavaScript transactions, translate the transaction name if it exists and doesn't start with /
86- // using the app's react-router routes. If the transaction name doesn't exist, use the window.location.pathname
87- // as the fallback.
88-
89- let prevTransactionName = event . transaction ;
90-
91- if ( typeof prevTransactionName === 'string' ) {
92- if ( prevTransactionName . startsWith ( '/' ) ) {
93- return event ;
94- }
95- } else {
96- prevTransactionName = window . location . pathname ;
97- }
98-
99- const transactionName : string | undefined = await new Promise ( function ( resolve ) {
100- Router . match (
101- {
102- routes : appRoutes ,
103- location : createLocation ( prevTransactionName ) ,
104- } ,
105- ( error , _redirectLocation , renderProps ) => {
106- if ( error ) {
107- return resolve ( undefined ) ;
108- }
109-
110- const routePath = getRouteStringFromRoutes ( renderProps . routes ?? [ ] ) ;
111- return resolve ( routePath ) ;
112- }
113- ) ;
114- } ) ;
115-
116- if ( typeof transactionName === 'string' && transactionName . length ) {
117- event . transaction = transactionName ;
118-
119- if ( event . tags ) {
120- event . tags [ 'ui.route' ] = transactionName ;
121- } else {
122- event . tags = {
123- 'ui.route' : transactionName ,
124- } ;
125- }
126- }
127- }
128-
129- return event ;
79+ return normalizeTransactionName ( event ) ;
13080 } ,
13181} ) ;
13282
0 commit comments