Skip to content

Commit

Permalink
fix: interceptor handler instance condition
Browse files Browse the repository at this point in the history
  • Loading branch information
char-yb committed Aug 23, 2024
1 parent edf1571 commit c8feb33
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ public class MdcLoggingInterceptor implements HandlerInterceptor {
public boolean preHandle(
HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
HandlerMethod handlerMethod = (HandlerMethod) handler;
String handlerName = handlerMethod.getMethod().getName();
String methodName = handlerMethod.getBeanType().getSimpleName();
String controllerInfo = methodName + "." + handlerName;
String traceId = UUID.randomUUID().toString();
MDC.put("traceId", traceId);
MDC.put("serviceName", controllerInfo);
// handler가 HandlerMethod인지 확인
if (handler instanceof HandlerMethod handlerMethod) {
String handlerName = handlerMethod.getMethod().getName();
String methodName = handlerMethod.getBeanType().getSimpleName();
String controllerInfo = methodName + "." + handlerName;
String traceId = UUID.randomUUID().toString();
MDC.put("traceId", traceId);
MDC.put("serviceName", controllerInfo);
}
return true;
}

Expand Down

0 comments on commit c8feb33

Please sign in to comment.