Socket
Socket
Sign inDemoInstall

libhoney

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libhoney - npm Package Compare versions

Comparing version 1.0.0-beta.2 to 1.0.0-beta.3

8

docs/package.json
{
"name": "libhoney",
"version": "1.0.0-beta.2",
"version": "1.0.0-beta.3",
"description": "Javascript library for sending data to Honeycomb",

@@ -37,7 +37,9 @@ "bugs": "https://github.com/honeycombio/libhoney-js/issues",

"jsdoc": "^3.4.0",
"mocha": "^3.0.2"
"mocha": "^3.0.2",
"superagent-mocker": "^0.5.2"
},
"dependencies": {
"superagent": "^1.5.0"
"superagent": "^2.3.0",
"urljoin": "^0.1.5"
}
}

@@ -6,5 +6,5 @@ var express = require('express');

app.use(honey({
apiHost: process.env["HONEY_API_HOST"],
writeKey: process.env["HONEY_WRITE_KEY"],
dataset: process.env["HONEY_DATASET"],
dataset: "express-example-dynamic-fields",
sampleRate: 5 // log 1 out of every 5 events
}));

@@ -11,0 +11,0 @@

@@ -8,3 +8,11 @@ var libhoney = require('libhoney').default;

return function(req, res, next) {
var builder = honey.newBuilder({
// Attach dynamic fields to the global event builder in libhoney.
// Dynamic fields calculate their values at the time the event is created
// (the event.sendNow call below)
honey.addDynamicField('rss_after', () => process.memoryUsage().rss);
honey.addDynamicField('heapTotal_after', () => process.memoryUsage().heapTotal);
honey.addDynamicField('heapUsed_after', () => process.memoryUsage().heapUsed);
var event = honey.newEvent();
event.add({
app: req.app,

@@ -25,12 +33,7 @@ baseUrl: req.baseUrl,

// fields here give the values at the time newBuilder is called
// these fields capture values for memory usage at the time they're added
// to the newEvent
rss_before: process.memoryUsage().rss,
heapTotal_before: process.memoryUsage().heapTotal,
heapUsed_before: process.memoryUsage().heapUsed
}, {
// dynamic fields generate values at the time the event is created
// (the buidler.sendNow call below.)
rss_after: () => process.memoryUsage().rss,
heapTotal_after: () => process.memoryUsage().heapTotal,
heapUsed_after: () => process.memoryUsage().heapUsed
});

@@ -37,0 +40,0 @@

@@ -7,5 +7,4 @@ var express = require('express');

var honey = new libhoney({
apiHost: process.env["HONEY_API_HOST"],
writeKey: process.env["HONEY_WRITE_KEY"],
dataset: process.env["HONEY_DATASET"]
dataset: "express-example-response-time"
});

@@ -12,0 +11,0 @@

@@ -6,6 +6,4 @@ var express = require('express');

app.use(honey({
apiHost: process.env["HONEY_API_HOST"],
writeKey: process.env["HONEY_WRITE_KEY"],
dataset: process.env["HONEY_DATASET"],
sampleRate: 5 // log 1 out of every 5 events
dataset: "express-example",
}));

@@ -12,0 +10,0 @@

@@ -1,2 +0,2 @@

to build these examples:
To build these examples:

@@ -6,2 +6,2 @@ 1. `cd $example-dir`

3. `npm install`
4. `HONEY_WRITE_KEY=YOUR_WRITE_KEY HONEY_DATA_SET=YOUR_DATA_SET npm start`
4. `HONEY_WRITE_KEY=YOUR_WRITE_KEY npm start`

@@ -158,3 +158,8 @@ 'use strict';

value: function newEvent() {
return new _event2.default(this._libhoney, this._fields, this._dyn_fields);
var ev = new _event2.default(this._libhoney, this._fields, this._dyn_fields);
ev.apiHost = this.apiHost;
ev.writeKey = this.writeKey;
ev.dataset = this.dataset;
ev.sampleRate = this.sampleRate;
return ev;
}

@@ -188,2 +193,7 @@

b.apiHost = this.apiHost;
b.writeKey = this.writeKey;
b.dataset = this.dataset;
b.sampleRate = this.sampleRate;
return b;

@@ -190,0 +200,0 @@ }

@@ -38,3 +38,3 @@ 'use strict';

var defaults = {
var defaults = Object.freeze({
// host to send data to

@@ -57,3 +57,3 @@ apiHost: "https://api.honeycomb.io/",

batchTimeTrigger: 100 // ... or after this many ms has passed.
};
});

@@ -84,20 +84,25 @@ /**

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;
}
/**
* sendEvent 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 [optional]: cause us to send 1 out of sampleRate events. overrides the libhoney instance's value.
* }
* @private
*/
_createClass(Libhoney, [{
key: 'sendEvent',
_createClass(Libhoney, [{
key: 'sendEvent',
/**
* sendEvent 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 [optional]: cause us to send 1 out of sampleRate events. overrides the libhoney instance's value.
* }
* @private
*/
value: function sendEvent(event) {

@@ -121,21 +126,21 @@ if (!this._usable) return;

var apiHost = event.apiHost || this._options.apiHost;
if (typeof apiHost !== 'string') {
console.error(".apiHost must be a string");
var apiHost = event.apiHost;
if (typeof apiHost !== 'string' || apiHost === "") {
console.error(".apiHost must be a non-empty string");
return;
}
var writeKey = event.writeKey || this._options.writeKey;
if (typeof writeKey !== 'string') {
console.error(".writeKey must be a string");
var writeKey = event.writeKey;
if (typeof writeKey !== 'string' || writeKey === "") {
console.error(".writeKey must be a non-empty string");
return;
}
var dataset = event.dataset || this._options.dataset;
if (typeof dataset !== 'string') {
console.error(".dataset must be a string");
var dataset = event.dataset;
if (typeof dataset !== 'string' || dataset === "") {
console.error(".dataset must be a non-empty string");
return;
}
var sampleRate = event.sampleRate || this._options.sampleRate;
var sampleRate = event.sampleRate;
if (typeof sampleRate !== 'number') {

@@ -157,2 +162,25 @@ console.error(".sampleRate must be a number");

/**
* 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.

@@ -261,13 +289,36 @@ * @param {Object|Map<string, any>} data field->value mapping.

value: function newBuilder(fields, dyn_fields) {
var b = new _builder2.default(this, this._fields, this._dyn_fields);
(0, _foreach2.default)(fields, function (v, k) {
return b.addField(k, v);
});
(0, _foreach2.default)(dyn_fields, function (v, k) {
return b.addDynamicField(k, v);
});
return b;
return this._builder.newBuilder(fields, dyn_fields);
}
}, {
key: 'apiHost',
set: function set(v) {
this._builder.apiHost = v;
},
get: function get() {
return this._builder.apiHost;
}
}, {
key: 'writeKey',
set: function set(v) {
this._builder.writeKey = v;
},
get: function get() {
return this._builder.writeKey;
}
}, {
key: 'dataset',
set: function set(v) {
this._builder.dataset = v;
},
get: function get() {
return this._builder.dataset;
}
}, {
key: 'sampleRate',
set: function set(v) {
this._builder.sampleRate = v;
},
get: function get() {
return this._builder.sampleRate;
}
}]);

@@ -274,0 +325,0 @@

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -7,3 +7,13 @@ Object.defineProperty(exports, "__esModule", {

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.
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; }; }();
var _urljoin = require('urljoin');
var _urljoin2 = _interopRequireDefault(_urljoin);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// Copyright 2016 Hound Technology, Inc. All rights reserved.
// Use of this source code is governed by the Apache License 2.0

@@ -15,14 +25,7 @@ // license that can be found in the LICENSE file.

*/
var superagent = require('superagent');
var _superagent = require("superagent");
var libhoney_js_version = "1.0.0-beta.3";
var superagent = _interopRequireWildcard(_superagent);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var libhoney_js_version = "1.0.0-beta.2";
// default triggers for sending a batch:

@@ -64,3 +67,3 @@ var batchSizeTrigger = 100; // either when the eventQueue is > this length

_createClass(Transmission, [{
key: "sendEvent",
key: 'sendEvent',
value: function sendEvent(ev) {

@@ -81,3 +84,3 @@ // bail early if we aren't sampling this event

}, {
key: "_sendBatch",
key: '_sendBatch',
value: function _sendBatch() {

@@ -98,5 +101,5 @@ var _this = this;

var url = ev.apiHost + "/1/events/" + ev.dataset;
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) {
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.

@@ -122,3 +125,3 @@ _this._responseCallback({ stuff: "goes here" }); // XXX(toshok)

}, {
key: "_shouldSendEvent",
key: '_shouldSendEvent',
value: function _shouldSendEvent(ev) {

@@ -133,3 +136,3 @@ var sampleRate = ev.sampleRate;

}, {
key: "_ensureSendTimeout",
key: '_ensureSendTimeout',
value: function _ensureSendTimeout() {

@@ -145,3 +148,3 @@ var _this2 = this;

}, {
key: "_clearSendTimeout",
key: '_clearSendTimeout',
value: function _clearSendTimeout() {

@@ -148,0 +151,0 @@ if (this._sendTimeoutId !== -1) {

{
"name": "libhoney",
"version": "1.0.0-beta.2",
"version": "1.0.0-beta.3",
"description": "Javascript library for sending data to Honeycomb",

@@ -37,7 +37,9 @@ "bugs": "https://github.com/honeycombio/libhoney-js/issues",

"jsdoc": "^3.4.0",
"mocha": "^3.0.2"
"mocha": "^3.0.2",
"superagent-mocker": "^0.5.2"
},
"dependencies": {
"superagent": "^1.5.0"
"superagent": "^2.3.0",
"urljoin": "^0.1.5"
}
}

@@ -1,18 +0,13 @@

A JS library for sending data to Honeycomb (https://honeycomb.io)
=================================================================
# libhoney [![Build Status](https://travis-ci.org/honeycombio/libhoney-js.svg?branch=master)](https://travis-ci.org/honeycombio/libhoney-js)
[![Build Status](https://travis-ci.com/honeycombio/libhoney-js-private.svg?token=pycxQxHKSNdG7LiWg3Nt&branch=master)](https://travis-ci.com/honeycombio/libhoney-js-private)
A node module for interacting with [Honeycomb](https://honeycomb.io). (See here for more information about [using Honeycomb](https://honeycomb.io/intro/) and [its libraries](https://honeycomb.io/docs/send-data/sdks).)
## Summary
**NOT** for use in browser-side JavaScript applications. Write keys are your auth tokens for sending data to Honeycomb and should be kept secure -- they're not per-site keys. Don't leave yourself vulnerable to malicious users.
libhoney is written to ease the process of sending data to Honeycomb from within
your js server code.
## Installation
For an overview of how to use a honeycomb library, see our documentation at
https://honeycomb.io/docs/send-data/sdks/
```
npm install libhoney --save-dev
```
Do NOT use this in your browser-side JS. Honeycomb uses write keys as auth tokens for sending data,
and they are not per-site keys. If someone has your write key they can write whatever they want to
whatever dataset they want. Don't do this.
## Documentation

@@ -24,5 +19,23 @@

See the `examples/` directory for sample code demonstrating how to use events,
builders, fields, and dynamic fields.
Honeycomb can calculate all sorts of statistics, so send the values you care about and let us crunch the averages, percentiles, lower/upper bounds, cardinality -- whatever you want -- for you.
```js
var libhoney = require('libhoney').default;
var hny = new libhoney({
writeKey: "YOUR_WRITE_KEY",
dataset: "honeycomb-js-example"
});
hny.sendNow({
message: "Test Honeycomb event",
randomFloat: Math.random(),
hostname: os.hostname(),
favoriteColor: "chartreuse"
});
```
For more, see the [`examples/`](examples/) directory for sample code demonstrating how to use events,
builders, fields, and dynamic fields in an Express app.
## Contributions

@@ -35,2 +48,1 @@

All contributions will be released under the Apache License 2.0.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc