Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Fix dummy traceID exception log (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
galales authored Sep 7, 2023
2 parents 0235022 + 5d76017 commit 651fd82
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.List;
import org.slf4j.MDC;
import org.springframework.beans.TypeMismatchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
Expand All @@ -14,6 +15,7 @@
import com.amazonaws.xray.AWSXRay;
import it.pagopa.interop.probing.statistics.api.util.constants.ErrorMessages;
import it.pagopa.interop.probing.statistics.api.util.logging.Logger;
import it.pagopa.interop.probing.statistics.api.util.logging.LoggingPlaceholders;
import it.pagopa.interop.probing.statistics.dtos.Problem;
import it.pagopa.interop.probing.statistics.dtos.ProblemError;

Expand Down Expand Up @@ -49,7 +51,7 @@ protected ResponseEntity<Object> handleIOException(IOException ex) {
@Override
protected ResponseEntity<Object> handleTypeMismatch(TypeMismatchException ex, HttpHeaders headers,
HttpStatus status, WebRequest request) {
log.logMessageException(ex);
handleException(ex);
Problem problemResponse =
createProblem(HttpStatus.BAD_REQUEST, ErrorMessages.BAD_REQUEST, ErrorMessages.BAD_REQUEST);
return ResponseEntity.status(status).body(problemResponse);
Expand All @@ -71,4 +73,11 @@ private Problem createProblem(HttpStatus responseCode, String titleMessage,
.traceId(AWSXRay.getCurrentSegment().getTraceId().toString()).errors(List.of(errorDetails))
.build();
}

private void handleException(Exception ex) {
MDC.put(LoggingPlaceholders.TRACE_ID_XRAY_PLACEHOLDER,
LoggingPlaceholders.TRACE_ID_XRAY_MDC_PREFIX
+ AWSXRay.getCurrentSegment().getTraceId().toString() + "]");
log.logMessageException(ex);
}
}
4 changes: 2 additions & 2 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<onMatch>DENY</onMatch>
</filter>
<encoder>
<pattern>%d{YYYY-MM-dd HH:mm:ss:SSS} %(%-5level) [%(%logger{20})] %X{AWS-XRAY-TRACE-ID} %X{trace_id} - %msg %n</pattern>
<pattern>%d{YYYY-MM-dd HH:mm:ss:SSS} %(%-5level) [%(%logger{20})] %X{AWS-XRAY-TRACE-ID} - %msg %n</pattern>
</encoder>
</appender>

Expand All @@ -18,7 +18,7 @@
<level>ERROR</level>
</filter>
<encoder>
<pattern>%d{YYYY-MM-dd HH:mm:ss:SSS} %(%-5level) [%(%logger{20})] %X{AWS-XRAY-TRACE-ID} [%X{trace_id}] - %msg %n</pattern>
<pattern>%d{YYYY-MM-dd HH:mm:ss:SSS} %(%-5level) [%(%logger{20})] %X{AWS-XRAY-TRACE-ID} - %msg %n</pattern>
</encoder>
<target>System.err</target>
</appender>
Expand Down

0 comments on commit 651fd82

Please sign in to comment.