Total Complexity | 13 |
Complexity/F | 1.3 |
Lines of Code | 50 |
Function Count | 10 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import addHooks from './helpers/add-hooks'; |
||
2 | |||
3 | /* |
||
4 | a decorator to timing action execution time in both success/error cases |
||
5 | and send metrics using the client attached in context |
||
6 | */ |
||
7 | const metricsTimer = ({ parseLabel = () => {} } = {}) => |
||
8 | addHooks({ |
||
9 | bypassHook: (p, m, { metrics }) => !metrics, |
||
10 | storageHook: (p, m, c, action) => { |
||
11 | const { metrics } = c; |
||
12 | const timer = metrics.find({ action, type: 'timer' }); |
||
13 | const stopTimer = timer.start({ ...m, ...parseLabel(p, m, c) }); |
||
14 | return { stopTimer }; |
||
15 | }, |
||
16 | afterHook: (r, p, m, c, a, { stopTimer }) => { |
||
17 | stopTimer(); |
||
18 | }, |
||
19 | errorHook: (e, p, m, c, a, { stopTimer }) => { |
||
20 | stopTimer(); |
||
21 | }, |
||
22 | }); |
||
23 | |||
24 | export default metricsTimer; |
||
25 |