diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/filter/CustomClientRequestLoggingFilter.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/filter/CustomClientRequestLoggingFilter.java new file mode 100644 index 00000000..9bec6a20 --- /dev/null +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/filter/CustomClientRequestLoggingFilter.java @@ -0,0 +1,29 @@ +package it.pagopa.selfcare.user.filter; + + +import jakarta.ws.rs.client.ClientRequestContext; +import jakarta.ws.rs.ext.Provider; +import lombok.extern.slf4j.Slf4j; +import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext; +import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestFilter; + +import java.io.IOException; + +@Provider +@Slf4j +public class CustomClientRequestLoggingFilter implements ResteasyReactiveClientRequestFilter { + + @Override + public void filter(ClientRequestContext requestContext) throws IOException { + ResteasyReactiveClientRequestFilter.super.filter(requestContext); + } + + @Override + public void filter(ResteasyReactiveClientRequestContext requestContext) { + String endpoint = requestContext.getUri().getPath(); + String query = requestContext.getUri().getQuery(); + String method = requestContext.getMethod(); + MDCUtils.addOperationIdAndParameters(method); + log.info("Request: method: {}, endpoint: {}, query: {}", method, endpoint, query); + } +} diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/filter/CustomClientResponseLoggingFilter.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/filter/CustomClientResponseLoggingFilter.java new file mode 100644 index 00000000..04f975e9 --- /dev/null +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/filter/CustomClientResponseLoggingFilter.java @@ -0,0 +1,30 @@ +package it.pagopa.selfcare.user.filter; + + +import jakarta.ws.rs.client.ClientRequestContext; +import jakarta.ws.rs.client.ClientResponseContext; +import jakarta.ws.rs.ext.Provider; +import lombok.extern.slf4j.Slf4j; +import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientRequestContext; +import org.jboss.resteasy.reactive.client.spi.ResteasyReactiveClientResponseFilter; +import org.slf4j.MDC; + +@Provider +@Slf4j +public class CustomClientResponseLoggingFilter implements ResteasyReactiveClientResponseFilter { + + @Override + public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) { + ResteasyReactiveClientResponseFilter.super.filter(requestContext, responseContext); + } + + @Override + public void filter(ResteasyReactiveClientRequestContext requestContext, ClientResponseContext responseContext) { + String endpoint = requestContext.getUri().getPath(); + String query = requestContext.getUri().getQuery(); + String method = requestContext.getMethod(); + int status = responseContext.getStatus(); + log.info("Response: method: {}, endpoint: {}, query: {}, status [{}]", method, endpoint, query, status); + MDC.clear(); + } +} diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/filter/MDCUtils.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/filter/MDCUtils.java new file mode 100644 index 00000000..4680531c --- /dev/null +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/filter/MDCUtils.java @@ -0,0 +1,10 @@ +package it.pagopa.selfcare.user.filter; + +import org.slf4j.MDC; + +public class MDCUtils { + + public static void addOperationIdAndParameters(String operationId) { + MDC.put("sc_operation_id", operationId); + } +} diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserInfoServiceDefault.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserInfoServiceDefault.java index 9fad3047..21e37ae0 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserInfoServiceDefault.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserInfoServiceDefault.java @@ -18,7 +18,9 @@ public class UserInfoServiceDefault implements UserInfoService { @Override public Uni findById(String userId) { Uni userInfo = UserInfo.findById(userId); - return userInfo.onItem().transform(userInfoMapper::toResponse); + return userInfo + .onItem().invoke(user -> log.info("Founded userInfo for userId: {}", userId)) + .onItem().transform(userInfoMapper::toResponse); } } diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserInstitutionServiceDefault.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserInstitutionServiceDefault.java index 41180f13..02d2382d 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserInstitutionServiceDefault.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserInstitutionServiceDefault.java @@ -139,6 +139,7 @@ public Uni updateUserCreatedAtByInstitutionAndProduct(String institutionId Map filterMap = userUtils.retrieveMapForFilter(onboardedProductFilterMap, userInstitutionFilterMap); Map fieldToUpdateMap = Map.of(UserInstitution.Fields.products.name() + CURRENT_ANY + OnboardedProduct.Fields.createdAt.name(), createdAt, UserInstitution.Fields.products.name() + CURRENT_ANY + OnboardedProduct.Fields.updatedAt.name(), LocalDateTime.now()); + log.info("Update user institution with filter: {} and field to update: {}", filterMap, fieldToUpdateMap); return UserInstitution.update(queryUtils.buildUpdateDocument(fieldToUpdateMap)) .where(queryUtils.buildQueryDocument(filterMap, USER_INSTITUTION_COLLECTION)); } diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserNotificationServiceImpl.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserNotificationServiceImpl.java index da57a151..37136b10 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserNotificationServiceImpl.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserNotificationServiceImpl.java @@ -22,6 +22,7 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.eclipse.microprofile.rest.client.inject.RestClient; +import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring; import org.openapi.quarkus.user_registry_json.model.UserResource; import org.openapi.quarkus.user_registry_json.model.WorkContactResource; @@ -167,6 +168,7 @@ private static String retrieveMail(UserResource user, UserInstitution institutio } else { email = certEmail.getEmail().getValue(); } + log.debug("retrieved Mail for user with id: {}", user.getId()); return email; } } \ No newline at end of file diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserPermissionServiceImpl.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserPermissionServiceImpl.java index 9fc9f626..9ee63fe9 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserPermissionServiceImpl.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserPermissionServiceImpl.java @@ -29,9 +29,10 @@ public class UserPermissionServiceImpl implements UserPermissionService { @Override public Uni hasPermission(String institutionId, String productId, PermissionTypeEnum permission, String userId) { log.trace("hasPermission start"); - log.debug("hasPermission institutionId = {}, productId = {}, permission = {}", institutionId, productId, permission); + log.debug("check permission {} for userId: {}, institutionId: {} and productId: {}", permission, userId, institutionId, productId); return retrievePerson(userId, productId, institutionId) + .onItem().ifNotNull().invoke(userInstitution -> log.debug("UserInstitution founded for given parameters")) .onItem().transform(userInstitution -> PermissionTypeEnum.ANY.equals(permission) || checkProductRole(userInstitution, productId, permission)) .onFailure(ResourceNotFoundException.class).recoverWithItem(false); } diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserRegistryServiceImpl.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserRegistryServiceImpl.java index e579f05e..cf1137d6 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserRegistryServiceImpl.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/service/UserRegistryServiceImpl.java @@ -54,12 +54,15 @@ public Uni> updateUserRegistryAndSendNotificationTo .institutionId(StringUtils.isNotBlank(institutionId) ? institutionId : null).build(); return Uni.combine().all() - .unis(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST_WITHOUT_FISCAL_CODE, userId), - userInstitutionService.findAllWithFilter(userInstitutionFilter.constructMap()).collect().asList()) + .unis(userRegistryApi.findByIdUsingGET(USERS_FIELD_LIST_WITHOUT_FISCAL_CODE, userId) + .onItem().ifNotNull().invoke(() -> log.debug("User founded on userRegistry with userId: {}", userId)), + userInstitutionService.findAllWithFilter(userInstitutionFilter.constructMap()).collect().asList() + .onItem().ifNotNull().invoke(() -> log.debug("UserInstitution founded for userId: {} and institutionId: {}", userId, institutionId))) .asTuple() .onItem().transformToMulti(tuple -> findMailUuidAndUpdateUserRegistry(tuple.getItem1(), updateUserRequest) .onItem().transformToMulti(uuidMail -> updateUserInstitutionAndSendNotification(tuple.getItem1(), tuple.getItem2(), uuidMail))) - .collect().asList(); + .collect().asList() + .onItem().invoke(items -> log.trace("update {} users on userRegistry", items.size())); } private Multi updateUserInstitutionAndSendNotification(UserResource userResource, List userInstitutions, String mailUuid) { @@ -67,6 +70,7 @@ private Multi updateUserInstitutionAndSendNotification(U .peek(userInstitution -> userInstitution.setUserMailUuid(mailUuid)) .toList()) .onItem().transformToUniAndMerge(userInstitutionService::persistOrUpdate) + .onItem().invoke(() -> log.debug("UserInstitution updated successfully")) .onItem().transformToMultiAndMerge(userInstitution -> sendKafkaNotification(userResource, userInstitution)); } diff --git a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/util/UserUtils.java b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/util/UserUtils.java index 1428cbe6..05a699a5 100644 --- a/apps/user-ms/src/main/java/it/pagopa/selfcare/user/util/UserUtils.java +++ b/apps/user-ms/src/main/java/it/pagopa/selfcare/user/util/UserUtils.java @@ -56,6 +56,7 @@ public Uni checkProductRole(String productId, PartyRole role, String produ if (StringUtils.isNotBlank(productRole) && StringUtils.isNotBlank(productId)) { try { productService.validateProductRole(productId, productRole, role); + log.debug("Product role {} is valid for product {}", productRole, productId); } catch (IllegalArgumentException e) { throw new InvalidRequestException(e.getMessage()); } diff --git a/apps/user-ms/src/main/resources/application.properties b/apps/user-ms/src/main/resources/application.properties index e678dad4..9628bbc6 100644 --- a/apps/user-ms/src/main/resources/application.properties +++ b/apps/user-ms/src/main/resources/application.properties @@ -13,7 +13,7 @@ smallrye.jwt.claims.groups=USER smallrye.jwt.path.sub=name ## OPEN API ## -uarkus.smallrye-openapi.info-title=User API +quarkus.smallrye-openapi.info-title=User API %dev.quarkus.smallrye-openapi.info-title=User API (development) %uat.quarkus.smallrye-openapi.info-title=User API (test) quarkus.smallrye-openapi.info-version=1.0.0