Skip to content

Commit

Permalink
Handle the case of xhr request + add a unit test for the case
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyad-elabid-nw committed Jun 30, 2023
1 parent 40e44eb commit 35b0909
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/replay/src/coreHandlers/util/xhrUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function _prepareXhrData(
return null;
}

if (!urlMatches(url, options.networkDetailAllowUrls)) {
if (!urlMatches(url, options.networkDetailAllowUrls) || urlMatches(url, options.networkDetailExcludeUrls)) {
const request = buildSkippedNetworkRequestOrResponse(requestBodySize);
const response = buildSkippedNetworkRequestOrResponse(responseBodySize);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,85 @@ other-header: test`;
},
]);
});

it('correctly excludes URL for xhr request', async () => {
options.networkDetailExcludeUrls = [
'https://example.com/foo',
'com/bar',
/^http:\/\/example.com\/exact$/,
/^http:\/\/example.com\/partial/,
];

const breadcrumb: Breadcrumb = {
category: 'xhr',
data: {
method: 'GET',
url,
status_code: 200,
},
};
const xhr = new XMLHttpRequest();
Object.defineProperty(xhr, 'response', {
value: 'test response',
});
Object.defineProperty(xhr, 'responseText', {
value: 'test response',
});
const hint: XhrBreadcrumbHint = {
xhr,
input: 'test input',
startTimestamp: BASE_TIMESTAMP + 1000,
endTimestamp: BASE_TIMESTAMP + 2000,
};
beforeAddNetworkBreadcrumb(options, breadcrumb, hint);

expect(breadcrumb).toEqual({
category: 'xhr',
data: {
method: 'GET',
request_body_size: 10,
response_body_size: 13,
status_code: 200,
url,
},
});

await waitForReplayEventBuffer();

expect((options.replay.eventBuffer as EventBufferArray).events).toEqual([
{
data: {
payload: {
data: {
method: 'GET',
request: {
_meta: {
warnings: ['URL_SKIPPED'],
},
headers: {},
size: 10,
},
response: {
_meta: {
warnings: ['URL_SKIPPED'],
},
headers: {},
size: 13,
},
statusCode: 200,
},
description: url,
endTimestamp: 1580598002,
op: 'resource.xhr',
startTimestamp: 1580598001,
},
tag: 'performanceSpan',
},
timestamp: 1580598001,
type: 5,
},
]);
});
});
});
});

0 comments on commit 35b0909

Please sign in to comment.