Skip to content

Commit

Permalink
Errors: Send during onload if autorun=false
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Apr 3, 2018
1 parent 970ad46 commit 46c6f62
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 7 deletions.
2 changes: 1 addition & 1 deletion boomerang.js
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ BOOMR_check_doc_domain();
if (impl.disabled_plugins[k]) {
continue;
}
if (!this.plugins[k].is_complete()) {
if (!this.plugins[k].is_complete(impl.vars)) {
BOOMR.debug("Plugin " + k + " is not complete, deferring beacon send");
return false;
}
Expand Down
36 changes: 33 additions & 3 deletions plugins/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,17 @@
sendAfterOnload: false,
isDuringLoad: true,
maxErrors: 10,
// How often to send an error beacon after onload
sendInterval: 1000,
// How often to send a beacon during onload if autorun=false
sendIntervalDuringLoad: 2500,
sendIntervalId: -1,
maxEvents: 10,

// state
initialized: false,
supported: false,
autorun: true,

/**
* All errors
Expand Down Expand Up @@ -633,7 +637,7 @@
* @param {number} source SOURCE_* constant
*/
addError: function(error, via, source) {
var onErrorResult, err, dup = false;
var onErrorResult, err, dup = false, now = BOOMR.now();

// only track post-load errors if configured
if (!impl.isDuringLoad && !impl.sendAfterOnload) {
Expand Down Expand Up @@ -671,7 +675,14 @@
// add to our current queue
impl.mergeDuplicateErrors(impl.q, err, true);

if (!impl.isDuringLoad && impl.sendIntervalId === -1) {
//
// There are a few reasons we'll send an error beacon on its own:
// 1. If this is after onload, and sendAfterOnload is set.
// 2. If this is during onload, but autorun is false. In that case,
// we want to send out errors (after a small delay) in case the
// page never loads (e.g. due to the error).
//
if ((!impl.isDuringLoad || !impl.autorun) && impl.sendIntervalId === -1) {
if (dup) {
// If this is not during a load, and it's a duplicate of
// a previous error, don't send a beacon just for itself
Expand All @@ -682,6 +693,13 @@
impl.sendIntervalId = setTimeout(function() {
impl.sendIntervalId = -1;

// Don't send a beacon if we've already flushed the queue. This
// might happen for pre-onload becaons if the onload beacon was
// sent after queueing
if (impl.q.length === 0) {
return;
}

// change this to an 'error' beacon
BOOMR.addVar("http.initiator", "error");

Expand All @@ -691,9 +709,17 @@
// add our errors to the beacon
impl.addErrorsToBeacon();

// ensure start/end timestamps are on the beacon since the RT
// plugin won't run until onload
if (impl.isDuringLoad) {
BOOMR.addVar("rt.tstart", now);
BOOMR.addVar("rt.end", now);
BOOMR.addVar("rt.start", "manual");
}

// send it!
BOOMR.sendBeacon();
}, impl.sendInterval);
}, impl.isDuringLoad ? impl.sendIntervalDuringLoad : impl.sendInterval);
}
},

Expand Down Expand Up @@ -1401,6 +1427,10 @@
return this;
}

if (config && typeof config.autorun !== "undefined") {
impl.autorun = config.autorun;
}

impl.initialized = true;

// TODO determine what we don't support
Expand Down
5 changes: 4 additions & 1 deletion plugins/rt.js
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,10 @@
return this;
},

is_complete: function() { return impl.complete; },
is_complete: function(vars) {
// allow error beacons to go through even if we're not complete
return impl.complete || (vars && vars["http.initiator"] === "error");
},

/**
* @desc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
}
});
</script>
<!-- delay the page by 1second so several errors can fire -->
<img src="/delay?delay=1000&amp;file=/assets/img.jpg" style="width: 100px" />
<!-- delay the page by 5 seconds so several errors can fire -->
<img src="/delay?delay=5000&amp;file=/assets/img.jpg" style="width: 100px" />
<%= footer %>
20 changes: 20 additions & 0 deletions tests/page-templates/14-errors/23-autorun-false.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<%= header %>
<%= boomerangScript %>
<!--
For this test, we'll turn autorun off and trigger an error.
We should see an error beacon be sent, even if no page load beacon is sent.
-->
<script src="23-autorun-false.js" type="text/javascript"></script>
<script>
BOOMR_test.init({
testAfterOnBeacon: true,
Errors: {
enabled: true
},
autorun: false
});

var a = badFunction();
</script>
<%= footer %>
62 changes: 62 additions & 0 deletions tests/page-templates/14-errors/23-autorun-false.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*eslint-env mocha*/
/*global BOOMR_test,assert,describe,it*/

