Skip to content
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

RUM Before Send Handler Includes XHR Request Details #533

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

-->

## [3.1.3]

### Changed
- Updated RUM XHR events to include `requestDetails` for the `onBeforeSendRUM` handler. Request details include `url` (including query parameters), `method`, `body` and `responseBody`. These details are stripped from the payload before it's sent to Raygun's servers.

## [3.1.2]

### Changed
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raygun4js",
"version": "3.1.2",
"version": "3.1.3",
"homepage": "http://raygun.com",
"authors": [
"Mindscape <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"title": "Raygun4js",
"description": "Raygun.com plugin for JavaScript",
"version": "3.1.2",
"version": "3.1.3",
"homepage": "https://github.com/MindscapeHQ/raygun4js",
"author": {
"name": "MindscapeHQ",
Expand Down
2 changes: 1 addition & 1 deletion raygun4js.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>raygun4js</id>
<version>3.1.2</version>
<version>3.1.3</version>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a minor version, not a patch, but I am not being pedantic here, go as is :-)

<title>Raygun4js</title>
<authors>Raygun Limited</authors>
<owners>Raygun Limited</owners>
Expand Down
43 changes: 35 additions & 8 deletions src/raygun.rum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,10 +733,17 @@ var raygunRumFactory = function (window, $, Raygun) {

var xhrStatusesForName = this.xhrStatusMap[url];
if (xhrStatusesForName && xhrStatusesForName.length > 0) {
var request = this.xhrStatusMap[url].shift();
var xhrStatus = this.xhrStatusMap[url].shift();

timingData.statusCode = request.status;
timingData.parentResource = request.parentResource;
timingData.statusCode = xhrStatus.response.status;
timingData.parentResource = xhrStatus.parentResource;

timingData.requestDetails = {
url: xhrStatus.request.requestURL,
method: xhrStatus.request.method,
body: xhrStatus.request.body,
responseBody: xhrStatus.response.body
};

log('found status for timing', timingData.statusCode);
if (this.xhrStatusMap[url].length === 0) {
Expand Down Expand Up @@ -984,7 +991,8 @@ var raygunRumFactory = function (window, $, Raygun) {
if (!!payload.eventData) {
for (var i = 0; i < payload.eventData.length; i++) {
if (!!payload.eventData[i].data && typeof payload.eventData[i].data !== 'string') {
payload.eventData[i].data = JSON.stringify(payload.eventData[i].data);
var strippedEventData = stripRequestDetailsFromPayloadEventData(payload.eventData[i].data);
payload.eventData[i].data = JSON.stringify(strippedEventData);
}
}
}
Expand Down Expand Up @@ -1012,6 +1020,18 @@ var raygunRumFactory = function (window, $, Raygun) {
}, (window.raygunUserAgentDataStatus === 1 ? 200 : 0));
}

function stripRequestDetailsFromPayloadEventData(payloadEventData){
for (var i = 0 ; i < payloadEventData.length; i++) {
var eventDataItem = payloadEventData[i];

if (eventDataItem.requestDetails) {
delete eventDataItem.requestDetails;
}
}

return payloadEventData;
}

function updateUserAgentData(payload) {
if (!payload.eventData) { return; }

Expand Down Expand Up @@ -1174,7 +1194,9 @@ var raygunRumFactory = function (window, $, Raygun) {
var requests = this.xhrRequestMap[response.baseUrl];

if (requests && requests.length > 0) {
var parentResource = requests[0].parentResource;
var request = requests[0];

var parentResource = request.parentResource;

this.xhrRequestMap[response.baseUrl].shift();

Expand All @@ -1186,9 +1208,14 @@ var raygunRumFactory = function (window, $, Raygun) {
this.xhrStatusMap[response.baseUrl] = [];
}

log('adding response to xhr status map', response);
var responseWithParent = attachParentResource(response, parentResource);
this.xhrStatusMap[response.baseUrl].push(responseWithParent);
var requestAndResponse = {
request: request,
response: response
};

log('adding request/response to xhr status map', requestAndResponse);
var requestAndResponseWithParent = attachParentResource(requestAndResponse, parentResource);
this.xhrStatusMap[response.baseUrl].push(requestAndResponseWithParent);
} else {
log('response fired from non-handled request');
}
Expand Down