Total Complexity | 7 |
Complexity/F | 1.17 |
Lines of Code | 28 |
Function Count | 6 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | import { getMetricsInstance } from './init'; |
||
2 | |||
3 | export const createEventMetrics = ({ service, operation, action }) => { |
||
4 | const metrics = getMetricsInstance(); |
||
5 | if (metrics === undefined) { |
||
6 | throw Error(`auto metrics instance needs to be initialised first`); |
||
7 | } |
||
8 | const serviceRoot = `service.${service}.action.${action}`; |
||
9 | const operationRoot = `operation.${operation}.action.${action}`; |
||
10 | const countOne = path => { |
||
11 | metrics.count(`${serviceRoot}.${path}`, 1); |
||
12 | metrics.count(`${operationRoot}.${path}`, 1); |
||
13 | }; |
||
14 | return { |
||
15 | start: () => countOne('state.start'), |
||
16 | success: () => countOne('state.success'), |
||
17 | failure: e => { |
||
18 | countOne(`state.failure.category.${e.category}.status.${e.status}`); |
||
19 | countOne(`state.failure.category.${e.category}.type.${e.type}`); |
||
20 | }, |
||
21 | }; |
||
22 | }; |
||
23 | |||
24 | export const metricsEvent = ({ service, operation, action }) => { |
||
25 | const event = createEventMetrics({ service, operation, action }); |
||
26 | event.start(); |
||
27 | return event; |
||
28 | }; |
||
29 |