hapi-tracer
hapi-tracer
provides a full hapi lifecycle trace.
Compatible with:
- node >=8.6.0
- hapi 16.x.x
- wreck 8.x.x
- catbox 7.x.x
Install
npm install --save hapi-tracer
Usage
server;
Options
hapi
- to instrument hapi, require hapi and assign.
wreck
- to instrument wreck, require wreck and assign.
catbox
- to instrument catbox, require catbox and assign.
record
- record is a function that consumes a trace
object. Use this function to record the request trace.
During a hapi request lifecycle - hapi middleware, methods and handlers are traced. Any http calls via wreck are also traced.
meta: {} // user generated meta aggregates: // aggregated trace stats middleware: duration: 10 // aggregated duration in ms count: 1 // aggregated count percent: 1667 // aggregated % of total request latency methods: duration: 10 count: 1 percent: 1667 handlers: duration: 10 count: 1 percent: 1667 wreck: duration: 10 count: 1 percent: 1667 catbox: duration: 10 count: 1 percent: 1667 custom: duration: 10 count: 1 percent: 1667 trace: // ordered trace items type: 'Middleware' subType: 'onRequest' fncName: 'fetchHeaders' // if unknown, '<anonymous>' arity: 2 // fnc arity start: 1000000 // unix timestamp end: 1000010 // unix timestamp duration: 10 // ms percent: 1667 // % of total request latency type: 'Handler' subType: 'getData' fncName: '<anonymous>' arity: 2 start: 1000010 end: 1000020 duration: 10 percent: 1667 type: 'Method' subType: 'add' fncName: 'add' arity: 3 start: 1000020 end: 1000030 duration: 10 percent: 1667 type: 'Wreck' subType: 'request' fncName: '<anonymous>' arity: 3 start: 1000030 end: 1000040 duration: 10 percent: 1667 type: 'Catbox' subType: 'request' fncName: '<anonymous>' arity: 3 start: 1000040 end: 1000050 duration: 10 percent: 1667 type: 'Custom' subType: 'request' fncName: '<anonymous>' arity: 3 start: 1000050 end: 1000060 duration: 10 percent: 1667
generateMeta
- is an optional function that consumes a hapi request, the result of which will be appended to the trace
object as meta
.
Use this function to generate tags or meta data for your traces.
NB. Any uncovered time is recorded as unknown
.
Custom
recordFn
and recordProto
are also exposed on the hapi.server
object - allowing you to append custom trace items.
recordFn
example:
// decorate an inline function const fn = serverplugins'hapi-tracer'; // execute function const result = ;
recordProto
example:
// decorate a prototype function serverplugins'hapi-tracer';