Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | 5x 5x | /**
* This file hold common mixins methods and actions for metrics mixins
*/
const Int64 = require('node-int64');
module.exports = {
name: 'metrics.base',
version: 1,
settings: {},
/**
* Methods
*/
methods: {
/**
* Get service name from metric event
*
* @param {Object} metric
* @returns {String}
*/
getServiceName(metric) {
if (metric.service && metric.service.name)
return metric.service.name;
let parts = metric.action.name.split('.');
parts.pop(); //action name
return parts.pop(); //service name
},
getServiceVersion(metric) {
if (metric.service && metric.service.version)
return metric.service.version;
let parts = metric.action.name.split('.');
parts.pop(); //action name
parts.pop(); //service name
return parts.pop(); //version
},
/**
* Get span name from metric event. By default it returns the action name
*
* @param {Object} metric
* @returns {String}
*/
getActionName(metric) {
if (metric.action && metric.action.name) {
let parts = metric.action.name.split('.');
return parts.pop(); //action name
}
//fallback
if (metric.name) return metric.name;
if (metric.action) return metric.action.name;
},
/**
* Convert Context ID to makeTraceId (Zipkin format)
*
* @param {String} id
* @returns {String}
*/
makeTraceId(id) {
if (id) {
return new Int64(
id.replace(/-/g, '').substring(0, 16)
).toBuffer();
}
return null;
}
}
}; |