Comparing version 0.6.5 to 0.6.6
@@ -53,2 +53,8 @@ (function(root, factory) { | ||
// }); | ||
// | ||
// Supported options: | ||
// * `debug`: This logs messages to the console. | ||
// * `newrelic`: This option can be set as an instance of the newrelic agent. | ||
// RPC requests received by this client will be wrapped in a newrelic | ||
// transaction named after the group. | ||
HelpEsb.Client = function(uri, options) { | ||
@@ -64,3 +70,3 @@ // Extend EventEmitter to handle events. | ||
this._login = null; | ||
this._options = _.extend({debug: false}, options); | ||
this._options = _.extend({debug: false, newrelic: null}, options); | ||
@@ -178,4 +184,5 @@ this.mb = new HelpEsb.MessageBuilder(this); | ||
HelpEsb.Client.prototype.rpcReceive = function(group, cb) { | ||
var newrelic = this._options.newrelic; | ||
this.subscribe(group); | ||
this.on('group.' + group, function(message) { | ||
var messageHandler = function(message) { | ||
var meta = { | ||
@@ -208,3 +215,3 @@ type: 'sendMessage', | ||
Promise.try(cb.bind({}, message)).then(function(message) { | ||
var execute = Promise.try(cb.bind({}, message)).then(function(message) { | ||
return sendToAll( | ||
@@ -215,9 +222,43 @@ this.mb.success( | ||
); | ||
}.bind(this)).catch(function(error) { | ||
var reason = error instanceof Error ? error.toString() : error; | ||
}.bind(this)); | ||
var errorHandler = function(error) { | ||
var reason = _.isError(error) ? error.toString() : error; | ||
var errorMeta = _.extend({reason: reason}, meta); | ||
if (newrelic !== null) { | ||
newrelic.noticeError( | ||
_.isError(error) ? error : ('' + error), | ||
message.toJSON() | ||
); | ||
} | ||
return sendToAll(this.mb.failure({meta: errorMeta})); | ||
}.bind(this)); | ||
}.bind(this)); | ||
}.bind(this); | ||
if (newrelic !== null) { | ||
errorHandler = newrelic.agent.tracer.bindFunction( | ||
errorHandler, | ||
newrelic.agent.tracer.segment | ||
); | ||
} | ||
execute = execute.catch(errorHandler); | ||
if (newrelic !== null) { | ||
execute.finally(newrelic.agent.tracer.bindFunction( | ||
newrelic.endTransaction.bind(newrelic), | ||
newrelic.agent.tracer.segment | ||
)); | ||
} | ||
}.bind(this); | ||
if (newrelic !== null) { | ||
messageHandler = newrelic.createBackgroundTransaction( | ||
group, | ||
messageHandler | ||
); | ||
} | ||
this.on('group.' + group, messageHandler); | ||
}; | ||
@@ -224,0 +265,0 @@ |
{ | ||
"name": "help-esb", | ||
"version": "0.6.5", | ||
"version": "0.6.6", | ||
"description": "A client for the Help.com team's ESB.", | ||
@@ -5,0 +5,0 @@ "main": "help-esb.js", |
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
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
31614
591