1.6.0 • Published 7 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
. localContext
fields will overwritecontext
fields of the same name.Telemetry.track
will add two fields that cannot be overwritten:name
from the parameter of the functionts
which is the unix epoch time the object was created (seconds)
- Returns a
Promise
containing 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.track
will not POST and will return a rejectedPromise
with 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
obj
toendpoint
without modifications or context. - Returns a
Promise
containing the response of the POST on success, or the error on failure. Use this method if
Telemetry.track
does not fit your needs.
- Will POST
Telemetry.create(name[, localContext])
- Returns the object created by
Telemetry.track
without POSTing it.
- Returns the object created by