fix(apm): Set the transaction name for JavaScript transactions before they are flushed#18822
fix(apm): Set the transaction name for JavaScript transactions before they are flushed#18822
Conversation
73048dc to
67c4264
Compare
HazAT
left a comment
There was a problem hiding this comment.
Can we remove the code from app/utils/apm.tsx that sets the transaction?
| location: createLocation(prevTransactionName), | ||
| }, | ||
| (error, _redirectLocation, renderProps) => { | ||
| if (error) { |
There was a problem hiding this comment.
Do we know the cases when this might fail?
Because in those cases we would still get the full url.
I just wanted to highlight this.
There was a problem hiding this comment.
Unfortunately we may not know.
We need to at least handle this otherwise the transaction name will be overridden by a worst choice of a transaction name; in this case, a blank string.
|
How do we document this in our SDKs, framework docs, etc. so that other people can easily follow this example? cc @HazAT |
|
@HazAT I've noticed that we do not call the set transaction name on @dashed and I were talking about removing |
|
Going to put this PR on pause and try #18836 for a week or so. |
|
@benvinegar Revisiting the docs explaining how to APM in Python/JS is my next project. We currently have an example of instrumenting a react component which I'd like to flesh out and clean up a bit. Will definitely be looking for feedback on that section once I have a draft, since I'm still fairly new to react. |
3a50682 to
515b1b2
Compare
There was a problem hiding this comment.
Should we tag this event to identify how often this happens?
There was a problem hiding this comment.
@dashed Yeah, might be nice to have it as a tag in the event
There was a problem hiding this comment.
@dashed Yeah, you may be able to simplify to prev !== transactionName if you don't need the prev transaction name (since you already have transaction name).
There was a problem hiding this comment.
@billyvg I'm unsure what you meant. prevTransactionName !== transactionName should be guaranteed to be true in this code path.
There was a problem hiding this comment.
Ah, then the previous tag should be enough, and if you wanted to know the number of transactions that required normalization you can query for something like !transaction.rename.before:''?
There was a problem hiding this comment.
I think has:transaction.rename.source might be the search condition. Since this gets set knowing that normalization is required. And regardless of whether or not the normalization process was successful.
7a5ba50 to
3149baf
Compare
| const hasReplays = | ||
| window.__SENTRY__USER && window.__SENTRY__USER.isStaff && !!process.env.DISABLE_RR_WEB; | ||
|
|
||
| const appRoutes = Router.createRoutes(routes()); |
There was a problem hiding this comment.
For some reason, I cannot move this to src/sentry/static/sentry/app/utils/apm.tsx
| return event; | ||
| } | ||
|
|
||
| set(event, ['tags', 'transaction.rename.source'], 'existing transaction name'); |
There was a problem hiding this comment.
There was a problem hiding this comment.
@billyvg nah I don't think so. I think, semantically, tags that begin transaction.rename should only apply to events that have undergone a transaction rename process.
There was a problem hiding this comment.
To clarify, we shouldn't be renaming transactions that begin with /. Since these transactions are what we'd expect. They've already been renamed at the React app level from within the lifecycle method.
There was a problem hiding this comment.
That makes sense, the word "existing" kind of threw me off (I was thinking existing mean it has a correct transaction name).
… they are flushed Set the transaction name for JavaScript transactions based on latest window.location object just before the transaction is flushed. The window.location object is translated based on the app react-router routes using the react-router utility functions.
58bb0bf to
5249c9b
Compare
For JavaScript transactions, translate the transaction name if it exists and doesn't start with
/using the app's react-router routes; the expected transaction name would be the URL, which is set by the JS SDK.
If the transaction name doesn't exist, use the
window.location.pathnameas the fallback.The transaction name is translated based on the app react-router routes using the react-router utility functions.
This should deal with the race condition between setting the transaction name during the React render reconciliation and when transactions are flushed.
TODO
ui.routetag