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

function slowRouter(m) {
    let uid = `${_.get(m, 'fields.uid', '0') || '0'}`.replace(/"/g, '');

    return {
        app: _.get(m, 'tags.app', ''),
        type: _.get(m, 'tags.type', ''),
        hostname: _.get(m, 'tags.hostname', ''),
        preqid: _.get(m, 'fields.preqid', '').replace(/"/g, ''),
        reqid: _.get(m, 'fields.reqID', '').replace(/"/g, ''),
        uid: parseInt(uid),
        udid: _.get(m, 'fields.udid', '').replace(/"/g, ''),
        api: _.get(m, 'tags.api', ''),
        route: _.get(m, 'tags.route', ''),
        duration: _.get(m, 'fields.duration', ''),
        create_time: _.get(m, 'time') ? _.get(m, 'time') / 1000000 : 0
    };
}

function errorRouter(m) {
    let uid = `${_.get(m, 'fields.uid', '0') || '0'}`.replace(/"/g, '');
    let line = `${_.get(m, 'fields.line', '0') || '0'}`.replace(/"/g, '');
    let column = `${_.get(m, 'fields.column', '0') || '0'}`.replace(/"/g, '');

    return {
        app: _.get(m, 'tags.app', ''),
        api: _.get(m, 'tags.api', ''),
        type: _.get(m, 'tags.type', ''),
        hostname: _.get(m, 'tags.hostname', ''),
        preqid: _.get(m, 'fields.preqid', '').replace(/"/g, ''),
        reqid: _.get(m, 'fields.reqID', '').replace(/"/g, ''),
        uid: parseInt(uid),
        udid: _.get(m, 'fields.udid', '').replace(/"/g, ''),
        route: _.get(m, 'tags.route', ''),
        code: _.parseInt(_.get(m, 'tags.code', '0')),
        line: parseInt(line),
        column: parseInt(column),
        script: _.get(m, 'fields.script', ''),
        message: _.get(m, 'fields.message', ''),
        stack: _.get(m, 'fields.stack', ''),
        useragent: _.get(m, 'fields.useragent', ''),
        create_time: _.get(m, 'time') ? _.get(m, 'time') / 1000000 : 0
    };
}

module.exports = {
    slowRouter,
    errorRouter
};