Apply user-provided ObservationConventions in auto-configurations

Prior to this commit, we would advise developers, as migration path from
Spring Boot 2.0-x metrics, to create `GlobalObservationConvention` beans
for the observations they want to customize (observation name or key
values).

`GlobalObservationConvention` are currently applied **in addition** to
the chosen convention in some cases, so this does not work well with
this migration path.

Instead, instrumentations always provide a default convention but also a
way to configure a custom convention for their observations. Spring Boot
should inject custom convention beans in the relevant
auto-configurations.

Fixes gh-33285
This commit is contained in:
Brian Clozel
2022-11-22 20:44:05 +01:00
parent f6ac891cc1
commit 07766c436c
11 changed files with 240 additions and 30 deletions

View File

@@ -769,7 +769,7 @@ By default, Spring MVC related metrics are tagged with the following information
|===
To add to the default tags, provide a `@Bean` that extends `DefaultServerRequestObservationConvention` from the `org.springframework.http.observation` package.
To replace the default tags, provide a `@Bean` that implements `GlobalObservationConvention<ServerRequestObservationContext>`.
To replace the default tags, provide a `@Bean` that implements `ServerRequestObservationConvention`.
TIP: In some cases, exceptions handled in web controllers are not recorded as request metrics tags.
@@ -809,7 +809,7 @@ By default, WebFlux related metrics are tagged with the following information:
|===
To add to the default tags, provide a `@Bean` that extends `DefaultServerRequestObservationConvention` from the `org.springframework.http.observation.reactive` package.
To replace the default tags, provide a `@Bean` that implements `GlobalObservationConvention<ServerRequestObservationContext>`.
To replace the default tags, provide a `@Bean` that implements `ServerRequestObservationConvention`.
TIP: In some cases, exceptions handled in controllers and handler functions are not recorded as request metrics tags.
Applications can opt in and record exceptions by <<web#web.reactive.webflux.error-handling, setting handled exceptions as request attributes>>.