Comparing version 0.1.1 to 0.2.0
@@ -11,2 +11,4 @@ var HTTP_STATUS_CODES = require('http').STATUS_CODES; | ||
var traverse = require('traverse'); | ||
var hashish = require('hashish'); | ||
var querystring = require('querystring'); | ||
@@ -77,14 +79,4 @@ module.exports = Airbrake; | ||
var self = this; | ||
var callback = function(err) { | ||
if (cb) { | ||
cb.apply(self, arguments); | ||
return; | ||
} | ||
var callback = this._callback(cb); | ||
if (err) { | ||
self.emit('error', err); | ||
} | ||
}; | ||
request(options, function(err, res, body) { | ||
@@ -112,2 +104,16 @@ if (err) { | ||
Airbrake.prototype._callback = function(cb) { | ||
var self = this; | ||
return function(err) { | ||
if (cb) { | ||
cb.apply(self, arguments); | ||
return; | ||
} | ||
if (err) { | ||
self.emit('error', err); | ||
} | ||
}; | ||
}; | ||
Airbrake.prototype.url = function(path) { | ||
@@ -292,1 +298,56 @@ return this.protocol + '://' + this.serviceHost + path; | ||
}; | ||
Airbrake.prototype.trackDeployment = function(params, cb) { | ||
if (typeof params === 'function') { | ||
cb = params; | ||
params = {}; | ||
} | ||
params = hashish.merge({ | ||
key: this.key, | ||
env: this.env, | ||
user: process.env.USER, | ||
rev: '', | ||
repo: '', | ||
}, params); | ||
var body = this.deploymentPostData(params); | ||
var options = { | ||
method: 'POST', | ||
url: this.url('/deploys.txt'), | ||
body: body, | ||
timeout: this.timeout, | ||
headers: { | ||
'Content-Length': body.length, | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
}; | ||
var callback = this._callback(cb); | ||
request(options, function(err, res, body) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (res.statusCode >= 300) { | ||
var status = HTTP_STATUS_CODES[res.statusCode]; | ||
return callback(new Error( | ||
'Deployment failed: ' + res.statusCode + ' ' + status + ': ' + body | ||
)); | ||
} | ||
callback(null, params); | ||
}); | ||
}; | ||
Airbrake.prototype.deploymentPostData = function(params) { | ||
return querystring.stringify({ | ||
'api_key': params.key, | ||
'deploy[rails_env]': params.env, | ||
'deploy[local_username]': params.user, | ||
'deploy[scm_revision]': params.rev, | ||
'deploy[scm_repository]': params.repo, | ||
}); | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"description": "Node.js client for airbrakeapp.com, formerly known as hoptoadapp.com.", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/felixge/node-airbrake", | ||
@@ -20,3 +20,4 @@ "repository": { | ||
"stack-trace": "0.0.5", | ||
"traverse": "0.4.4" | ||
"traverse": "0.4.4", | ||
"hashish": "0.0.4" | ||
}, | ||
@@ -23,0 +24,0 @@ "devDependencies": { |
@@ -17,6 +17,6 @@ # airbrake | ||
The common use case for this module is to catch all `'uncaughtException'` | ||
events on the `process` object and send them to airbreak: | ||
events on the `process` object and send them to airbrake: | ||
``` javascript | ||
var airbreak = require('airbrake').createClient("your api key"); | ||
var airbrake = require('airbrake').createClient("your api key"); | ||
airbrake.handleExceptions(); | ||
@@ -28,9 +28,9 @@ | ||
Please note that the above will re-throw the exception after it has been | ||
successfully delivered to airbreak, caushing your process to exit with status 1. | ||
successfully delivered to airbrake, caushing your process to exit with status 1. | ||
If you want more control over the delivery of your errors, you can also | ||
manually submit errors to airbreak. | ||
manually submit errors to airbrake. | ||
``` javascript | ||
var airbreak = require('airbrake').createClient("your api key"); | ||
var airbrake = require('airbrake').createClient("your api key"); | ||
var err = new Error('Something went terribly wrong'); | ||
@@ -40,3 +40,3 @@ airbrake.notify(err, function(err, url) { | ||
// Error has been delivered, url links to the error in airbreak | ||
// Error has been delivered, url links to the error in airbrake | ||
}); | ||
@@ -79,6 +79,6 @@ ``` | ||
* **request.session:** (`err.session` object if set) | ||
* **server-environment.project-root:** (`airbreak.projectRoot` string if set) | ||
* **server-environment.environment-name:** (`airbreak.env` string) | ||
* **server-environment.app-version:** (`airbreak.appVersion string if set) | ||
* **server-environment.hostname:** (`airbreak.hostname` string if set) | ||
* **server-environment.project-root:** (`airbrake.projectRoot` string if set) | ||
* **server-environment.environment-name:** (`airbrake.env` string) | ||
* **server-environment.app-version:** (`airbrake.appVersion string if set) | ||
* **server-environment.hostname:** (`airbrake.hostname` string if set) | ||
@@ -89,3 +89,3 @@ You can add additional context information by modifying the error properties | ||
``` javascript | ||
var airbreak = require('airbrake').createClient("your api key"); | ||
var airbrake = require('airbrake').createClient("your api key"); | ||
var http = require('http'); | ||
@@ -128,2 +128,27 @@ | ||
## Tracking deployments | ||
This client supports airbrake's [deployment tracking][]: | ||
``` javascript | ||
var airbrake = require('airbrake').createClient("your api key"); | ||
var deployment = { | ||
rev: '98103a8fa850d5eaf3666e419d8a0a93e535b1b2', | ||
repo: 'git@github.com:felixge/node-airbrake.git', | ||
}; | ||
airbrake.trackDeployment(deployment, function(err, params) { | ||
if (err) { | ||
throw err; | ||
} | ||
console.log('Tracked deployment of %s to %s', params.rev, params.env); | ||
}); | ||
``` | ||
Check out the `airbrake.trackDeployment()` API docs below for a list of all | ||
options. | ||
[deployment tracking]: http://help.airbrakeapp.com/kb/api-2/deploy-tracking | ||
## API | ||
@@ -139,3 +164,3 @@ | ||
### airbrake.env = process.env.NODE_ENV || 'development'; | ||
### airbrake.env = process.env.NODE_ENV || 'development' | ||
@@ -183,2 +208,12 @@ The name of the server environment this is running in. | ||
### airbrake.trackDeployment([params, [cb]]) | ||
Notifies airbrake about a deployment. `params` is an object with the following | ||
options: | ||
* `env:` The environment being deployed, defaults to `airbrake.env`. | ||
* `user:` The user doing the deployment, defaults to `process.env.USER`. | ||
* `repo:` The github url of this repository. Defaults to `''`. | ||
* `rev:` The revision of this deployment. Defaults to `''`. | ||
## Alternative modules | ||
@@ -191,8 +226,16 @@ | ||
## Todo | ||
## Contribute | ||
* Implement `airbrake.deployment()` | ||
Besides bug fixes, I'd be happy to accept patches for: | ||
* Automatically parsing `repo` and `rev` from the local git repository when | ||
calling `airbrake.trackDeployment()`. This can be done via `exec()`, but must | ||
not be done when specifying `repo` / `rev` by hand, or if they are set to | ||
`false`. | ||
If you have other feature ideas, please open an issue first, so we can discuss | ||
it. | ||
## License | ||
airbrake is licensed under the MIT license. |
var path = require('path'); | ||
var hashish = require('hashish'); | ||
// An account on the free plan specifically for testing this module. | ||
exports.key = 'eee7284b1d06c3d9e7adf9936dcd867e'; | ||
exports.env = 'test'; | ||
// Use custom config if available instead | ||
try { | ||
hashish.update(exports, require('./config')); | ||
} catch (e) {} | ||
exports.port = 8424; | ||
@@ -8,0 +13,0 @@ |
var common = require('../common'); | ||
var airbrake = require(common.dir.root).createClient(common.key, common.env) | ||
var airbrake = require(common.dir.root).createClient(common.key); | ||
var assert = require('assert'); | ||
@@ -4,0 +4,0 @@ var http = require('http'); |
var common = require('../common'); | ||
var airbrake = require(common.dir.root).createClient(common.key, common.env) | ||
var airbrake = require(common.dir.root).createClient(common.key); | ||
var assert = require('assert'); | ||
@@ -4,0 +4,0 @@ var sinon = require('sinon'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 3 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
1414161
36
521
233
5
14
13
+ Addedhashish@0.0.4
+ Addedhashish@0.0.4(transitive)