src/event.js   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 1.17

Size

Lines of Code 28
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 7
c 1
b 0
f 0
nc 1
mnd 1
bc 5
fnc 6
dl 0
loc 28
rs 10
bpm 0.8333
cpm 1.1666
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A event.js ➔ ??? 0 20 2
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