feat(REQ-2924) - 优化异常告警的内容

This commit is contained in:
wangli 2024-09-14 14:56:40 +08:00
parent 09f2d09ae1
commit e221cb1d6b
3 changed files with 19 additions and 10 deletions

View File

@ -20,9 +20,9 @@ public enum ReporterType {
*/
ONLY_DING_TALK {
@Override
public void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, Throwable e, Boolean downgrade) {
public void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, String invokeServerName, Throwable e, Boolean downgrade) {
if (sendDingTalk) {
DingTalkUtils.sendDingTalk(profile, title, argsArrayToString(args), e);
DingTalkUtils.sendDingTalk(profile, title, argsArrayToString(args), invokeServerName, e);
}
}
@ -32,7 +32,7 @@ public enum ReporterType {
*/
ONLY_LOG {
@Override
public void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, Throwable e, Boolean downgrade) {
public void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, String invokeServerName, Throwable e, Boolean downgrade) {
if (downgrade) {
log.warn("ER: {}", e.getMessage());
} else {
@ -46,9 +46,9 @@ public enum ReporterType {
*/
BOTH {
@Override
public void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, Throwable e, Boolean downgrade) {
public void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, String invokeServerName, Throwable e, Boolean downgrade) {
if (sendDingTalk) {
DingTalkUtils.sendDingTalk(profile, title, argsArrayToString(args), e);
DingTalkUtils.sendDingTalk(profile, title, argsArrayToString(args),invokeServerName, e);
}
if (downgrade) {
log.warn("ER: {}", e.getMessage());
@ -66,7 +66,7 @@ public enum ReporterType {
* @param shortString 用于日志输出的关键信息
* @param e 异常对象
*/
public abstract void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, Throwable e, Boolean downgrade);
public abstract void executeAction(String profile, String title, Boolean sendDingTalk, Object[] args, String shortString, String invokeServerName, Throwable e, Boolean downgrade);
private static void logWarn(Throwable throwable, String shortString) {
// 由于框架底层 AbstractExceptionApiResultHandler 默认会打印所以此处都只是降级打印

View File

@ -138,7 +138,13 @@ public class ErrorReportAspect implements Ordered {
}
log.warn("request header server name: {}", getHeader());
envConfig.type().executeAction(profile, operation.summary(), filterSendDingTalk, joinPoint.getArgs(), joinPoint.getSignature().toShortString(), e,
envConfig.type().executeAction(profile,
operation.summary(),
filterSendDingTalk,
joinPoint.getArgs(),
joinPoint.getSignature().toShortString(),
getHeader(),
e,
workflowProperties.getFilterOperations().contains(operation.summary()));
}

View File

@ -68,17 +68,20 @@ public class DingTalkUtils {
}
@SneakyThrows
public static void sendDingTalk(String profile, String title, Object req, Throwable throwable) {
public static void sendDingTalk(String profile, String title, Object req, String invokeServerName, Throwable throwable) {
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
markdown.setTitle("Notice " + title + ", Env: " + profile);
markdown.setText("#### [" + profile + "]" + title + "\n" +
String text = "#### [" + profile + "]" + title + "\n" +
"> 入参: " + JSONUtil.toJsonStr(req) + "\n\n" +
"> ###### 异常信息: " + JSONUtil.toJsonStr(Objects.isNull(throwable.getCause()) ? throwable.getMessage() :
throwable.getCause().getMessage()) + " \n\n" +
"> ##### traceId: " + MDC.get(CTX_LOG_ID_MDC) + " \n" +
"> ##### [点击查看异常明细](" + getDeadLetterStacktrace(profile, req) + ") \n");
"> ##### 调用方服务名称:" + invokeServerName + " \n";
String deadLetterStacktrace = getDeadLetterStacktrace(profile, req);
text = text + (StringUtils.hasText(deadLetterStacktrace) ? "> ##### [点击查看异常明细](" + deadLetterStacktrace + ") \n" : "");
markdown.setText(text);
request.setMarkdown(markdown);
sendDingTalk(request);
}