-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(apm): Set the transaction name for JavaScript transactions before they are flushed #18822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8369f43
579cacc
bb11e49
542bce1
194338d
5249c9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
import * as Router from 'react-router'; | ||
import {createMemoryHistory} from 'history'; | ||
import set from 'lodash/set'; | ||
|
||
import getRouteStringFromRoutes from 'app/utils/getRouteStringFromRoutes'; | ||
|
||
const createLocation = createMemoryHistory().createLocation; | ||
|
||
/** | ||
* Sets the transaction name | ||
|
@@ -9,3 +16,61 @@ export function setTransactionName(name: string) { | |
scope.setTag('ui.route', name); | ||
}); | ||
} | ||
|
||
export async function normalizeTransactionName( | ||
appRoutes: Router.PlainRoute[], | ||
event: Sentry.Event | ||
): Promise<Sentry.Event> { | ||
if (event.type !== 'transaction') { | ||
return event; | ||
} | ||
|
||
// For JavaScript transactions, translate the transaction name if it exists and doesn't start with / | ||
// using the app's react-router routes. If the transaction name doesn't exist, use the window.location.pathname | ||
// as the fallback. | ||
|
||
let prevTransactionName = event.transaction; | ||
|
||
if (typeof prevTransactionName === 'string') { | ||
if (prevTransactionName.startsWith('/')) { | ||
return event; | ||
} | ||
|
||
set(event, ['tags', 'transaction.rename.source'], 'existing transaction name'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @billyvg nah I don't think so. I think, semantically, tags that begin There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, we shouldn't be renaming transactions that begin with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense, the word "existing" kind of threw me off (I was thinking existing mean it has a correct transaction name). |
||
} else { | ||
set(event, ['tags', 'transaction.rename.source'], 'window.location.pathname'); | ||
|
||
prevTransactionName = window.location.pathname; | ||
} | ||
|
||
const transactionName: string | undefined = await new Promise(function(resolve) { | ||
Router.match( | ||
{ | ||
routes: appRoutes, | ||
location: createLocation(prevTransactionName), | ||
}, | ||
(error, _redirectLocation, renderProps) => { | ||
if (error) { | ||
set(event, ['tags', 'transaction.rename.react-router-match'], 'error'); | ||
return resolve(undefined); | ||
} | ||
|
||
set(event, ['tags', 'transaction.rename.react-router-match'], 'success'); | ||
|
||
const routePath = getRouteStringFromRoutes(renderProps.routes ?? []); | ||
return resolve(routePath); | ||
} | ||
); | ||
}); | ||
|
||
if (typeof transactionName === 'string' && transactionName.length) { | ||
event.transaction = transactionName; | ||
|
||
set(event, ['tags', 'transaction.rename.before'], prevTransactionName); | ||
set(event, ['tags', 'transaction.rename.after'], transactionName); | ||
|
||
set(event, ['tags', 'ui.route'], transactionName); | ||
} | ||
|
||
return event; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, I cannot move this to
src/sentry/static/sentry/app/utils/apm.tsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if you move it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The app doesn't load.