Skip to content

Commit

Permalink
LCAM-985: Upgraded crime commons version and enabled micrometer tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
skasthuri36326 committed Oct 18, 2023
1 parent ef2e270 commit da02bab
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crime-evidence/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def versions = [
mockwebserverVersion : "4.10.0",
pitest : "1.4.10",
commonsLang3Version : "3.10",
crimeCommonsVersion : "2.2.0",
crimeCommonsVersion : "2.7.0",
wiremockVersion : "2.35.0"

]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@Slf4j
@SpringBootApplication
@SpringBootApplication(exclude = ZipkinAutoConfiguration.class)
@ConfigurationPropertiesScan
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class CrimeEvidenceApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@Value
@Builder
public class ErrorDTO {
private String traceId;
private String code;
private String message;
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
package uk.gov.justice.laa.crime.evidence.exception;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import uk.gov.justice.laa.crime.commons.exception.APIClientException;
import uk.gov.justice.laa.crime.commons.tracing.TraceIdHandler;
import uk.gov.justice.laa.crime.evidence.dto.ErrorDTO;


@RestControllerAdvice
@Slf4j
@RestControllerAdvice
@RequiredArgsConstructor
public class CrimeEvidenceExceptionHandler {

private static ResponseEntity<ErrorDTO> buildErrorResponse(HttpStatus status, String errorMessage) {
private final TraceIdHandler traceIdHandler;

private static ResponseEntity<ErrorDTO> buildErrorResponse(HttpStatus status, String errorMessage, String traceId) {
return new ResponseEntity<>(ErrorDTO.builder().code(status.toString()).message(errorMessage).build(), status);
}

@ExceptionHandler(APIClientException.class)
public ResponseEntity<ErrorDTO> handleApiClientError(APIClientException ex) {
log.error("APIClientException: ", ex);
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage(), traceIdHandler.getTraceId());
}

@ExceptionHandler(CrimeEvidenceDataException.class)
public ResponseEntity<ErrorDTO> handleCrimeEvidenceDataException(CrimeEvidenceDataException ex) {
log.error("CrimeEvidenceDataException: ", ex);
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage(), traceIdHandler.getTraceId());
}

}
3 changes: 3 additions & 0 deletions crime-evidence/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ management:
web:
exposure:
include: health,info,metrics,prometheus
tracing:
propagation:
type: w3c,b3

springdoc:
packagesToScan: uk.gov.justice.laa.crime.evidence
Expand Down
2 changes: 1 addition & 1 deletion crime-evidence/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<configuration>
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
<pattern>%d{HH:mm:ss.SSS} traceId: %X{traceId:-} spanId: %X{spanId:-} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.oauth2.jwt.JwtDecoder;

import java.time.Instant;
import java.util.Map;

@TestConfiguration
@ComponentScan(basePackages = {"uk.gov.justice.laa.crime.commons.tracing"})
public class CrimeEvidenceTestConfiguration {

static final String SUB = "sub";
Expand Down

0 comments on commit da02bab

Please sign in to comment.