Skip to content

Commit d3515b9

Browse files
committed
translate transaction name if it exists and doesn't start with /
1 parent 67c4264 commit d3515b9

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

‎src/sentry/static/sentry/app/bootstrap.tsx‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import React from 'react';
1212
import ReactDOM from 'react-dom';
1313
import Reflux from 'reflux';
1414
import * as Router from 'react-router';
15+
import {createMemoryHistory} from 'history';
1516
import * as Sentry from '@sentry/browser';
1617
import {ExtraErrorData} from '@sentry/integrations';
1718
import {Integrations} from '@sentry/apm';
@@ -73,6 +74,7 @@ const config = ConfigStore.getConfig();
7374
const tracesSampleRate = config ? config.apmSampling : 0;
7475

7576
const appRoutes = Router.createRoutes(routes());
77+
const createLocation = createMemoryHistory().createLocation;
7678

7779
Sentry.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

Comments
 (0)