- 后端:增加自定义埋点测试

This commit is contained in:
YunaiV
2019-05-21 16:21:19 +08:00
parent a64a0e3887
commit 8240a0dc36
2 changed files with 19 additions and 0 deletions

View File

@@ -10,6 +10,8 @@ import cn.iocoder.mall.admin.api.SystemLogService;
import cn.iocoder.mall.admin.api.dto.systemlog.AccessLogAddDTO;
import cn.iocoder.mall.admin.api.dto.systemlog.ExceptionLogAddDTO;
import com.alibaba.fastjson.JSON;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Metrics;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
@@ -29,6 +31,11 @@ import java.util.Date;
@ControllerAdvice
public class GlobalExceptionHandler {
/**
* 异常总数 Metrics
*/
private static final Counter EXCEPTION_COUNTER = Metrics.counter("mall.exception.total");
private Logger logger = LoggerFactory.getLogger(getClass());
@Value("${spring.application.name}")
@@ -73,6 +80,8 @@ public class GlobalExceptionHandler {
// 插入异常日志
ExceptionLogAddDTO exceptionLog = new ExceptionLogAddDTO();
try {
// 增加异常计数 metrics
EXCEPTION_COUNTER.increment();
// 初始化 exceptionLog
initExceptionLog(exceptionLog, req, e);
// 执行插入 exceptionLog