Permalink
Browse files

It works!

  • Loading branch information...
mattrobenolt committed Mar 17, 2012
1 parent 5aca11f commit 546de7f260b543c9a95f288b231ac74696eb51b2
Showing with 34 additions and 29 deletions.
  1. +15 −14 lib/client.js
  2. +10 −8 lib/middleware/connect-raven.js
  3. +5 −3 lib/utils.js
  4. +2 −2 test/raven.client.js
  5. +2 −2 test/raven.utils.js
View
@@ -24,6 +24,8 @@ _.process = function process(kwargs) {
checksum;
kwargs['event_id'] = event_id;
+ kwargs['timestamp'] = new Date().toISOString().split('.')[0];
+ kwargs['project'] = this.dsn.project_id;
if(!kwargs['checksum']){
checksum = kwargs['checksum'] = utils.construct_checksum(kwargs);
@@ -45,31 +47,31 @@ _.sendRemote = function sendRemote(message, headers, callback) {
var self = this;
var options = {
host: self.dsn.host,
- path: self.dsn.path + '/' + self.dsn.project_id,
+ path: self.dsn.path + '/api/store/',
headers: headers,
method: 'POST'
}, req = http[self.dsn.protocol].request(options, function(res){
+ res.setEncoding('utf8');
res.on('data', function(data) {
- //console.log(data.toString());
+ // don't care!
});
});
req.on('error', function(e){
- //console.log(e.message);
+ // do we care?
});
req.end(message);
};
_.send = function send(kwargs) {
var self = this;
zlib.deflate(JSON.stringify(kwargs), function(err, buff) {
- var message = buff.toString('base64');
- //TODO: refactor this to not blast out to all servers at once.
- var timestamp = new Date().getTime()/1000,
- signature = utils.get_signature(self.dsn.public_key, message, timestamp),
+ var message = buff.toString('base64'),
+ timestamp = new Date().getTime(),
+ signature = utils.get_signature(self.dsn.private_key, message, timestamp),
headers = {
- 'X-Sentry-Auth': utils.get_auth_header(signature, timestamp),
+ 'X-Sentry-Auth': utils.get_auth_header(signature, timestamp, self.dsn.public_key, self.dsn.project_id),
'Content-Type': 'application/octet-stream',
- 'Content-Length': message.length,
+ 'Content-Length': message.length
};
self.sendRemote(message, headers);
@@ -87,10 +89,10 @@ _.create_from_text = function createFromText(message, kwargs, callback) {
kwargs['message'] = message;
kwargs['sentry.interfaces.Message'] = {
message: message,
- params: {}
+ params: []
};
var result = this.process(kwargs);
- if(callback) callback(result);
+ callback && callback(result);
};
_.createFromError =
@@ -109,18 +111,17 @@ _.create_from_error = function createFromError(err, kwargs, callback) {
kwargs['sentry.interfaces.Stacktrace'] = {frames:frames};
kwargs['culprit'] = err.name + ' in ' + err.stack.split('\n')[1].match(/^.*?\((.*?):\d+:\d+\)$/)[1].replace(process.cwd()+'/', '');
var result = self.process(kwargs);
- if(callback) callback(result);
+ callback && callback(result);
});
};
module.exports.patchGlobal =
module.exports.patch_global = function patchGlobal(options) {
+ var util = require('util');
var client = (options instanceof Client) ? options : new Client(options);
process.on('uncaughtException', function(err) {
client.createFromError(err, function(result) {
- var util = require('util');
util.log('uncaughtException: '+client.get_ident(result));
});
- // client.create_from_exception(err);
});
};
@@ -1,24 +1,26 @@
-var Client = require('../client').Client;
+var Client = require('../client').Client
+ , url = require('url');
module.exports = function raven(options) {
var client = (options instanceof Client) ? options : new Client(options);
return function(err, req, res, next) {
var kwargs = {
'sentry.interfaces.Http': {
method: req.method,
- data: {META: {
- headers: req.headers,
- }},
- url: (function build_absolute_url(req) {
+ query_string: url.parse(req.url).query,
+ headers: req.headers,
+ cookies: req.cookies || '<unavailable: use cookieParser middleware>',
+ data: req.body || '<unavailable: use bodyParser middleware>',
+ url: (function build_absolute_url() {
var protocol = req.socket.encrypted ? 'https' : 'http',
host = req.headers.host || '<no host>';
return protocol+'://'+host+req.url;
- }(req))
+ }()),
+ env: process.env
}
};
client.createFromError(err, kwargs, function(result) {
- result.ident = client.getIdent(result);
- res.sentry = result;
+ res.sentry = client.getIdent(result);
next(err, req, res);
});
};
View
@@ -15,11 +15,13 @@ module.exports.get_signature = function get_signature(key, message, timestamp) {
return hmac.digest('hex');
};
-module.exports.get_auth_header = function get_auth_header(signature, timestamp, api_key) {
- var header = ['Sentry sentry_signature='+signature];
+module.exports.get_auth_header = function get_auth_header(signature, timestamp, api_key, project_id) {
+ var header = ['Sentry sentry_version=2.0'];
+ header.push('sentry_signature='+signature);
header.push('sentry_timestamp='+timestamp);
header.push('sentry_client=raven-node/0.1');
if(api_key) header.push('sentry_key='+api_key);
+ if(project_id) header.push('project_id='+project_id);
return header.join(', ');
};
@@ -35,7 +37,7 @@ module.exports.parseDSN = function parseDSN(dsn) {
var path = parsed.path.substr(1)
, index = path.lastIndexOf('/');
response.path = path.substr(0, index);
- response.project_id = path.substr(index+1);
+ response.project_id = ~~path.substr(index+1);
return response;
};
View
@@ -25,8 +25,8 @@ describe('raven.Client', function(){
it('should send a plain text message to Sentry server', function(done){
var scope = nock('https://app.getsentry.com')
.filteringRequestBody(/.*/, '*')
- .post('/269', '*')
- .reply(200, {});
+ .post('/api/store/', '*')
+ .reply(200, 'OK');
client.createFromText('Hey!');
setTimeout(function(){scope.done(); done();}, 2); // Really should not take more than 5ms to work.
View
@@ -27,7 +27,7 @@ describe('raven.utils', function() {
private_key: '296768aa91084e17b5ac02d3ad5bc7e7',
host: 'app.getsentry.com',
path: '',
- project_id: '269'
+ project_id: 269
};
dsn.should.eql(expected);
});
@@ -40,7 +40,7 @@ describe('raven.utils', function() {
private_key: '296768aa91084e17b5ac02d3ad5bc7e7',
host: 'mysentry.com',
path: 'some/other/path',
- project_id: '269'
+ project_id: 269
};
dsn.should.eql(expected);
});

0 comments on commit 546de7f

Please sign in to comment.