Skip to content

[Enhancement request] observability for request validation #34356

@patpatpat123

Description

@patpatpat123

Hello team,

May I ask if it is possible to see traces for springboot-starter-validation and the @Valid of the http request?

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)

Image

(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

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions