1.1.0 • Published 6 years ago

hapi-instrumental v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Hapi Instrumental Plugin

npm version Build Status Coverage Status

Instrument your Hapi.js app with instrumental service InstrumentalApp

Usage

Register plugin

// register plugin
server.register({
  register: require('hapi-instrumental'),
  options: {
    apiKey: 'jlsdfjklsjf2423432' //instrumental api key
  }
})
// register plugin with INSTRUMENTAL_KEY environment variable
process.env.INSTRUMENTAL_KEY = 'jlsdfjklsjf2423432'

server.register({
  register: require('hapi-instrumental'),
  options: {
  }
})

Usage

In addition to logging responses you can both increment and use the gauge functionality (please see instrumentalapp.com docs) as you would from the agent. The plugin also provides the ability to gauge the time from the start of the request as well as gauging start and stop keys.

server.route({
  method: 'GET',
  path: '/',
  handler: (request, h) => {
    request.increment('web.request.home')
    return  'Hi There'
  }
})

// with startMeasuring and endMeasuring
server.route({
  method: 'GET',
  path: '/slowquery',
  handler: async (request, h) => {
    request.startMeasuring('api.dataquery.time')
    const result = await getSomeData()
    request.endMeasuring('api.dataquery.time')
    return result
  }
})

// gauge from the start of the reqest
server.route({
  method: 'GET',
  path: '/slowquery',
  handler: async (request, h) => {

    const result = await getSomeData()
    request.measure('web.dataquery.time') // from start
    const result2 = await getSomeOtherData()

    return { ...result, ...result2 }
  }
})
// using the gauge directly
server.route({
  method: 'GET',
  path: '/slowquery',
  handler: async (request, h) => {
    const hrstart = process.hrtime()
    const result = await getSomeData()
    const hrend = process.hrtime(hrstart)
    request.gauge(
      'api.dataquery.time',
      hrend[1] / 1000000 /*, time = now, count = 1 */
    )
    return result
  }
})
1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago