Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Hapi.js + PostgreSQL Auto-Instrumentation Example

This is an example of automatically producing distributed traces using the SignalFx Tracing Library for JavaScript. Please examine the instrumented client and server for some basic patterns in accessing the instrumentations of a http client and a Hapi server using a node-postgres client.

In this example, we have a simple contact application named "ContactKeeper" that is auto-instrumented by a lone tracer invocation.

Building the example app and client

To run this example locally and send traces to your available Smart Agent or Gateway, from this directory do the following:

In one terminal:

$ # start up the postgres server
$ npm run postgres
$ # install app requirements
$ npm install
$ # Run the server from one shell session:
$ npm start

++++++++++++++++++++++++++++++++++++++++++++++++++++++

    Welcome to ContactKeeper.
    The server is listening on http://localhost:8000.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

Note: Allow a few seconds between npm run postgres and npm start, to ensure the postgres server is ready for use.

From a different terminal, you may run the client commands.

$ # You may also use ` ./client.js help` directly
$ npm run client help
Usage: contactKeeper <command> [options]

Commands:
  contactKeeper add <firstName> <lastName> <email>        Add a new contact to your address book.
  contactKeeper delete <fName> <lName>                    Delete a contact.
  contactKeeper deleteByID <id>                           Delete a contact by ID.
  contactKeeper list                                      Show list.
  contactKeeper get <fName> [lName]                       Get contact from your ContactKeeper.
  contactKeeper update <fName> <lName> <email>            Update a contact's email.
  contactKeeper updateByID <id> <email>                   Update a contact's email by ID.


The signalfx-tracing module and this application configuration assume that your Smart Agent or Gateway is accepting traces at http://localhost:9080/v1/trace. If this is not the case, you can set the SIGNALFX_ENDPOINT_URL environment variable to the desired url to suit your environment before launching the server and client.

Using

The ContactKeeper allows you to add, retrieve, update and delete entries of your contacts.

Example usage:

$ # You may also use ` ./client.js add Cara French [email protected]` directly
$ npm run client add Cara French [email protected]

++++++++++++++++++++++++++++++++++
ContactKeeper: 

You have successfully added 'Cara French'
Email: '[email protected]' to your ContactKeeper.

++++++++++++++++++++++++++++++++++



$ npm run client get Cara

+++++++++++++++++++++++++++++++++++
             Contact(s)
----++---------++++---------++-----

id: 1
firstname: Cara
lastname: French
email: [email protected]

-----++---------++++---------++----

+++++++++++++++++++++++++++++++++++