Comparing version 1.0.0-beta.4 to 1.0.0-beta.5
{ | ||
"name": "libhoney", | ||
"version": "1.0.0-beta.4", | ||
"version": "1.0.0-beta.5", | ||
"description": "Javascript library for sending data to Honeycomb", | ||
@@ -5,0 +5,0 @@ "bugs": "https://github.com/honeycombio/libhoney-js/issues", |
@@ -7,2 +7,10 @@ var libhoney = require('libhoney').default; | ||
return function(req, res, next) { | ||
const responseCallback = (queue) => { | ||
var responses = queue.splice(0, queue.length); | ||
for (var i = 0; i < responses.length; i ++) { | ||
console.log("response status =", responses[i].status_code); | ||
} | ||
}; | ||
honey.once("response", responseCallback); | ||
honey.sendNow({ | ||
@@ -9,0 +17,0 @@ app: req.app, |
@@ -27,2 +27,2 @@ "use strict"; | ||
} | ||
}; | ||
} |
@@ -9,11 +9,4 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // Copyright 2016 Hound Technology, Inc. All rights reserved. | ||
// Use of this source code is governed by the Apache License 2.0 | ||
// license that can be found in the LICENSE file. | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
/** | ||
* @module | ||
*/ | ||
var _transmission = require('./transmission'); | ||
@@ -27,2 +20,4 @@ | ||
var _events = require('events'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -32,2 +27,13 @@ | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Copyright 2016 Hound Technology, Inc. All rights reserved. | ||
// Use of this source code is governed by the Apache License 2.0 | ||
// license that can be found in the LICENSE file. | ||
/** | ||
* @module | ||
*/ | ||
var defaults = Object.freeze({ | ||
@@ -41,5 +47,2 @@ // host to send data to | ||
// response queue. just an plain js array that transmission will append to | ||
responseQueue: [], | ||
// transmission constructor, or a string "worker"/"base" to pick one of our builtin versions. | ||
@@ -58,3 +61,6 @@ // we fall back to the base impl if worker or a custom implementation throws on init. | ||
// the maximum number of pending events we allow in our queue before they get batched | ||
pendingWorkCapacity: 10000 | ||
pendingWorkCapacity: 10000, | ||
// the maximum number of responses we enqueue before we drop. | ||
maxResponseQueueSize: 1000 | ||
}); | ||
@@ -67,3 +73,5 @@ | ||
var Libhoney = function () { | ||
var Libhoney = function (_EventEmitter) { | ||
_inherits(Libhoney, _EventEmitter); | ||
/** | ||
@@ -83,22 +91,36 @@ * constructs a libhoney context. | ||
this._options = Object.assign({}, defaults, opts); | ||
this._transmission = getAndInitTransmission(this._options.transmission, this._options); | ||
this._usable = this._transmission != null; | ||
this._builder = new _builder2.default(this); | ||
var _this = _possibleConstructorReturn(this, (Libhoney.__proto__ || Object.getPrototypeOf(Libhoney)).call(this)); | ||
this._builder.apiHost = this._options.apiHost; | ||
this._builder.writeKey = this._options.writeKey; | ||
this._builder.dataset = this._options.dataset; | ||
this._builder.sampleRate = this._options.sampleRate; | ||
_this._options = Object.assign({ responseCallback: _this._responseCallback.bind(_this) }, defaults, opts); | ||
_this._transmission = getAndInitTransmission(_this._options.transmission, _this._options); | ||
_this._usable = _this._transmission != null; | ||
_this._builder = new _builder2.default(_this); | ||
_this._builder.apiHost = _this._options.apiHost; | ||
_this._builder.writeKey = _this._options.writeKey; | ||
_this._builder.dataset = _this._options.dataset; | ||
_this._builder.sampleRate = _this._options.sampleRate; | ||
_this._responseQueue = []; | ||
return _this; | ||
} | ||
/** | ||
* 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, [{ | ||
key: '_responseCallback', | ||
value: function _responseCallback(response) { | ||
var queue = this._responseQueue; | ||
if (queue.length < this._options.maxResponseQueueSize) { | ||
queue.push(response); | ||
} | ||
this.emit("response", queue); | ||
} | ||
/** | ||
* 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, [{ | ||
}, { | ||
key: 'sendEvent', | ||
@@ -167,3 +189,4 @@ | ||
dataset: dataset, | ||
sampleRate: sampleRate | ||
sampleRate: sampleRate, | ||
metadata: event.metadata | ||
}); | ||
@@ -173,25 +196,2 @@ } | ||
/** | ||
* a shortcut to create an event, add data, and send the event immediately. | ||
* @param {Object|Map<string, any>} data field->value mapping. | ||
* @example <caption>using an object</caption> | ||
* honey.sendNow ({ | ||
* responseTime_ms: 100, | ||
* httpStatusCode: 200 | ||
* }); | ||
* @example <caption>using an ES2015 map</caption> | ||
* let map = new Map(); | ||
* map.set("responseTime_ms", 100); | ||
* map.set("httpStatusCode", 200); | ||
* honey.sendNow (map); | ||
*/ | ||
}, { | ||
key: 'sendNow', | ||
value: function sendNow(data) { | ||
var ev = this.newEvent(); | ||
ev.add(data); | ||
this.sendEvent(ev); | ||
} | ||
/** | ||
* adds a group of field->values to the global Builder. | ||
@@ -253,9 +253,13 @@ * @param {Object|Map<string, any>} data field->value mapping. | ||
* creates and sends an event, including all global builder fields/dyn_fields, as well as anything in the optional data parameter. | ||
* @param {Object|Map<string, any>} [data] field->value mapping to add to the event sent. | ||
* @example <caption>empty sendNow</caption> | ||
* honey.sendNow(); // sends just the data that has been added via add/addField/addDynamicField. | ||
* @example <caption>adding data at send-time</caption> | ||
* honey.sendNow({ | ||
* additionalField: value | ||
* @param {Object|Map<string, any>} data field->value mapping. | ||
* @example <caption>using an object</caption> | ||
* honey.sendNow ({ | ||
* responseTime_ms: 100, | ||
* httpStatusCode: 200 | ||
* }); | ||
* @example <caption>using an ES2015 map</caption> | ||
* let map = new Map(); | ||
* map.set("responseTime_ms", 100); | ||
* map.set("httpStatusCode", 200); | ||
* honey.sendNow (map); | ||
*/ | ||
@@ -394,3 +398,3 @@ | ||
return Libhoney; | ||
}(); | ||
}(_events.EventEmitter); | ||
@@ -397,0 +401,0 @@ exports.default = Libhoney; |
@@ -29,3 +29,3 @@ 'use strict'; | ||
var userAgent = "libhoney-js/1.0.0-beta.4"; | ||
var userAgent = "libhoney-js/1.0.0-beta.5"; | ||
@@ -125,2 +125,15 @@ var _global = typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : undefined; | ||
var finishBatch = function finishBatch() { | ||
_this._batchCount--; | ||
var queueLength = _this._eventQueue.length; | ||
if (queueLength > 0) { | ||
if (queueLength > _this._batchSizeTrigger) { | ||
_this._sendBatch(); | ||
} else { | ||
_this._ensureSendTimeout(); | ||
} | ||
} | ||
}; | ||
eachPromise(batch, function (ev) { | ||
@@ -131,5 +144,11 @@ var url = (0, _urljoin2.default)(ev.apiHost, "/1/events", ev.dataset); | ||
return new Promise(function (resolve) { | ||
var start = Date.now(); | ||
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 }); | ||
_this._responseCallback({ | ||
status_code: res ? res.status : err.status, | ||
duration: Date.now() - start, | ||
metadata: ev.metadata, | ||
error: err | ||
}); | ||
@@ -141,13 +160,3 @@ // we resolve unconditionally to continue the iteration in eachSeries. errors will cause | ||
}); | ||
}).then(function () { | ||
_this._batch--; | ||
if (_this._eventQueue.length > _this._batchSizeTrigger) { | ||
_this._sendBatch(); | ||
} | ||
}).catch(function () { | ||
_this._batch--; | ||
if (_this._eventQueue.length > _this._batchSizeTrigger) { | ||
_this._sendBatch(); | ||
} | ||
}); | ||
}).then(finishBatch).catch(finishBatch); | ||
} | ||
@@ -154,0 +163,0 @@ }, { |
{ | ||
"name": "libhoney", | ||
"version": "1.0.0-beta.4", | ||
"version": "1.0.0-beta.5", | ||
"description": "Javascript library for sending data to Honeycomb", | ||
@@ -5,0 +5,0 @@ "bugs": "https://github.com/honeycombio/libhoney-js/issues", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances 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
203642
91
3508
30
1