MeterRegistry closes HighCardinalityTagsDetector twice if the registry is closed twice (original) (raw)
I am using Micrometer 1.17.0-M3 via Spring Boot 4.1.0-M3, but this problem exists prior to this.
Spring Boot calls close() on the MeterRegistry as part of application shutdown and then calls it again because it is a bean with a close() method. See this Spring Boot issue. This causes multiple log output statements when a HighCardinalityTagsDetector is configured. This is exacerbated by having multiple meter registries configured with a detector.
This seems benign, but the multiple logs makes it appear as though there are more detector instances being shutdown than actually are which leads to confusion.
In MeterRegistry.close(), the detector close method is called outside the if closed conditional. Not sure if this is intentional or not.
public void close() { if (closed.compareAndSet(false, true)) { synchronized (meterMapLock) { for (Meter meter : meterMap.values()) { meter.close(); } } }
if (highCardinalityTagsDetector != null) { highCardinalityTagsDetector.close(); // This method outputs the log statement } }
Log output
2026-04-16T16:08:11.890-06:00 INFO 68464 --- [demo] [ionShutdownHook] i.m.c.i.HighCardinalityTagsDetector : Stopping HighCardinalityTagsDetector
2026-04-16T16:08:11.891-06:00 INFO 68464 --- [demo] [ionShutdownHook] o.s.boot.tomcat.GracefulShutdown : Commencing graceful shutdown. Waiting for active requests to complete
2026-04-16T16:08:13.907-06:00 INFO 68464 --- [demo] [tomcat-shutdown] o.s.boot.tomcat.GracefulShutdown : Graceful shutdown complete
2026-04-16T16:08:13.917-06:00 INFO 68464 --- [demo] [ionShutdownHook] i.m.c.i.HighCardinalityTagsDetector : Stopping HighCardinalityTagsDetector
Log output with two meter registries configured in Spring Boot
2026-04-16T16:41:46.250-06:00 INFO 77024 --- [demo] [ionShutdownHook] i.m.c.i.HighCardinalityTagsDetector : Stopping HighCardinalityTagsDetector
2026-04-16T16:41:46.250-06:00 INFO 77024 --- [demo] [ionShutdownHook] i.m.c.i.HighCardinalityTagsDetector : Stopping HighCardinalityTagsDetector
2026-04-16T16:41:46.250-06:00 INFO 77024 --- [demo] [ionShutdownHook] i.m.c.i.HighCardinalityTagsDetector : Stopping HighCardinalityTagsDetector
2026-04-16T16:41:46.251-06:00 INFO 77024 --- [demo] [ionShutdownHook] i.m.c.i.HighCardinalityTagsDetector : Stopping HighCardinalityTagsDetector
2026-04-16T16:41:46.251-06:00 INFO 77024 --- [demo] [ionShutdownHook] i.m.c.i.HighCardinalityTagsDetector : Stopping HighCardinalityTagsDetector
2026-04-16T16:41:46.251-06:00 INFO 77024 --- [demo] [ionShutdownHook] o.s.boot.tomcat.GracefulShutdown : Commencing graceful shutdown. Waiting for active requests to complete
2026-04-16T16:41:48.274-06:00 INFO 77024 --- [demo] [tomcat-shutdown] o.s.boot.tomcat.GracefulShutdown : Graceful shutdown complete
2026-04-16T16:41:48.283-06:00 INFO 77024 --- [demo] [ionShutdownHook] i.m.c.i.HighCardinalityTagsDetector : Stopping HighCardinalityTagsDetector
2026-04-16T16:41:48.283-06:00 INFO 77024 --- [demo] [ionShutdownHook] i.m.c.i.HighCardinalityTagsDetector : Stopping HighCardinalityTagsDetector
2026-04-16T16:41:48.284-06:00 INFO 77024 --- [demo] [ionShutdownHook] i.m.c.i.HighCardinalityTagsDetector : Stopping HighCardinalityTagsDetector
2026-04-16T16:41:48.284-06:00 INFO 77024 --- [demo] [ionShutdownHook] i.m.c.i.HighCardinalityTagsDetector : Stopping HighCardinalityTagsDetector
2026-04-16T16:41:48.284-06:00 INFO 77024 --- [demo] [ionShutdownHook] i.m.c.i.HighCardinalityTagsDetector : Stopping HighCardinalityTagsDetector
Seems like the detector should be closed inside the if block where the closed flag is checked, or the logic in the detector close method should have similar logic guarding the close.
public void close() { if (closed.compareAndSet(false, true)) { synchronized (meterMapLock) { for (Meter meter : meterMap.values()) { meter.close(); } } if (highCardinalityTagsDetector != null) { highCardinalityTagsDetector.close(); } } }
Please consider fixing this to prevent unnecessary confusion and wasting time investigating why it is being output multiple times.