Register per-repository pattern for observability purposes.

The standard Spring MVC observability integration registers the plain request pattern for observations. For our repository controllers that would result in one pattern registered for all individual repository resources (e.g. /{repository}/{id} etc.). However, the insights users would like to gain rather follows the individual repositories exposed. That's why we have so far exposed repository specific path pattern (/myrepo/{id}) via a custom request attribute. To adhere to the new observability integration of Spring Framework 6, we need to expose that particular pattern on the ServerRequestObservationContext, too.

Fixes #2212.
This commit is contained in:
Oliver Drotbohm
2023-01-09 15:31:57 +01:00
parent 2c8ff9fe04
commit 1bfa83cb73
3 changed files with 51 additions and 4 deletions

View File

@@ -753,6 +753,14 @@ public class JpaWebTests extends CommonWebTests {
.andExpect(status().isOk());
}
@Test // #2212
void exposesRepositoryPatternForObservation() throws Exception {
mvc.perform(get("/authors/42"));
assertThat(observationContext.getPathPattern()).isEqualTo("/authors/{id}");
}
private List<Link> preparePersonResources(Person primary, Person... persons) throws Exception {
Link peopleLink = client.discoverUnique(LinkRelation.of("people"));