Comparing version 1.0.0-beta.6 to 1.0.0-beta.7
{ | ||
"name": "libhoney", | ||
"version": "1.0.0-beta.6", | ||
"version": "1.0.0-beta.7", | ||
"description": "Javascript library for sending data to Honeycomb", | ||
@@ -5,0 +5,0 @@ "bugs": "https://github.com/honeycombio/libhoney-js/issues", |
@@ -41,4 +41,4 @@ var libhoney = require('libhoney').default; | ||
builder.sendNow(); | ||
event.send(); | ||
}; | ||
}; |
@@ -95,9 +95,9 @@ 'use strict'; | ||
* builder.add ({ | ||
* responseTime_ms: 100, | ||
* httpStatusCode: 200 | ||
* component: "web", | ||
* depth: 200 | ||
* }); | ||
* @example <caption>using an ES2015 map</caption> | ||
* let map = new Map(); | ||
* map.set("responseTime_ms", 100); | ||
* map.set("httpStatusCode", 200); | ||
* map.set("component", "web"); | ||
* map.set("depth", 200); | ||
* builder.add (map); | ||
@@ -124,3 +124,3 @@ */ | ||
* @example | ||
* builder.addField("responseTime_ms", 100); | ||
* builder.addField("component", "web"); | ||
*/ | ||
@@ -127,0 +127,0 @@ |
@@ -90,3 +90,4 @@ "use strict"; | ||
* httpStatusCode: 200 | ||
* }); | ||
* }) | ||
* .send(); | ||
* @example <caption>using an ES2015 map</caption> | ||
@@ -98,2 +99,3 @@ * let map = new Map(); | ||
* event.add (map); | ||
* event.send(); | ||
*/ | ||
@@ -155,3 +157,3 @@ | ||
/** | ||
* sends this event to honeycomb | ||
* Sends this event to honeycomb, sampling if necessary. | ||
*/ | ||
@@ -164,2 +166,13 @@ | ||
} | ||
/** | ||
* Dispatch an event to be sent to Honeycomb. Assumes sampling has already happened, | ||
* and will send every event handed to it. | ||
*/ | ||
}, { | ||
key: "sendPresampled", | ||
value: function sendPresampled() { | ||
this._libhoney.sendPresampledEvent(this); | ||
} | ||
}]); | ||
@@ -166,0 +179,0 @@ |
@@ -59,3 +59,3 @@ 'use strict'; | ||
// the maximum number of responses we enqueue before we drop. | ||
// the maximum number of s we enqueue before we drop. | ||
maxResponseQueueSize: 1000 | ||
@@ -65,3 +65,3 @@ }); | ||
/** | ||
* Represents a honeycomb context. Each honeycomb context has | ||
* Represents a honeycomb context. Each honeycomb context has | ||
* @class | ||
@@ -134,2 +134,5 @@ */ | ||
* } | ||
* | ||
* Sampling is done based on the supplied sampleRate, so events passed to this method might not | ||
* actually be sent to Honeycomb. | ||
* @private | ||
@@ -179,2 +182,4 @@ */ | ||
var metadata = event.metadata; | ||
this._transmission.sendEvent({ | ||
@@ -187,3 +192,3 @@ timestamp: timestamp, | ||
sampleRate: sampleRate, | ||
metadata: event.metadata | ||
metadata: metadata | ||
}); | ||
@@ -193,2 +198,75 @@ } | ||
/** | ||
* sendPresampledEvent takes events of the following form: | ||
* | ||
* { | ||
* data: a JSON-serializable object, keys become colums in Honeycomb | ||
* timestamp [optional]: time for this event, defaults to now() | ||
* writeKey [optional]: your team's write key. overrides the libhoney instance's value. | ||
* dataset [optional]: the data set name. overrides the libhoney instance's value. | ||
* sampleRate: the rate this event has already been sampled. | ||
* } | ||
* | ||
* Sampling is presumed to have already been done (at the supplied sampledRate), so all events passed to this method | ||
* are sent to Honeycomb. | ||
* @private | ||
*/ | ||
}, { | ||
key: 'sendPresampledEvent', | ||
value: function sendPresampledEvent(event) { | ||
if (!this._usable) return; | ||
var timestamp = event.timestamp || Date.now(); | ||
if (typeof timestamp === 'string' || typeof timestamp === 'number') timestamp = new Date(timestamp); | ||
if (_typeof(event.data) !== 'object' || event.data === null) { | ||
console.error(".data must be an object"); | ||
return; | ||
} | ||
var postData; | ||
try { | ||
postData = JSON.stringify(event.data); | ||
} catch (e) { | ||
console.error("error converting event data to JSON: " + e); | ||
return; | ||
} | ||
var apiHost = event.apiHost; | ||
if (typeof apiHost !== 'string' || apiHost === "") { | ||
console.error(".apiHost must be a non-empty string"); | ||
return; | ||
} | ||
var writeKey = event.writeKey; | ||
if (typeof writeKey !== 'string' || writeKey === "") { | ||
console.error(".writeKey must be a non-empty string"); | ||
return; | ||
} | ||
var dataset = event.dataset; | ||
if (typeof dataset !== 'string' || dataset === "") { | ||
console.error(".dataset must be a non-empty string"); | ||
return; | ||
} | ||
var sampleRate = event.sampleRate; | ||
if (typeof sampleRate !== 'number') { | ||
console.error(".sampleRate must be a number"); | ||
return; | ||
} | ||
var metadata = event.metadata; | ||
this._transmission.sendPresampledEvent({ | ||
timestamp: timestamp, | ||
apiHost: apiHost, | ||
postData: postData, | ||
writeKey: writeKey, | ||
dataset: dataset, | ||
sampleRate: sampleRate, | ||
metadata: metadata | ||
}); | ||
} | ||
/** | ||
* adds a group of field->values to the global Builder. | ||
@@ -199,9 +277,9 @@ * @param {Object|Map<string, any>} data field->value mapping. | ||
* honey.add ({ | ||
* responseTime_ms: 100, | ||
* httpStatusCode: 200 | ||
* buildID: "a6cc38a1", | ||
* env: "staging" | ||
* }); | ||
* @example <caption>using an ES2015 map</caption> | ||
* let map = new Map(); | ||
* map.set("responseTime_ms", 100); | ||
* map.set("httpStatusCode", 200); | ||
* map.set("build_id", "a6cc38a1"); | ||
* map.set("env", "staging"); | ||
* honey.add (map); | ||
@@ -223,3 +301,3 @@ */ | ||
* @example | ||
* honey.addField("responseTime_ms", 100); | ||
* honey.addField("build_id", "a6cc38a1"); | ||
*/ | ||
@@ -226,0 +304,0 @@ |
@@ -29,3 +29,3 @@ 'use strict'; | ||
var userAgent = "libhoney-js/1.0.0-beta.6"; | ||
var userAgent = "libhoney-js/1.0.0-beta.7"; | ||
@@ -70,6 +70,2 @@ var _global = typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : undefined; | ||
this._batchCount = 0; | ||
// Included for testing; to stub out randomness and verify that an event | ||
// was dropped. | ||
this._randomFn = Math.random; | ||
this._droppedCallback = emptyResponseCallback; | ||
@@ -91,5 +87,17 @@ if (typeof options.responseCallback == "function") { | ||
} | ||
// Included for testing; to stub out randomness and verify that an event | ||
// was dropped. | ||
this._randomFn = Math.random; | ||
} | ||
_createClass(Transmission, [{ | ||
key: '_droppedCallback', | ||
value: function _droppedCallback(ev, reason) { | ||
this._responseCallback({ | ||
metadata: ev.metadata, | ||
error: new Error(reason) | ||
}); | ||
} | ||
}, { | ||
key: 'sendEvent', | ||
@@ -99,6 +107,15 @@ value: function sendEvent(ev) { | ||
if (!this._shouldSendEvent(ev)) { | ||
this._droppedCallback(); | ||
this._droppedCallback(ev, "event dropped due to sampling"); | ||
return; | ||
} | ||
this.sendPresampledEvent(ev); | ||
} | ||
}, { | ||
key: 'sendPresampledEvent', | ||
value: function sendPresampledEvent(ev) { | ||
if (this._eventQueue.length >= this._pendingWorkCapacity) { | ||
this._droppedCallback(ev, "queue overflow"); | ||
return; | ||
} | ||
this._eventQueue.push(ev); | ||
@@ -166,5 +183,2 @@ if (this._eventQueue.length >= this._batchSizeTrigger) { | ||
value: function _shouldSendEvent(ev) { | ||
if (this._eventQueue.length >= this._pendingWorkCapacity) { | ||
return false; | ||
} | ||
var sampleRate = ev.sampleRate; | ||
@@ -171,0 +185,0 @@ |
{ | ||
"name": "libhoney", | ||
"version": "1.0.0-beta.6", | ||
"version": "1.0.0-beta.7", | ||
"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
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
206787
3599