Add configuration property to enable micrometer annotations

Prior to this commit, the Micrometer annotations support (`@Timed`,
`@Counted`...) was guarded by the presence of both Micrometer and
AspectJ on the classpath.

This signal is too weak, considering the startup performance impact and
the fact that the AspectJ dependency can be brought transitively in many
cases.

This commit adds a new `micrometer.observations.annotations.enabled`
property that is set to `false` by default to only process the
annotations support when this property is enabled.

Fixes gh-39128
This commit is contained in:
Brian Clozel
2024-01-15 13:51:15 +01:00
parent 8bdaae37b0
commit 46b7bd2f23
9 changed files with 56 additions and 9 deletions

View File

@@ -1067,7 +1067,8 @@ Metrics for Jetty's `Connector` instances are bound by using Micrometer's `Jetty
[[actuator.metrics.supported.timed-annotation]]
==== @Timed Annotation Support
To use `@Timed` where it is not directly supported by Spring Boot, refer to the {micrometer-concepts-docs}#_the_timed_annotation[Micrometer documentation].
To enable scanning of `@Timed` annotations, you will need to set the configprop:micrometer.observations.annotations.enabled[] property to `true`.
Please refer to the {micrometer-concepts-docs}#_the_timed_annotation[Micrometer documentation].

View File

@@ -85,3 +85,11 @@ NOTE: Spring Boot does not provide auto-configuration for OpenTelemetry metrics
OpenTelemetry tracing is only auto-configured when used together with <<actuator#actuator.micrometer-tracing, Micrometer Tracing>>.
The next sections will provide more details about logging, metrics and traces.
[[actuator.observability.annotations]]
=== Micrometer Observation Annotations support
To enable scanning of metrics and tracing annotations like `@Timed`, `@Counted`, `@MeterTag` and `@NewSpan` annotations, you will need to set the configprop:micrometer.observations.annotations.enabled[] property to `true`.
This feature is supported Micrometer directly, please refer to the {micrometer-concepts-docs}#_the_timed_annotation[Micrometer] and {micrometer-tracing-docs}/api.html#_aspect_oriented_programming[Micrometer Tracing] reference docs.

View File

@@ -109,6 +109,7 @@
:micrometer-docs: https://micrometer.io/docs
:micrometer-concepts-docs: {micrometer-docs}/concepts
:micrometer-registry-docs: {micrometer-docs}/registry
:micrometer-tracing-docs: https://docs.micrometer.io/tracing/reference
:tomcat-docs: https://tomcat.apache.org/tomcat-{tomcat-version}-doc
:graal-version: 22.3
:graal-native-image-docs: https://www.graalvm.org/{graal-version}/reference-manual/native-image