-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(tracing): ignore the xhr/fetch response if its request is not being tracked #4428
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
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.
Thank you so much for the PR! This is def something we should have accounted for. Test is great as well.
Will merge after we've addressed the comment.
@@ -216,7 +216,9 @@ export function xhrCallback( | |||
const xhr = handlerData.xhr.__sentry_xhr__; | |||
|
|||
// check first if the request has finished and is tracked by an existing span which should now end | |||
if (handlerData.endTimestamp && handlerData.xhr.__sentry_xhr_span_id__) { | |||
if (handlerData.endTimestamp) { |
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.
we probably want this logic to be like:
if (handlerData.endTimestamp) {
const spanId = handlerData.xhr.__sentry_xhr_span_id__;
if (spanId) {
const span = spans[spanId];
if (span) {
span.setHttpStatus(xhr.status_code);
span.finish();
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete spans[spanId];
}
}
return;
}
This is also more bundle size efficient
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.
hi, thanks for looking into this.
I have refactored into using the spanId
variable as suggested.
But I'm using eager-return style because it modifies less codes and I also believe multiple nesting levels is less readable. Not sure if it's significant to the bundle size?
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.
Well it's two return
keywords rather than one (both of which can't be minified), but yeah the impact is probably minimal. We can leave it like this!
trigger send request to start tracking span
packages/tracing/test/hub.test.ts
Outdated
@@ -418,6 +419,7 @@ describe('Hub', () => { | |||
|
|||
const request = new XMLHttpRequest(); | |||
request.open('GET', '/chase-partners'); | |||
request.send(); |
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.
This errors because we are now actually making the request, to a resource that doesn't exist.
As a quick thing to unblock we can just request http://example.com
- but we should probably use SinonFakeServer
like we do to test the xhr transport in
sentry-javascript/packages/browser/test/unit/transports/xhr.test.ts
Lines 18 to 24 in caba96e
let server: SinonFakeServer; | |
let transport: Transports.BaseTransport; | |
describe('XHRTransport', () => { | |
beforeEach(() => { | |
server = fakeServer.create(); | |
server.respondImmediately = true; |
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.
oh somehow the tests did not fail on my machine. They do fail when I disable the Internet. I'm working on 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.
I could not get the tests to work properly with fake servers. But since these tests do not really care about the responses, I have fixed them by waiting for the requests to complete regardless of the result
by waiting for requests properly
19a538d
to
ccecb71
Compare
@datbth both your PRs were merged, they'll be out with the next release. Really appreciate the help! If you're interested in continuing to help us out, we are hiring - and flexible to different locations! Email in GH profile if you want more details :) |
Thanks, @AbhiPrasad. I'm happy to have worked with you guys. |
yarn lint
) & (yarn test
).A possible fix for #4427