Polish "Disable Micrometer global registry in tests by default"

See gh-51142
This commit is contained in:
Moritz Halbritter
2026-07-29 11:37:35 +02:00
parent c66a5ef94f
commit be35ff4149
10 changed files with 224 additions and 200 deletions
@@ -64,6 +64,9 @@ management:
use-global-registry: false
----
NOTE: In tests that use `spring-boot-micrometer-metrics-test`, the global registry is disabled by default.
If you want to use the global registry in such a test, annotate it with javadoc:org.springframework.boot.micrometer.metrics.test.autoconfigure.AutoConfigureMetrics[format=annotation] using `useGlobalRegistry = true`, or set the configprop:management.metrics.use-global-registry[] property explicitly to `true`.
You can register any number of javadoc:org.springframework.boot.micrometer.metrics.autoconfigure.MeterRegistryCustomizer[] beans to further configure the registry, such as applying common tags, before any meters are registered with the registry:
include-code::commontags/MyMeterRegistryConfiguration[]
@@ -244,6 +244,9 @@ If you need to export metrics to a different backend as part of an integration t
If you annotate xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[a sliced test] with javadoc:org.springframework.boot.micrometer.metrics.test.autoconfigure.AutoConfigureMetrics[format=annotation], it auto-configures an in-memory javadoc:io.micrometer.core.instrument.MeterRegistry[].
Data exporting in sliced tests is not supported with the javadoc:org.springframework.boot.micrometer.metrics.test.autoconfigure.AutoConfigureMetrics[format=annotation] annotation.
Meter registries are not added to the xref:actuator/metrics.adoc#actuator.metrics.getting-started[global registry] by default in tests.
If you need the global registry in a test, annotate it with javadoc:org.springframework.boot.micrometer.metrics.test.autoconfigure.AutoConfigureMetrics[format=annotation] using `useGlobalRegistry = true`, or set the configprop:management.metrics.use-global-registry[] property explicitly to `true`.
[[testing.spring-boot-applications.tracing]]