Authored by 周奇琪

在错误处理里加上报APM

... ... @@ -193,6 +193,11 @@ if (isProduction) {
}
return Math.min(options.attempt * 100, 1000);
}
},
report: {
host: 'influxd.yoho.cn',
port: 80,
db: 'web-apm'
}
});
} else if (isTest) {
... ...
... ... @@ -5,6 +5,7 @@
const headerModel = require('../models/header');
const logger = global.yoho.logger;
const helpers = global.yoho.helpers;
const sender = global.yoho.apmSender;
const forceNoCache = (res) => {
if (res && !res.finished) {
... ... @@ -49,6 +50,24 @@ exports.notFound = () => {
exports.serverError = () => {
return (err, req, res, next) => {
forceNoCache(res);
const uid = this.ctx.req.user.uid || 0;
const udid = this.ctx.req.query.udid || this.ctx.req.cookies._yasvd;
//上报服务端错误
sender.addMessage({
measurement: 'error-report',
tags: {
type: 'server',
reqID: req.reqID,
uid,
udid,
code: err.code || 500
},
fields: {
message: err.message,
stack: err.stack
}
});
if (err && err.code === 401) {
logger.error(`401 error info:client_type=${req.query.client_type},req.user=${JSON.stringify(req.user)},req.query=${JSON.stringify(req.query)},cookies=${JSON.stringify(req.cookies)}`); // eslint-disable-line
... ...