Skip to content

Commit

Permalink
Merge pull request #375 from rollbar/fix-telemetry-xhr-level
Browse files Browse the repository at this point in the history
update the level when we find out the status
  • Loading branch information
rokob authored Aug 15, 2017
2 parents 32b75d0 + bbdc138 commit e38ab41
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/browser/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Instrumenter.prototype.instrumentNetwork = function() {
if (xhr.__rollbar_xhr && (xhr.readyState === 1 || xhr.readyState === 4)) {
if (xhr.__rollbar_xhr.status_code === null) {
xhr.__rollbar_xhr.status_code = 0;
self.telemeter.captureNetwork(xhr.__rollbar_xhr, 'xhr');
xhr.__rollbar_event = self.telemeter.captureNetwork(xhr.__rollbar_xhr, 'xhr');
}
if (xhr.readyState === 1) {
xhr.__rollbar_xhr.start_time_ms = _.now();
Expand All @@ -114,7 +114,9 @@ Instrumenter.prototype.instrumentNetwork = function() {
}
try {
var code = xhr.status;
xhr.__rollbar_xhr.status_code = code === 1223 ? 204 : code;
code = code === 1223 ? 204 : code;
xhr.__rollbar_xhr.status_code = code;
xhr.__rollbar_event.level = self.telemeter.levelFromStatus(code);
} catch (e) {
/* ignore possible exception from xhr.status */
}
Expand Down
22 changes: 11 additions & 11 deletions src/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,20 @@ Telemeter.prototype.captureLog = function(message, level, rollbarUUID, timestamp
Telemeter.prototype.captureNetwork = function(metadata, subtype, rollbarUUID) {
subtype = subtype || 'xhr';
metadata.subtype = metadata.subtype || subtype;
var level = levelFromStatus(metadata.status_code);
var level = this.levelFromStatus(metadata.status_code);
return this.capture('network', metadata, level, rollbarUUID);
};

Telemeter.prototype.levelFromStatus = function(statusCode) {
if (statusCode >= 200 && statusCode < 400) {
return 'info';
}
if (statusCode === 0 || statusCode >= 400) {
return 'error';
}
return 'info';
};

Telemeter.prototype.captureDom = function(subtype, element, value, checked, rollbarUUID) {
var metadata = {
subtype: subtype,
Expand Down Expand Up @@ -123,14 +133,4 @@ function getLevel(type, level) {
return defaultLevel[type] || 'info';
}

function levelFromStatus(statusCode) {
if (statusCode >= 200 && statusCode < 400) {
return 'info';
}
if (statusCode === 0 || statusCode >= 400) {
return 'error';
}
return 'info';
}

module.exports = Telemeter;

0 comments on commit e38ab41

Please sign in to comment.