1 | # lib-hapi-good-tracer
|
2 |
|
3 | [![Coverage Status](https://coveralls.io/repos/github/GoodwayGroup/lib-hapi-good-tracer/badge.svg?branch=master)](https://coveralls.io/github/GoodwayGroup/lib-hapi-good-tracer?branch=master) [![CircleCI](https://circleci.com/gh/GoodwayGroup/lib-hapi-good-tracer.svg?style=svg)](https://circleci.com/gh/GoodwayGroup/lib-hapi-good-tracer)
|
4 |
|
5 | ## Usage
|
6 |
|
7 | This plugin will read, generate and track a tracer header on `request`s that is then injected into the `Good` log stream via an `inject` object.
|
8 |
|
9 | ```
|
10 | $ npm install -S @goodwaygroup/lib-hapi-good-tracer
|
11 | ```
|
12 |
|
13 | In your `index.js` for the Hapi server, register the plugin:
|
14 |
|
15 | ```js
|
16 | await server.register({
|
17 | plugin: require('@goodwaygroup/lib-hapi-good-tracer'),
|
18 | options: {
|
19 | traceUUIDHeader: 'x-custom-trace-uuid', // optional defaults to 'x-gg-trace-uuid'
|
20 | traceSeqIDHeader: 'x-custom-trace-seqid', // optional defaults to 'x-gg-trace-seqid'
|
21 | enableStatsRoute: true, // optional defaults to false
|
22 | baseRoute: '/debug', // optional defaults to ''
|
23 | cache: {
|
24 | ttl: 60 // optional defaults to 120 seconds
|
25 | }
|
26 | }
|
27 | });
|
28 |
|
29 | // add stream to Good log reporters
|
30 | const logReporters = {
|
31 | console: [
|
32 | server.plugins.goodTracer.GoodSourceTracer, // Stream Transform that will inject the tracer object
|
33 | {
|
34 | module: 'good-squeeze',
|
35 | name: 'Squeeze',
|
36 | args: [{
|
37 | response: { exclude: 'healthcheck' },
|
38 | log: '*',
|
39 | request: '*',
|
40 | error: '*',
|
41 | ops: '*'
|
42 | }]
|
43 | }, {
|
44 | module: 'good-squeeze',
|
45 | name: 'SafeJson'
|
46 | }, 'stdout']
|
47 | };
|
48 |
|
49 | await server.register({
|
50 | plugin: Good,
|
51 | options: {
|
52 | reporters: logReporters
|
53 | }
|
54 | });
|
55 | ```
|
56 |
|
57 | ## In-Memory Cache
|
58 |
|
59 | This plugin uses an in-memory cache that is used to pass the `tracer` information between the server, request and logger.
|
60 |
|
61 | There is a global TTL per object that is reset on each `get` of the object.
|
62 |
|
63 | If an object is stale for the length of the TTL, it will be culled.
|
64 |
|
65 | There is a max number of keys that can be active at any time to help with memory concerns.
|
66 |
|
67 | See [node-cache](https://github.com/node-cache/node-cache) for available settings.
|
68 |
|
69 | ## Configuration Options
|
70 |
|
71 | > When passing a configuration option, it will overwrite the defaults.
|
72 |
|
73 | - `traceUUIDHeader`: defaults to `x-gg-trace-uuid`. The header that is used for the Trace ID
|
74 | - `traceSeqIDHeader`: defaults to `x-gg-trace-seqid`. The header that is used for the Sequence ID
|
75 | - `enableStatsRoute`: defaults to `false`. Publish a route to `/good-tracer/stats` that exposes the current metrics for [`node-cache` statistics](https://github.com/node-cache/node-cache#statistics-stats).
|
76 | - `baseRoute`: defaults to `''`. Prepends to the `/good-tracer/stats` route.
|
77 | - Example: `baseRoute = /serivce-awesome` results in `/serivce-awesome/good-tracer/stats`
|
78 | - `cache`: internal memory cache settings. See [node-cache](https://github.com/node-cache/node-cache)
|
79 | - `ttl`: default 120 seconds
|
80 | - `checkPeriod`: default 5 minutes
|
81 | - `maxKeys`: default `5000`
|
82 | - `useClones`: default `false`
|
83 | - `extendTTLOnGet`: This feature will reset the TTL to the global TTL when a successful `get` occurs. This will extend the life of an item in the cache as a result. default `true`
|
84 |
|
85 | ## Running Tests
|
86 |
|
87 | To run tests, just run the following:
|
88 |
|
89 | ```
|
90 | npm test
|
91 | ```
|
92 |
|
93 | All commits are tested on [CircleCI](https://circleci.com/gh/GoodwayGroup/workflows/lib-hapi-good-tracer)
|
94 |
|
95 | ## Linting
|
96 |
|
97 | To run `eslint`:
|
98 |
|
99 | ```
|
100 | npm run lint
|
101 | ```
|
102 |
|
103 | To auto-resolve:
|
104 |
|
105 | ```
|
106 | npm run lint:fix
|
107 | ```
|
108 |
|
109 | ## Contributing
|
110 |
|
111 | Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
|
112 |
|
113 | ## Versioning
|
114 |
|
115 | We use milestones and `npm` version to bump versions. We also employ [git-chglog](https://github.com/git-chglog/git-chglog) to manage the [CHANGELOG.md](CHANGELOG.md). For the versions available, see the [tags on this repository](https://github.com/GoodwayGroup/lib-hapi-good-tracer/tags).
|
116 |
|
117 | To initiate a version change:
|
118 |
|
119 | ```
|
120 | npm version minor
|
121 | ```
|
122 |
|
123 | ## Authors
|
124 |
|
125 | * **Derek Smith** - *Initial work* - [@clok](https://github.com/clok)
|
126 |
|
127 | See also the list of [contributors](https://github.com/GoodwayGroup/lib-hapi-good-tracer/contributors) who participated in this project.
|
128 |
|
129 | ## License
|
130 |
|
131 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
|
132 |
|
133 | ## Acknowledgments
|
134 |
|
135 | ## Sponsors
|
136 |
|
137 | [![goodwaygroup][goodwaygroup]](https://goodwaygroup.com)
|
138 |
|
139 | [goodwaygroup]: https://s3.amazonaws.com/gw-crs-assets/goodwaygroup/logos/ggLogo_sm.png "Goodway Group"
|