We have Sleuth enabled on all endpoints Spring 2.7.x ( that comes out of the box). Just plain and simple traceId/spanId tracking. Now as in Spring Sleuth is no more available in Spring Boot 3.0.0. Is there a way to enable this new Observation Api on all endpoints.
Before had this:
/*
List all beers in database
*/
public Mono<ServerResponse> listBeer() {
return beerService.listBeers(null, null, PageRequest.ofSize(50), true)
.flatMap(beerDto -> ServerResponse.ok().bodyValue(beerDto))
.switchIfEmpty(ServerResponse.notFound().build());
}
Now with new Api in every endpoint need to do this:
/*
List all beers in database
*/
public Mono<ServerResponse> listBeer() {
Observation observation = Observation.start("listBeer-sample", observationRegistry);
return Mono.just(observation).flatMap(span -> {
observation.scoped(() -> log.info("I can fetch trace id <TRACE:{}> ",
this.tracer.currentSpan().context().traceId())
);
return beerService.listBeers(null, null, PageRequest.ofSize(50), true)
.flatMap(beerDto -> ServerResponse.ok().bodyValue(beerDto))
.switchIfEmpty(ServerResponse.notFound().build());
}).doFinally(signalType -> observation.stop())
.contextWrite(context -> context.put(ObservationThreadLocalAccessor.KEY, observation));
}
}
Is there a way to enable traceId/spanId out of the box on all endpoints without all of this clutter?