-
-
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
Conversation
73048dc
to
67c4264
Compare
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
event.transaction = transactionName; | ||
|
||
if (event.tags) { | ||
event.tags['ui.route'] = transactionName; |
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.
Should we tag this event to identify how often this happens?
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.
@billyvg do you mean analytics?
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.
@dashed Yeah, might be nice to have it as a tag in the 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.
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -70,10 +72,15 @@ const tracesSampleRate = config ? config.apmSampling : 0; | |||
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.
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.
return event; | ||
} | ||
|
||
set(event, ['tags', 'transaction.rename.source'], 'existing transaction name'); |
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.
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The 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).
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.
Lgtm
… 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.pathname
as 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.route
tag