Merge branch 'RED-10681' into 'master'
RED-10681: Improve tracing to include metadata ids from RequestBody Closes RED-10681 See merge request redactmanager/persistence-service!905
This commit is contained in:
commit
6d0354946a
@ -135,11 +135,14 @@ public class Application implements ApplicationContextAware {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KeyValues getHighCardinalityKeyValues(ServerRequestObservationContext context) {
|
public KeyValues getHighCardinalityKeyValues(ServerRequestObservationContext context) {
|
||||||
// Make sure that KeyValues entries are already sorted by name for better performance
|
|
||||||
return super.getHighCardinalityKeyValues(context)
|
return super.getHighCardinalityKeyValues(context)
|
||||||
.and(getValueFromPathVariableOrRequestParam(context, "dossierId"),
|
.and(getValueFromPathVariableOrRequestParam(context, "dossierId"),
|
||||||
getValueFromPathVariableOrRequestParam(context, "dossierTemplateId"),
|
getValueFromPathVariableOrRequestParam(context, "dossierTemplateId"),
|
||||||
getValueFromPathVariableOrRequestParam(context, "fileId"));
|
getValueFromPathVariableOrRequestParam(context, "fileId"))
|
||||||
|
.and(getValueFromRequestAttribute(context, "dossierId"),
|
||||||
|
getValueFromRequestAttribute(context, "dossierTemplateId"),
|
||||||
|
getValueFromRequestAttribute(context, "fileId"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -164,6 +167,13 @@ public class Application implements ApplicationContextAware {
|
|||||||
.orElse(""));
|
.orElse(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private KeyValue getValueFromRequestAttribute(ServerRequestObservationContext context, String name) {
|
||||||
|
|
||||||
|
Object value = context.getCarrier().getAttribute(name);
|
||||||
|
return KeyValue.of(name, value == null ? "" : value.toString());
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,94 @@
|
|||||||
|
package com.iqser.red.service.peristence.v1.server;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.core.MethodParameter;
|
||||||
|
import org.springframework.http.HttpInputMessage;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@ControllerAdvice
|
||||||
|
public class GenericRequestBodyAdvice implements RequestBodyAdvice {
|
||||||
|
|
||||||
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(@NonNull MethodParameter methodParameter, @NonNull Type targetType, @NonNull Class<? extends HttpMessageConverter<?>> converterType) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull HttpInputMessage beforeBodyRead(@NonNull HttpInputMessage inputMessage,
|
||||||
|
@NonNull MethodParameter parameter,
|
||||||
|
@NonNull Type targetType,
|
||||||
|
@NonNull Class<? extends HttpMessageConverter<?>> converterType) {
|
||||||
|
|
||||||
|
return inputMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Object afterBodyRead(@NonNull Object body,
|
||||||
|
@NonNull HttpInputMessage inputMessage,
|
||||||
|
@NonNull MethodParameter parameter,
|
||||||
|
@NonNull Type targetType,
|
||||||
|
@NonNull Class<? extends HttpMessageConverter<?>> converterType) {
|
||||||
|
|
||||||
|
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
if (attrs == null) {
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpServletRequest request = attrs.getRequest();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Map<String, Object> bodyMap = objectMapper.convertValue(body, new TypeReference<>() {
|
||||||
|
});
|
||||||
|
|
||||||
|
storeFieldIfPresent(bodyMap, "dossierId", request);
|
||||||
|
storeFieldIfPresent(bodyMap, "dossierTemplateId", request);
|
||||||
|
storeFieldIfPresent(bodyMap, "fileId", request);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object handleEmptyBody(Object body,
|
||||||
|
@NonNull HttpInputMessage inputMessage,
|
||||||
|
@NonNull MethodParameter parameter,
|
||||||
|
@NonNull Type targetType,
|
||||||
|
@NonNull Class<? extends HttpMessageConverter<?>> converterType) {
|
||||||
|
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void storeFieldIfPresent(Map<String, Object> bodyMap, String fieldName, HttpServletRequest request) {
|
||||||
|
|
||||||
|
if (bodyMap.containsKey(fieldName)) {
|
||||||
|
Object value = bodyMap.get(fieldName);
|
||||||
|
if (value != null) {
|
||||||
|
request.setAttribute(fieldName, value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user