Skip to content

Commit 541dd22

Browse files
authored
Merge pull request #533 from MindscapeHQ/mb/request-data-for-rum-before-send-handler
RUM Before Send Handler Includes XHR Request Details
2 parents 5cedcbb + 4bb8e67 commit 541dd22

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
3030
-->
3131

32+
## [3.1.3]
33+
34+
### Changed
35+
- 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.
36+
3237
## [3.1.2]
3338

3439
### Changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "raygun4js",
3-
"version": "3.1.2",
3+
"version": "3.1.3",
44
"homepage": "http://raygun.com",
55
"authors": [
66
"Mindscape <[email protected]>"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"title": "Raygun4js",
99
"description": "Raygun.com plugin for JavaScript",
10-
"version": "3.1.2",
10+
"version": "3.1.3",
1111
"homepage": "https://github.com/MindscapeHQ/raygun4js",
1212
"author": {
1313
"name": "MindscapeHQ",

raygun4js.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata>
44
<id>raygun4js</id>
5-
<version>3.1.2</version>
5+
<version>3.1.3</version>
66
<title>Raygun4js</title>
77
<authors>Raygun Limited</authors>
88
<owners>Raygun Limited</owners>

src/raygun.rum/index.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,17 @@ var raygunRumFactory = function (window, $, Raygun) {
733733

734734
var xhrStatusesForName = this.xhrStatusMap[url];
735735
if (xhrStatusesForName && xhrStatusesForName.length > 0) {
736-
var request = this.xhrStatusMap[url].shift();
736+
var xhrStatus = this.xhrStatusMap[url].shift();
737737

738-
timingData.statusCode = request.status;
739-
timingData.parentResource = request.parentResource;
738+
timingData.statusCode = xhrStatus.response.status;
739+
timingData.parentResource = xhrStatus.parentResource;
740+
741+
timingData.requestDetails = {
742+
url: xhrStatus.request.requestURL,
743+
method: xhrStatus.request.method,
744+
body: xhrStatus.request.body,
745+
responseBody: xhrStatus.response.body
746+
};
740747

741748
log('found status for timing', timingData.statusCode);
742749
if (this.xhrStatusMap[url].length === 0) {
@@ -984,7 +991,8 @@ var raygunRumFactory = function (window, $, Raygun) {
984991
if (!!payload.eventData) {
985992
for (var i = 0; i < payload.eventData.length; i++) {
986993
if (!!payload.eventData[i].data && typeof payload.eventData[i].data !== 'string') {
987-
payload.eventData[i].data = JSON.stringify(payload.eventData[i].data);
994+
var strippedEventData = stripRequestDetailsFromPayloadEventData(payload.eventData[i].data);
995+
payload.eventData[i].data = JSON.stringify(strippedEventData);
988996
}
989997
}
990998
}
@@ -1012,6 +1020,18 @@ var raygunRumFactory = function (window, $, Raygun) {
10121020
}, (window.raygunUserAgentDataStatus === 1 ? 200 : 0));
10131021
}
10141022

1023+
function stripRequestDetailsFromPayloadEventData(payloadEventData){
1024+
for (var i = 0 ; i < payloadEventData.length; i++) {
1025+
var eventDataItem = payloadEventData[i];
1026+
1027+
if (eventDataItem.requestDetails) {
1028+
delete eventDataItem.requestDetails;
1029+
}
1030+
}
1031+
1032+
return payloadEventData;
1033+
}
1034+
10151035
function updateUserAgentData(payload) {
10161036
if (!payload.eventData) { return; }
10171037

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

11761196
if (requests && requests.length > 0) {
1177-
var parentResource = requests[0].parentResource;
1197+
var request = requests[0];
1198+
1199+
var parentResource = request.parentResource;
11781200

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

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

1189-
log('adding response to xhr status map', response);
1190-
var responseWithParent = attachParentResource(response, parentResource);
1191-
this.xhrStatusMap[response.baseUrl].push(responseWithParent);
1211+
var requestAndResponse = {
1212+
request: request,
1213+
response: response
1214+
};
1215+
1216+
log('adding request/response to xhr status map', requestAndResponse);
1217+
var requestAndResponseWithParent = attachParentResource(requestAndResponse, parentResource);
1218+
this.xhrStatusMap[response.baseUrl].push(requestAndResponseWithParent);
11921219
} else {
11931220
log('response fired from non-handled request');
11941221
}

0 commit comments

Comments
 (0)