1.6.0 • Published 7 years ago

frau-http-telemetry v1.6.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
7 years ago

frau-http-telemetry npm.io

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.

  • Telemetry.track(name[, localContext])
    • POSTs payload to the configured endpoint. The payload is determined by name, localContext, and context.
    • localContext fields will overwrite context fields of the same name.
    • Telemetry.track will add two fields that cannot be overwritten:
      • name from the parameter of the function
      • ts 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.
  • Telemetry.enable()
  • Telemetry.disable()
    • When telemetry is disabled, Telemetry.track will not POST and will return a rejected Promise 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.
  • 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 to endpoint 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.

  • Telemetry.create(name[, localContext])
    • Returns the object created by Telemetry.track without POSTing it.