Skip to content

Commit f9770b0

Browse files
committed
Merge pull request #11 from stackify/SF-3437
SF-3437
2 parents 5dc1c33 + 4958dd9 commit f9770b0

File tree

11 files changed

+389
-161
lines changed

11 files changed

+389
-161
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2-
npm-debug.log
2+
npm-debug.log
3+
.idea
4+
*.iml

lib/api.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@ module.exports.methods = {
1919
DeviceName: os.hostname(),
2020
AppName: appname,
2121
ConfiguredAppName: appname,
22-
AppLocaton: process.env.PWD
22+
AppLocation: process.env.PWD
2323
},
2424
callback = function (data) {
2525
debug.write('Successfully identified');
2626

2727
CONFIG.APP_DETAILS = data;
2828

29-
//start sending logs unless it's not already being sent because of exception
30-
31-
if (!exc.excCaught) {
32-
logger.methods.start();
33-
}
29+
logger.methods.start();
3430

3531
},
3632
fail = function () {
@@ -56,7 +52,6 @@ module.exports.methods = {
5652
}
5753

5854
options = helpers.getOptions(CONFIG.IDENTIFY_PATH, body, settings ? settings.proxy : undefined);
59-
options.headers['X-Stackify-Key'] = settings.apiKey;
6055

6156
debug.write('Identifying the app');
6257
sender.send(options, callback, fail);
@@ -82,12 +77,12 @@ module.exports.methods = {
8277
var sinceFirstError;
8378
debug.write('Sending logs failed');
8479
if (code === 401) {
85-
delay = CONFIG.DELAY.FIVE_MINUTES;
80+
delay = CONFIG.DELAY.FIVE_MINUTES_DELAY;
8681
lastApiError = new Date().getTime();
8782
} else {
8883
lastApiError = lastApiError || new Date().getTime();
8984
sinceFirstError = new Date().getTime() - lastApiError;
90-
delay = Math.min(Math.max(sinceFirstError, CONFIG.DELAY.ONE_SECOND), CONFIG.DELAY.ONE_MINUTE);
85+
delay = Math.min(Math.max(sinceFirstError, CONFIG.DELAY.ONE_SECOND_DELAY), CONFIG.DELAY.ONE_MINUTE_DELAY);
9186
}
9287

9388
setTimeout(function () {

lib/debug.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var fs = require('fs'),
1212
stream = fs.createWriteStream(log_path, {flags: 'a'});
1313
stream.write(makeMsg('Debugging started'));
1414
stream.on('error', function (err) {
15-
console.error('Error occured during writing to the log file ', util.inspect(err));
15+
console.error('Error occurred during writing to the log file ', util.inspect(err));
1616
});
1717
};
1818

@@ -31,22 +31,16 @@ module.exports = {
3131
}
3232
},
3333

34-
writeResponse: function (response, close) {
34+
writeResponse: function (response) {
3535
var body = response ? response.body : null,
3636
msgBody = (body && typeof body === 'object') ? JSON.stringify(response.body, null, 4) : body,
3737
msg = response ? ('url: ' + response.request.uri.href + ':' + response.request.uri.port + ', method: '
3838
+ response.req.method + ', status: ' + response.statusCode + '\nresponse: ' + msgBody) : 'no data available';
39-
if (close) {
40-
this.close('Response received\n' + msg);
41-
} else {
42-
this.write('Response received\n' + msg);
43-
}
39+
40+
this.write('Response received\n' + msg);
4441
},
4542

4643
writeRequest: function (request, close) {
47-
if (request.body.Msgs) {
48-
request.body.Msgs = request.body.Msgs.length + ' messages';
49-
}
5044
if (close) {
5145
this.close('Request sent\n' + JSON.stringify(request, null, 4));
5246
} else {

lib/error.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var url = require('url'),
1010

1111
module.exports = {
1212
/**
13-
* Check for duplicate error messages. If the same error message logged more than configurated limit in one minute
13+
* Check for duplicate error messages. If the same error message logged more than configured limit in one minute
1414
* don't push it to the queue
1515
*/
1616
checkErrorLimitMessage : function checkErrorLimitMessage(ex) {
@@ -46,7 +46,7 @@ module.exports = {
4646
result = {},
4747
lastElement = trace[trace.length - 1];
4848

49-
if (not_direct && !exc.excCaught) {
49+
if (not_direct) {
5050
if (lastElement.CodeFileName === 'module.js') {
5151
result.SrcMethod = trace[trace.length - 2].Method;
5252
result.SrcLine = trace[trace.length - 2].LineNum;
@@ -103,9 +103,12 @@ module.exports = {
103103
PostData: helpers.getPostData(req)
104104
};
105105

106-
if (req.headers.cookie) {
107-
ex.WebRequestDetail.Headers.cookie = CONFIG.COOKIE_MASK;
108-
}
106+
// mask certain headers so data is not sent to Stackify
107+
["cookie", "authorization"].forEach(function(elm){
108+
if (req.headers[elm]) {
109+
ex.WebRequestDetail.Headers[elm] = CONFIG.COOKIE_MASK;
110+
}
111+
});
109112
}
110113

111114
return ex;

lib/exception.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ module.exports = {
4343
return next();
4444
}
4545

46-
if (!this.excCaught) {
47-
this.excCaught = true;
48-
logger.methods.sendException(err, req, cb);
49-
}
46+
logger.methods.sendException(err, req, cb);
5047
},
5148
// drain the queue and send the messages before server closes
5249
gracefulExitHandler : function gracefulExitHandler() {

lib/helpers.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ var stackTrace = require('stack-trace'),
22

33
path = require('path'),
44
os = require('os'),
5-
qs = require('querystring'),
65

76
CONFIG = require('../config/config');
87

@@ -185,25 +184,4 @@ module.exports.getHeaders = function getHeaders() {
185184
'X-Stackify-Key': CONFIG.APIKEY,
186185
'X-Stackify-PV': CONFIG.X_STACKIFY_PV
187186
};
188-
};
189-
/*
190-
*** Function for getting post data from the request
191-
*/
192-
module.exports.getPostData = function getPostData (req) {
193-
return (function() {
194-
if (request.method == 'POST') {
195-
var body = '';
196-
request.on('data', function (data) {
197-
body += data;
198-
199-
// Too much POST data, kill the connection!
200-
if (body.length > 1e6)
201-
request.connection.destroy();
202-
});
203-
request.on('end', function () {
204-
var json = qs.parse(body);
205-
req.body = json;
206-
});
207-
}
208-
}());
209-
};
187+
};

0 commit comments

Comments
 (0)