Hello team,
May I ask if it is possible to see traces for validation?
I am using spring boot and the @Valid annotation, which uses this project to perform the actual validation.
However, there is no observability.
By that I mean, looking at the following code:
@RestController
class HelloController {
@Autowired
HelloService helloService;
@GetMapping("/test")
String justString(@RequestBody @Valid SignupRequest signupRequest) throws InterruptedException {
return helloService.doSomething(signupRequest);
}
@Service
public class HelloService {
@Observed(name = "test.timed", contextualName = "test.span", lowCardinalityKeyValues = {"low", "low"})
public String doSomething(SignupRequest signupRequest) throws InterruptedException {
Thread.sleep(2000);
return "ok";
}
@PasswordMatching(
password = "password",
confirmPassword = "confirmPassword",
message = "Password and Confirm Password must be matched!"
)
record SignupRequest(
@NotBlank
@Size(min = 3, max = 20)
String username,
@NotBlank
@Size(max = 50)
@Email
String email,
String password,
String confirmPassword
) {
}
@Constraint(validatedBy = PasswordMatchingValidator.class)
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@interface PasswordMatching {
String password();
String confirmPassword();
String message() default "Passwords must match!";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
class PasswordMatchingValidator implements ConstraintValidator<PasswordMatching, SignupRequest> {
@Override
public boolean isValid(final SignupRequest signupRequest, final ConstraintValidatorContext constraintValidatorContext) {
return signupRequest.password().equals(signupRequest.confirmPassword());
}
}
I am seeing this trace for “when validation passes” (please see screenshot)
(please note, there is no spring security, I didn’t create any filters, etc, it’s just the http request validation.
rationale:
Http request (payload, headers, etc) validation is very common step of springboot.
However, there is little help provided by the framework to observe this crucial step (it is usually one of the first step).
Would it be possible to instrument observability for the validation step?
Thank you