Skip to content

Commit

Permalink
Move two utilities back into timing data section
Browse files Browse the repository at this point in the history
  • Loading branch information
UberMouse committed Nov 2, 2018
1 parent c13a3a9 commit 0a9dd7a
Showing 1 changed file with 50 additions and 48 deletions.
98 changes: 50 additions & 48 deletions src/raygun.rum.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,26 @@ var raygunRumFactory = function(window, $, Raygun) {
return data;
}

function extractChildData(collection, fromVirtualPage) {
if (!performanceEntryExists('getEntries', 'function')) {
return;
}

try {
var resources = window.performance.getEntries();

for (var i = self.offset; i < resources.length; i++) {
var segment = resources[i].name.split('?')[0];
if (!shouldIgnoreResource(segment)) {
collection.push(getSecondaryTimingData(resources[i], fromVirtualPage));
}
}

self.offset = resources.length;
} catch (e) {}
}


function getPrimaryTimingData() {
var pathName = window.location.pathname;

Expand Down Expand Up @@ -629,6 +649,36 @@ var raygunRumFactory = function(window, $, Raygun) {
};
}

function getPerformanceData(virtualPage, firstLoad) {
if (
!performanceEntryExists('timing', 'object') ||
window.performance.timing.fetchStart === undefined ||
isNaN(window.performance.timing.fetchStart)
) {
return null;
}

var data = [];

if (firstLoad) {
// Called by the static onLoad event being fired, persist itself
data.push(getPrimaryTimingData());
}

// Called during both the static load event and the virtual load calls
// Associates all data loaded up to this point with the previous page
// Eg: Page load if it is this is a new load, or the last view if a virtual page was freshly triggered
extractChildData(data);

if (virtualPage) {
data.push(getVirtualPrimaryTimingData(virtualPage, getPerformanceNow(0)));
extractChildData(data, true);
}

return data;
}


function getSecondaryTimingData(timing, fromZero) {
var url = timing.name.split('?')[0];

Expand Down Expand Up @@ -676,35 +726,6 @@ var raygunRumFactory = function(window, $, Raygun) {
return false;
}

function getPerformanceData(virtualPage, firstLoad) {
if (
!performanceEntryExists('timing', 'object') ||
window.performance.timing.fetchStart === undefined ||
isNaN(window.performance.timing.fetchStart)
) {
return null;
}

var data = [];

if (firstLoad) {
// Called by the static onLoad event being fired, persist itself
data.push(getPrimaryTimingData());
}

// Called during both the static load event and the virtual load calls
// Associates all data loaded up to this point with the previous page
// Eg: Page load if it is this is a new load, or the last view if a virtual page was freshly triggered
extractChildData(data);

if (virtualPage) {
data.push(getVirtualPrimaryTimingData(virtualPage, getPerformanceNow(0)));
extractChildData(data, true);
}

return data;
}

function sanitizeNaNs(data) {
for (var i in data) {
if (isNaN(data[i]) && typeof data[i] !== 'string') {
Expand Down Expand Up @@ -813,25 +834,6 @@ var raygunRumFactory = function(window, $, Raygun) {
return null;
}

function extractChildData(collection, fromVirtualPage) {
if (!performanceEntryExists('getEntries', 'function')) {
return;
}

try {
var resources = window.performance.getEntries();

for (var i = self.offset; i < resources.length; i++) {
var segment = resources[i].name.split('?')[0];
if (!shouldIgnoreResource(segment)) {
collection.push(getSecondaryTimingData(resources[i], fromVirtualPage));
}
}

self.offset = resources.length;
} catch (e) {}
}

function getSecondaryTimingType(timing) {
if (timing.initiatorType === 'xmlhttprequest' || timing.initiatorType === "fetch") {
return Timings.XHR;
Expand Down

0 comments on commit 0a9dd7a

Please sign in to comment.