-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the bug
We are using micrometer in a spring boot application and have tests in place for our micrometer trace instrumentation. After (implicitly) updating micrometer from 1.13.8 to 1.14.2, a few of our tests fail due to InvalidObservationException being thrown. Tracing this down, the reason is the newly introduced ObservationValidator.
Note that the issue is in the micrometer test jar, not in the micrometer productive code.
The error message is "Invalid stop: Observation 'xxx' has already been stopped"
The underlying reason why "stop" is tried to be executed "twice" is probably that MicrometerObservationListener (which is not in the test jar) does an observation.stop in it's doOnCancel method (the same as in it's doOnComplete). It seems that the spring boot reactive framework does not guarantee that doOnStop and doOnCancel are always called mutually exclusive. Note that the situation only occurs in a few test cases where the request is terminated by an Exception or using skipWhile on a Flux which seems to indicate that the onCancel is issued by the spring framework when disposing the request.
Environment
Spring boot 3.4.1 with managed micrometer version 1.14.2
- Micrometer version 1.14.2
- Micrometer registry dynatrace
- OS: windows/linux
- Java version: 17
To Reproduce
How to reproduce the bug:
Hard to provide a test case short of our application.
Expected behavior
Adding micrometer test must not break existing productive code. A quick solution might be to allow to create a TestObservationRegistry that does not include the ObservationValidator by default. Alternatively, allowing to pass an alternative Consumer<ValidationResult> instead of throwInvalidObservationException might be an option so that validation results could be checked by the consuming tests.
Additional context
Add any other context about the problem here, e.g. related issues.