Home Reference Source
import Builder from 'libhoney/src/builder.js'
public class | source

Builder

Allows piecemeal creation of events.

Constructor Summary

Private Constructor
private

Member Summary

Public Members
public

The hostname for the Honeycomb API server to which to send events created through this builder.

public

The name of the Honeycomb dataset to which to send these events.

public

The rate at which to sample events.

public

The Honeycomb authentication token.

Private Members
private
private

_fields: *

private

Method Summary

Public Methods
public

add(data: Object | Map<string, any>): Builder

adds a group of field->values to the events created from this builder.

public

addDynamicField(name: string, fn: function(): any): Builder

adds a single field->dynamic value function, which is invoked to supply values when events are created from this builder.

public

addField(name: string, val: any): Builder

adds a single field->value mapping to the events created from this builder.

public

newBuilder(fields: Object | Map<string, any>, dyn_fields: Object | Map<string, any>): Builder

creates and returns a clone of this builder, merged with fields and dyn_fields passed as arguments.

public

creates and returns a new Event containing all fields/dyn_fields from this builder, that can be further fleshed out and sent on its own.

public

sendNow(data: Object | Map<string, any>)

creates and sends an event, including all builder fields/dyn_fields, as well as anything in the optional data parameter.

Private Constructors

private constructor() source

Public Members

public apiHost: string source

The hostname for the Honeycomb API server to which to send events created through this builder. default: https://api.honeycomb.io/

public dataset: string source

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.

public sampleRate: number source

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.

public writeKey: string source

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

Private Members

private _dyn_fields: * source

private _fields: * source

private _libhoney: * source

Public Methods

public add(data: Object | Map<string, any>): Builder source

adds a group of field->values to the events created from this builder.

Params:

NameTypeAttributeDescription
data Object | Map<string, any>

field->value mapping.

Return:

Builder

this Builder instance.

Example:

using an object
  var honey = new libhoney();
  var builder = honey.newBuilder();
  builder.add ({
    component: "web",
    depth: 200
  });
using an ES2015 map
  let map = new Map();
  map.set("component", "web");
  map.set("depth", 200);
  builder.add (map);

public addDynamicField(name: string, fn: function(): any): Builder source

adds a single field->dynamic value function, which is invoked to supply values when events are created from this builder.

Params:

NameTypeAttributeDescription
name string

the name of the field to add to events.

fn function(): any

the function called to generate the value for this field.

Return:

Builder

this Builder instance.

Example:

  builder.addDynamicField("process_heapUsed", () => process.memoryUsage().heapUsed);

public addField(name: string, val: any): Builder source

adds a single field->value mapping to the events created from this builder.

Params:

NameTypeAttributeDescription
name string
val any

Return:

Builder

this Builder instance.

Example:

  builder.addField("component", "web");

public newBuilder(fields: Object | Map<string, any>, dyn_fields: Object | Map<string, any>): Builder source

creates and returns a clone of this builder, merged with fields and dyn_fields passed as arguments.

Params:

NameTypeAttributeDescription
fields Object | Map<string, any>

a field->value mapping to merge into the new builder.

dyn_fields Object | Map<string, any>

a field->dynamic function mapping to merge into the new builder.

Return:

Builder

a Builder instance

Example:

no additional fields/dyn_field
  let anotherBuilder = builder.newBuilder();
additional fields/dyn_field
  let anotherBuilder = builder.newBuilder({ requestId },
                                          {
                                            process_heapUsed: () => process.memoryUsage().heapUsed
                                          });

public newEvent(): Event source

creates and returns a new Event containing all fields/dyn_fields from this builder, that can be further fleshed out and sent on its own.

Return:

Event

an Event instance

Example:

adding data at send-time
  let ev = builder.newEvent();
  ev.addField("additionalField", value);
  ev.send();

public sendNow(data: Object | Map<string, any>) source

creates and sends an event, including all builder fields/dyn_fields, as well as anything in the optional data parameter.

Params:

NameTypeAttributeDescription
data Object | Map<string, any>
  • optional

field->value mapping to add to the event sent.

Example:

empty sendNow
  builder.sendNow(); // sends just the data that has been added via add/addField/addDynamicField.
adding data at send-time
  builder.sendNow({
    additionalField: value
  });