describe("e2e/14-errors/23-autorun-false", function() {
var tf = BOOMR.plugins.TestFramework;
var t = BOOMR_test;
var C = BOOMR.utils.Compression;

it("Should have sent one beacon", function(done) {
this.timeout(10000);
t.ensureBeaconCount(done, 1);
});

it("Should have http.initiator = error", function() {
var b = tf.lastBeacon();
assert.equal(b["http.initiator"], "error");
});

it("Should have put err on the beacon", function() {
var b = tf.lastBeacon();
assert.isDefined(b.err);
});

it("Should have an error count = 1", function() {
var b = tf.lastBeacon();
var err = BOOMR.plugins.Errors.decompressErrors(C.jsUrlDecompress(b.err))[0];
assert.equal(err.count, 1);
});

it("Should have an error coming from the html page", function() {
var b = tf.lastBeacon();
var err = BOOMR.plugins.Errors.decompressErrors(C.jsUrlDecompress(b.err))[0];

if (err.fileName) {
assert.include(err.fileName, "23-autorun-false.html");
}

if (err.functionName) {
assert.include(err.functionName, "badFunction");
}
});

it("Should have rt.end", function() {
var b = tf.lastBeacon();
assert.isDefined(b["rt.end"]);
});

it("Should have rt.sl = 0", function() {
var b = tf.lastBeacon();
assert.equal(b["rt.sl"], 0);
});

it("Should have rt.tstart", function() {
var b = tf.lastBeacon();
assert.isDefined(b["rt.tstart"]);
});

it("Should have rt.start = manual", function() {
var b = tf.lastBeacon();
assert.equal(b["rt.start"], "manual");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%= header %>
<%= boomerangScriptMin %>
<!--
For this test, we'll turn autorun off and trigger an two errors, wait, then call
BOOMR.page_ready() so the real beacon is sent.
We should see an error beacon be sent, then the page load beacon later.
-->
<script src="24-autorun-false-multiple-then-load.js" type="text/javascript"></script>
<script>
BOOMR_test.init({
testAfterOnBeacon: 2,
Errors: {
enabled: true
},
autorun: false
});

setTimeout(function() {
// wait until after the error beacon is sent
BOOMR.page_ready();
}, 5000);

var a = badFunction();
</script>
<script>
var b = badFunction2();
</script>
<%= footer %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*eslint-env mocha*/
/*global BOOMR_test,assert,describe,it*/

describe("e2e/14-errors/24-autorun-false-multiple-then-load", function() {
var tf = BOOMR.plugins.TestFramework;
var t = BOOMR_test;
var C = BOOMR.utils.Compression;

it("Should have sent two beacons", function(done) {
this.timeout(10000);
t.ensureBeaconCount(done, 2);
});

it("Should have http.initiator = error on the first beacon", function() {
var b = tf.beacons[0];
assert.equal(b["http.initiator"], "error");
});

it("Should have put err on the first beacon", function() {
var b = tf.beacons[0];
assert.isDefined(b.err);
});

it("Should have two errors on the first beacon", function() {
var b = tf.beacons[0];
var errs = BOOMR.plugins.Errors.decompressErrors(C.jsUrlDecompress(b.err));
assert.equal(errs.length, 2);
});

it("Should have an error count = 1 on the first beacon first error", function() {
var b = tf.beacons[0];
var err = BOOMR.plugins.Errors.decompressErrors(C.jsUrlDecompress(b.err))[0];
assert.equal(err.count, 1);
});

it("Should have an error coming from the html page on the first beacon first error", function() {
var b = tf.beacons[0];
var err = BOOMR.plugins.Errors.decompressErrors(C.jsUrlDecompress(b.err))[0];

if (err.fileName) {
assert.include(err.fileName, "24-autorun-false-multiple-then-load.html");
}

if (err.functionName) {
assert.include(err.functionName, "badFunction");
}
});

it("Should have rt.end on the first beacon", function() {
var b = tf.beacons[0];
assert.isDefined(b["rt.end"]);
});

it("Should have rt.tstart on the first beacon", function() {
var b = tf.beacons[0];
assert.isDefined(b["rt.tstart"]);
});

it("Should have rt.start = manual on the first beacon", function() {
var b = tf.beacons[0];
assert.equal(b["rt.start"], "manual");
});

it("Should have no http.initiator the second beacon", function() {
var b = tf.beacons[1];
assert.isUndefined(b["http.initiator"]);
});

it("Should have rt.start=navigation on the second beacon (if NavigationTiming is supported)", function() {
if (t.isNavigationTimingSupported()) {
assert.equal(tf.beacons[1]["rt.start"], "navigation");
}
else {
assert.equal(tf.beacons[1]["rt.start"], "none");
}
});

it("Should have put NavigationTiming metrics on the second beacon (if NavigationTiming is supported)", function() {
if (t.isNavigationTimingSupported()) {
assert.isDefined(tf.beacons[1].nt_nav_st);
assert.isDefined(tf.beacons[1].nt_load_st);
}
});

it("Should have rt.sl = 0 on the first beacon", function() {
var b = tf.beacons[0];
assert.equal(b["rt.sl"], 0);
});

it("Should have rt.sl = 1 on the second beacon", function() {
var b = tf.beacons[1];
assert.equal(b["rt.sl"], 1);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<%= header %>
<%= boomerangScriptMin %>
<!--
For this test, we'll turn autorun off and trigger an error.
BOOMR.page_ready() happens right afterward, and should send the normal page load beacon with the error.
-->
<script src="25-autorun-false-onload-happens.js" type="text/javascript"></script>
<script>
BOOMR_test.init({
testAfterOnBeacon: true,
Errors: {
enabled: true
},
autorun: false
});

var a = badFunction();
</script>
<script>
BOOMR.page_ready();
</script>
<%= footer %>
Loading

0 comments on commit 46c6f62

Please sign in to comment.