1.6.0 • Published 8 years ago
frau-http-telemetry v1.6.0
frau-http-telemetry 
Simple module to POST an object to an HTTP endpoint
npm i frau-http-telemetry --save
var Telemetry = require('frau-http-telemetry');
// Set endpoint
Telemetry.endpoint('http://db.com/logs');
// Set values for all messages
Telemetry.context('appName', 'exampleApp');
// Asynchronously POST message to http://db.com/logs
Telemetry.track('appLoad', {user: 'user1'});
// The payload below is what was sent by Telemetry.track
var sent = {
appName: 'exampleApp',
user: 'user1',
name: 'appLoad',
ts: 1459351569 // object creation time
};
// You can also POST anything you want
Telemetry.raw({data: 'this obj is sent without modification or context'});API
Telemetry.endpoint(endpoint)- Sets the endpoint for the global telemetry instance, overwriting the current endpoint.
Telemetry.context(key, value)- Sets a key-value pair to be sent on all calls to
Telemetry.track. Overwritten by
localContext.
- Sets a key-value pair to be sent on all calls to
Telemetry.track(name[, localContext])- POSTs payload to the configured endpoint. The payload is determined by
name,localContext, andcontext. localContextfields will overwritecontextfields of the same name.Telemetry.trackwill add two fields that cannot be overwritten:namefrom the parameter of the functiontswhich is the unix epoch time the object was created (seconds)
- Returns a
Promisecontaining the response of the POST on success, or the error on failure.
- POSTs payload to the configured endpoint. The payload is determined by
Telemetry.enable()Telemetry.disable()- When telemetry is disabled,
Telemetry.trackwill not POST and will return a rejectedPromisewith an appropriate error message instead. - You should use caution when deciding to call this method as this will affect all telemetry instances. For example, calling this in a dependency will disable telemetry for the entire application.
- When telemetry is disabled,
Telemetry.clearContext()- Deletes all context associated with the global telemetry object.
- You should use caution when deciding to call this method as this will affect all telemetry instances. For example, calling this in a dependency will clear the context for the entire application.
Telemetry.raw(obj)- Will POST
objtoendpointwithout modifications or context. - Returns a
Promisecontaining the response of the POST on success, or the error on failure. Use this method if
Telemetry.trackdoes not fit your needs.
- Will POST
Telemetry.create(name[, localContext])- Returns the object created by
Telemetry.trackwithout POSTing it.
- Returns the object created by