libhoney
Advanced tools
Comparing version 1.0.0-beta.3 to 1.0.0-beta.4
{ | ||
"name": "libhoney", | ||
"version": "1.0.0-beta.3", | ||
"version": "1.0.0-beta.4", | ||
"description": "Javascript library for sending data to Honeycomb", | ||
@@ -5,0 +5,0 @@ "bugs": "https://github.com/honeycombio/libhoney-js/issues", |
@@ -48,2 +48,33 @@ 'use strict'; | ||
/** | ||
* The hostname for the Honeycomb API server to which to send events created through this | ||
* builder. default: https://api.honeycomb.io/ | ||
* | ||
* @type {string} | ||
*/ | ||
this.apiHost = ""; | ||
/** | ||
* The Honeycomb authentication token. If it is set on a libhoney instance it will be used as the | ||
* default write key for all events. If absent, it must be explicitly set on a Builder or | ||
* Event. Find your team write key at https://ui.honeycomb.io/account | ||
* | ||
* @type {string} | ||
*/ | ||
this.writeKey = ""; | ||
/** | ||
* The name of the Honeycomb dataset to which to send these events. If it is specified during | ||
* libhoney initialization, it will be used as the default dataset for all events. If absent, | ||
* dataset must be explicitly set on a builder or event. | ||
* | ||
* @type {string} | ||
*/ | ||
this.dataset = ""; | ||
/** | ||
* The rate at which to sample events. Default is 1, meaning no sampling. If you want to send one | ||
* event out of every 250 times send() is called, you would specify 250 here. | ||
* | ||
* @type {number} | ||
*/ | ||
this.sampleRate = 1; | ||
(0, _foreach2.default)(fields, function (v, k) { | ||
@@ -205,3 +236,2 @@ return _this.addField(k, v); | ||
exports.default = Builder; | ||
; | ||
exports.default = Builder; |
@@ -43,2 +43,29 @@ "use strict"; | ||
/** | ||
* The hostname for the Honeycomb API server to which to send this event. default: | ||
* https://api.honeycomb.io/ | ||
* | ||
* @type {string} | ||
*/ | ||
this.apiHost = ""; | ||
/** | ||
* The Honeycomb authentication token for this event. Find your team write key at | ||
* https://ui.honeycomb.io/account | ||
* | ||
* @type {string} | ||
*/ | ||
this.writeKey = ""; | ||
/** | ||
* The name of the Honeycomb dataset to which to send this event. | ||
* | ||
* @type {string} | ||
*/ | ||
this.dataset = ""; | ||
/** | ||
* The rate at which to sample this event. | ||
* | ||
* @type {number} | ||
*/ | ||
this.sampleRate = 1; | ||
(0, _foreach2.default)(fields, function (v, k) { | ||
@@ -140,3 +167,2 @@ return _this.addField(k, v); | ||
exports.default = Event; | ||
; | ||
exports.default = Event; |
@@ -26,10 +26,2 @@ 'use strict'; | ||
var _event = require('./event'); | ||
var _event2 = _interopRequireDefault(_event); | ||
var _foreach = require('./foreach'); | ||
var _foreach2 = _interopRequireDefault(_foreach); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -55,4 +47,11 @@ | ||
// batch triggers | ||
batchSizeTrigger: 100, // we send a batch to the api when we have this many outstanding events | ||
batchTimeTrigger: 100 // ... or after this many ms has passed. | ||
batchSizeTrigger: 50, // we send a batch to the api when we have this many outstanding events | ||
batchTimeTrigger: 100, // ... or after this many ms has passed. | ||
// batches are sent serially (one event at a time), so we allow multiple concurrent batches | ||
// to increase parallelism while sending. | ||
maxConcurrentBatches: 10, | ||
// the maximum number of pending events we allow in our queue before they get batched | ||
pendingWorkCapacity: 10000 | ||
}); | ||
@@ -91,2 +90,10 @@ | ||
/** | ||
* The hostname for the Honeycomb API server to which to send events created through this libhoney | ||
* instance. default: https://api.honeycomb.io/ | ||
* | ||
* @type {string} | ||
*/ | ||
_createClass(Libhoney, [{ | ||
@@ -293,6 +300,22 @@ key: 'sendEvent', | ||
this._builder.apiHost = v; | ||
}, | ||
} | ||
/** | ||
* The hostname for the Honeycomb API server to which to send events created through this libhoney | ||
* instance. default: https://api.honeycomb.io/ | ||
* | ||
* @type {string} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._builder.apiHost; | ||
} | ||
/** | ||
* The Honeycomb authentication token. If it is set on a libhoney instance it will be used as the | ||
* default write key for all events. If absent, it must be explicitly set on a Builder or | ||
* Event. Find your team write key at https://ui.honeycomb.io/account | ||
* | ||
* @type {string} | ||
*/ | ||
}, { | ||
@@ -302,6 +325,23 @@ key: 'writeKey', | ||
this._builder.writeKey = v; | ||
}, | ||
} | ||
/** | ||
* The Honeycomb authentication token. If it is set on a libhoney instance it will be used as the | ||
* default write key for all events. If absent, it must be explicitly set on a Builder or | ||
* Event. Find your team write key at https://ui.honeycomb.io/account | ||
* | ||
* @type {string} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._builder.writeKey; | ||
} | ||
/** | ||
* The name of the Honeycomb dataset to which to send events through this libhoney instance. If | ||
* it is specified during libhoney initialization, it will be used as the default dataset for all | ||
* events. If absent, dataset must be explicitly set on a builder or event. | ||
* | ||
* @type {string} | ||
*/ | ||
}, { | ||
@@ -311,6 +351,22 @@ key: 'dataset', | ||
this._builder.dataset = v; | ||
}, | ||
} | ||
/** | ||
* The name of the Honeycomb dataset to which to send these events through this libhoney instance. | ||
* If it is specified during libhoney initialization, it will be used as the default dataset for | ||
* all events. If absent, dataset must be explicitly set on a builder or event. | ||
* | ||
* @type {string} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._builder.dataset; | ||
} | ||
/** | ||
* The rate at which to sample events. Default is 1, meaning no sampling. If you want to send one | ||
* event out of every 250 times send() is called, you would specify 250 here. | ||
* | ||
* @type {number} | ||
*/ | ||
}, { | ||
@@ -320,3 +376,10 @@ key: 'sampleRate', | ||
this._builder.sampleRate = v; | ||
}, | ||
} | ||
/** | ||
* The rate at which to sample events. Default is 1, meaning no sampling. If you want to send one | ||
* event out of every 250 times send() is called, you would specify 250 here. | ||
* | ||
* @type {number} | ||
*/ | ||
, | ||
get: function get() { | ||
@@ -323,0 +386,0 @@ return this._builder.sampleRate; |
@@ -21,2 +21,4 @@ 'use strict'; | ||
/* global require, window, global */ | ||
/** | ||
@@ -28,10 +30,26 @@ * @module | ||
var libhoney_js_version = "1.0.0-beta.3"; | ||
var userAgent = "libhoney-js/1.0.0-beta.4"; | ||
// default triggers for sending a batch: | ||
var batchSizeTrigger = 100; // either when the eventQueue is > this length | ||
var _global = typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : undefined; | ||
// how many events to collect in a batch | ||
var batchSizeTrigger = 50; // either when the eventQueue is > this length | ||
var batchTimeTrigger = 100; // or it's been more than this many ms since the first push | ||
// how many batches to maintain in parallel | ||
var maxConcurrentBatches = 10; | ||
// how many events to queue up for busy batches before we start dropping | ||
var pendingWorkCapacity = 10000; | ||
var emptyResponseCallback = function emptyResponseCallback() {}; | ||
var eachPromise = function eachPromise(arr, iteratorFn) { | ||
return arr.reduce(function (p, item) { | ||
return p.then(function () { | ||
return iteratorFn(item); | ||
}); | ||
}, Promise.resolve()); | ||
}; | ||
/** | ||
@@ -48,4 +66,7 @@ * @private | ||
this._batchTimeTrigger = batchTimeTrigger; | ||
this._maxConcurrentBatches = maxConcurrentBatches; | ||
this._pendingWorkCapacity = pendingWorkCapacity; | ||
this._sendTimeoutId = -1; | ||
this._eventQueue = []; | ||
this._batchCount = 0; | ||
// Included for testing; to stub out randomness and verify that an event | ||
@@ -65,2 +86,8 @@ // was dropped. | ||
} | ||
if (typeof options.maxConcurrentBatches == "number") { | ||
this._maxConcurrentBatches = options.maxConcurrentBatches; | ||
} | ||
if (typeof options.pendingWorkCapacity == "number") { | ||
this._pendingWorkCapacity = options.pendingWorkCapacity; | ||
} | ||
} | ||
@@ -89,35 +116,39 @@ | ||
if (this._batchCount == maxConcurrentBatches) { | ||
// don't start up another concurrent batch. the next timeout/sendEvent or batch completion | ||
// will cause us to send another | ||
return; | ||
} | ||
this._clearSendTimeout(); | ||
this._batchCount++; | ||
var batch = this._eventQueue.splice(0, this._batchSizeTrigger); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
eachPromise(batch, function (ev) { | ||
var url = (0, _urljoin2.default)(ev.apiHost, "/1/events", ev.dataset); | ||
var req = superagent.post(url); | ||
try { | ||
for (var _iterator = batch[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var ev = _step.value; | ||
return new Promise(function (resolve) { | ||
req.set('X-Hny-Team', ev.writeKey).set('X-Hny-Samplerate', ev.sampleRate).set('X-Hny-Event-Time', ev.timestamp.toISOString()).set('User-Agent', userAgent).type("json").send(ev.postData).end(function (err, res) { | ||
// call a callback here (in our init options) so it can be used both in the node, browser, and worker contexts. | ||
_this._responseCallback({ err: err, res: res }); | ||
var url = (0, _urljoin2.default)(ev.apiHost, "/1/events", ev.dataset); | ||
var req = superagent.post(url); | ||
req.set('X-Hny-Team', ev.writeKey).set('X-Hny-Samplerate', ev.sampleRate).set('X-Hny-Event-Time', ev.timestamp.toISOString()).set('User-Agent', 'libhoney-js/' + libhoney_js_version).type("json").send(ev.postData).end(function (err, res) { | ||
// call a callback here (in our init options) so it can be used both in the node, browser, and worker contexts. | ||
_this._responseCallback({ stuff: "goes here" }); // XXX(toshok) | ||
// we resolve unconditionally to continue the iteration in eachSeries. errors will cause | ||
// the event to be re-enqueued/dropped. | ||
resolve(); | ||
}); | ||
}); | ||
}).then(function () { | ||
_this._batch--; | ||
if (_this._eventQueue.length > _this._batchSizeTrigger) { | ||
_this._sendBatch(); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
}).catch(function () { | ||
_this._batch--; | ||
if (_this._eventQueue.length > _this._batchSizeTrigger) { | ||
_this._sendBatch(); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -127,2 +158,5 @@ }, { | ||
value: function _shouldSendEvent(ev) { | ||
if (this._eventQueue.length >= this._pendingWorkCapacity) { | ||
return false; | ||
} | ||
var sampleRate = ev.sampleRate; | ||
@@ -141,3 +175,3 @@ | ||
if (this._sendTimeoutId === -1) { | ||
this._sendTimeoutId = setTimeout(function () { | ||
this._sendTimeoutId = _global.setTimeout(function () { | ||
return _this2._sendBatch(); | ||
@@ -151,3 +185,3 @@ }, this._batchTimeTrigger); | ||
if (this._sendTimeoutId !== -1) { | ||
clearTimeout(this._sendTimeoutId); | ||
_global.clearTimeout(this._sendTimeoutId); | ||
this._sendTimeoutId = -1; | ||
@@ -154,0 +188,0 @@ } |
{ | ||
"name": "libhoney", | ||
"version": "1.0.0-beta.3", | ||
"version": "1.0.0-beta.4", | ||
"description": "Javascript library for sending data to Honeycomb", | ||
@@ -5,0 +5,0 @@ "bugs": "https://github.com/honeycombio/libhoney-js/issues", |
54656
1025