msg2row.js 1.3 KB
const _ = require('lodash');

function slowRouter(m) {
    return {
        app: _.get(m, 'tags.app', ''),
        type: _.get(m, 'tags.type', ''),
        hostname: _.get(m, 'tags.hostname', ''),
        preqid: _.get(m, 'fields.preqid', ''),
        reqid: _.get(m, 'fields.reqID', ''),
        uid: _.get(m, 'fields.uid', ''),
        udid: _.get(m, 'fields.udid', ''),
        api: _.get(m, 'tags.api', ''),
        route: _.get(m, 'tags.route', ''),
        duration: _.get(m, 'fields.duration', ''),
        create_time: _.get(m, 'time') / 1000000
    };
}

function errorRouter(m) {
    return {
        app: _.get(m, 'tags.app', ''),
        type: _.get(m, 'tags.type', ''),
        hostname: _.get(m, 'tags.hostname', ''),
        preqid: _.get(m, 'tags.preqid', ''),
        reqid: _.get(m, 'tags.reqID', ''),
        uid: _.get(m, 'tags.uid', ''),
        route: _.get(m, 'tags.route', ''),
        udid: _.get(m, 'tags.udid', ''),
        code: _.get(m, 'tags.code', ''),
        line: _.get(m, 'fields.line', ''),
        column: _.get(m, 'fields.column', ''),
        script: _.get(m, 'fields.script', ''),
        message: _.get(m, 'fields.message', ''),
        stack: _.get(m, 'fields.stack', ''),
        create_time: _.get(m, 'time') / 1000000
    };
}

module.exports = {
    slowRouter,
    errorRouter
};