|
|
|
@ -18,6 +18,7 @@ import kr.xit.core.support.slack.SlackWebhookPush;
|
|
|
|
|
import kr.xit.core.support.utils.Checks;
|
|
|
|
|
import kr.xit.core.support.utils.JsonUtils;
|
|
|
|
|
import kr.xit.core.support.utils.LogUtils;
|
|
|
|
|
import lombok.Getter;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
|
@ -86,8 +87,6 @@ public class TraceLoggerAspect {
|
|
|
|
|
|
|
|
|
|
private final ILoggingService loggingService;
|
|
|
|
|
private final SlackWebhookPush slackWebhookPush;
|
|
|
|
|
private static final String MESSAGE = "message";
|
|
|
|
|
private static final String CODE = "code";
|
|
|
|
|
private static final String REQUEST_TRACE_ID = "request_trace_id";
|
|
|
|
|
|
|
|
|
|
public TraceLoggerAspect(@Lazy ILoggingService loggingService, SlackWebhookPush slackWebhookPush) {
|
|
|
|
@ -112,8 +111,8 @@ public class TraceLoggerAspect {
|
|
|
|
|
if(!isReqLogEnabled) return;
|
|
|
|
|
ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
|
|
|
|
|
HttpServletRequest request = attributes != null? attributes.getRequest(): null;
|
|
|
|
|
assert request != null;
|
|
|
|
|
requestLog(request, getParams(request));
|
|
|
|
|
log.info("Before: " + joinPoint.getSignature().getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Around(value = "@annotation(kr.xit.core.spring.annotation.TraceLogging)")
|
|
|
|
@ -126,8 +125,8 @@ public class TraceLoggerAspect {
|
|
|
|
|
traceLogging(JsonUtils.toObjByObj(pjp.getArgs()[0], JSONObject.class), request);
|
|
|
|
|
Object result = pjp.proceed();
|
|
|
|
|
|
|
|
|
|
if(result instanceof CompletableFuture){
|
|
|
|
|
CompletableFuture future = (CompletableFuture)result;
|
|
|
|
|
//noinspection rawtypes
|
|
|
|
|
if(result instanceof CompletableFuture future){
|
|
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
|
if (future.isDone()) break;
|
|
|
|
@ -157,12 +156,13 @@ public class TraceLoggerAspect {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 배치 실행시 여기에서 set한 MDC 값이 batch 모듈에서 reading이 불가하여, 배치 tasklet에서 set한 trace_id로 set
|
|
|
|
|
* @param params
|
|
|
|
|
* @param request
|
|
|
|
|
* @param json JSONObject
|
|
|
|
|
* @param request HttpServletRequest
|
|
|
|
|
*/
|
|
|
|
|
protected void traceLogging(final JSONObject json, final HttpServletRequest request) {
|
|
|
|
|
String uri = "";
|
|
|
|
|
if(request != null) {
|
|
|
|
|
String uri = request.getRequestURI();
|
|
|
|
|
uri = request.getRequestURI();
|
|
|
|
|
if(Arrays.stream(excludes).anyMatch(uri::matches)) return;
|
|
|
|
|
|
|
|
|
|
MDC.put(REQUEST_TRACE_ID,
|
|
|
|
@ -180,15 +180,16 @@ public class TraceLoggerAspect {
|
|
|
|
|
//TODO::systemId, reqSystemId 설정 필요
|
|
|
|
|
log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
|
|
|
|
|
String params = resetJsonMasking(json);
|
|
|
|
|
String systemId = Checks.isNotEmpty(uri)? ApiSystemId.compareByUri(uri).getCode(): ApiSystemId.valueOf("NONE").getCode();
|
|
|
|
|
MDC.put("systemId", "ENS");
|
|
|
|
|
MDC.put("reqSystemId", "KAKAO");
|
|
|
|
|
MDC.put("reqSystemId", systemId);
|
|
|
|
|
MDC.put("param", params);
|
|
|
|
|
MDC.put("accessToken", "");
|
|
|
|
|
|
|
|
|
|
LoggingDTO loggingDTO = LoggingDTO.builder()
|
|
|
|
|
.requestId(MDC.getCopyOfContextMap().get(REQUEST_TRACE_ID))
|
|
|
|
|
.systemId("ENS")
|
|
|
|
|
.reqSystemId("KAKAO")
|
|
|
|
|
.reqSystemId(systemId)
|
|
|
|
|
.method(MDC.getCopyOfContextMap().get("method"))
|
|
|
|
|
.uri(MDC.getCopyOfContextMap().get("uri"))
|
|
|
|
|
.param(params)
|
|
|
|
@ -203,8 +204,8 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
|
|
|
|
|
protected void traceLoggingResult(final Object result) {
|
|
|
|
|
String success = "true";
|
|
|
|
|
//FIXME: slack webhook log push
|
|
|
|
|
if(result instanceof ApiResponseDTO<?>){
|
|
|
|
|
ApiResponseDTO<?> apiResponseDTO = (ApiResponseDTO<?>)result;
|
|
|
|
|
if(result instanceof ApiResponseDTO<?> apiResponseDTO){
|
|
|
|
|
|
|
|
|
|
if(!apiResponseDTO.isSuccess()){
|
|
|
|
|
success = "false";
|
|
|
|
|
|
|
|
|
@ -217,7 +218,7 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
|
|
|
|
|
}else{
|
|
|
|
|
slackWebhookPush.sendSlackAlertLog(
|
|
|
|
|
String.format("[%s]%s", MDC.get(REQUEST_TRACE_ID), apiResponseDTO.getMessage()),
|
|
|
|
|
MDC.get("uri"),
|
|
|
|
|
MDC.getCopyOfContextMap().get("uri"),
|
|
|
|
|
"batch call");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -247,9 +248,9 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getResult(final Object o){
|
|
|
|
|
if(o instanceof Future) {
|
|
|
|
|
//noinspection rawtypes
|
|
|
|
|
if(o instanceof Future future) {
|
|
|
|
|
try {
|
|
|
|
|
Future<?> future = (Future<?>)o;
|
|
|
|
|
return JsonUtils.toJson(future.get());
|
|
|
|
|
} catch (InterruptedException ie){
|
|
|
|
|
// thread pool에 에러 상태 전송
|
|
|
|
@ -369,4 +370,32 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
|
|
|
|
|
}
|
|
|
|
|
return json.toJSONString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Getter
|
|
|
|
|
private enum ApiSystemId {
|
|
|
|
|
KAKAO("KAKAO", "카카오", "/kakao/"),
|
|
|
|
|
KT_BC("KT-BC", "공공알림문자", "/kt/"),
|
|
|
|
|
PPLUS("POST-PLUS", "Post Plus", "/pplus/"),
|
|
|
|
|
NICE("NICE", "NICE CI", "/nice/"),
|
|
|
|
|
EPOST("EPOST", "E-POST", "/ag/"),
|
|
|
|
|
BATCH("BATCH", "미정의", "/미정의/"),
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
private final String code;
|
|
|
|
|
private final String desc;
|
|
|
|
|
private final String uri;
|
|
|
|
|
|
|
|
|
|
ApiSystemId(final String code, final String desc, final String uri) {
|
|
|
|
|
this.code = code;
|
|
|
|
|
this.desc = desc;
|
|
|
|
|
this.uri = uri;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ApiSystemId compareByUri(final String uri){
|
|
|
|
|
return Arrays.stream(ApiSystemId.values())
|
|
|
|
|
.filter(ssc -> uri.contains(ssc.getUri()))
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElseGet(() -> ApiSystemId.valueOf("BATCH"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|