micrometer-metrics / micrometer

An application observability facade for the most popular observability tools. Think SLF4J, but for observability.
https://micrometer.io
Apache License 2.0
4.39k stars 965 forks source link

Test duplicate stops on observations #5239

Open bclozel opened 4 days ago

bclozel commented 4 days ago

While working on a Spring Framework instrumentation problem, I have noticed that my instrumentation could in some cases call observation.stop() twice. This is not an intended usage and is considered as a bug in the instrumentation.

In production, calling stop() multiple times on an observation will result in calling observation handlers multiple times. In case of metrics, this will create duplicate records for the same observation (it will be counted twice). I have tried to replicate this case and test against it in my test suite, but failed to do that. Right now "micrometer-observation-test" allows to check whether an observation has been closed. In case of multiple stop() calls, I couldn't find a way to detect this case with the TestObservationRegistry.

I understand that introducing additional state checks in observations would likely create a performance degradation - testing this case would help instrumentations.