If we focus back on the Metrics library, we will find several CDI integrations. The global idea is to decorate the code with some annotation and automatically get the metrics associated with the executed code. Clearly, it will impact your code this way (using https://github.com/astefanutti/metrics-cdi for instance):
@Transactional@ApplicationScopedpublic class QuoteService { @PersistenceContext private EntityManager entityManager; @Timed(name = "create") public Quote create(final Quote newQuote) { entityManager.persist(newQuote); entityManager.flush(); return newQuote; }}
The @Timed annotation will automatically wrap the method execution in a Metrics timer and will therefore provide the statistics about the execution time ...