orpiske commented on code in PR #151: URL: https://github.com/apache/camel-quarkus-examples/pull/151#discussion_r1247795900
########## observability/README.adoc: ########## @@ -19,18 +19,88 @@ workspace. Any modifications in your project will automatically take effect in t TIP: Please refer to the Development mode section of https://camel.apache.org/camel-quarkus/latest/first-steps.html#_development_mode[Camel Quarkus User guide] for more details. +=== How to enable metrics +To enable observability features in Camel, we need to add some additional dependencies to the project's pom.xml file. +The most important one (see link:pom.xml#L97-L100[pom.xml]): + +[source, xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-micrometer</artifactId> +</dependency> +---- + +After adding this dependency, you can benefit from both https://camel.apache.org/components/3.20.x/micrometer-component.html[Camel Micrometer] and https://quarkus.io/guides/micrometer[Quarkus Micrometer] worlds. +We are able to use multiple ways how to achieve create meters for our custom metrics. + +First of them is using Camel micrometer component (see link:src/main/java/org/acme/observability/Routes.java[Routes.java]): + +[source, java] +---- +.to("micrometer:counter:org.acme.observability.greeting-provider?tags=type=events,purpose=example") +---- + +which will count each call to `platform-http:/greeting-provider` endpoint. + +Second approach is to benefit from auto-injected `MeterRegistry` (see link:src/main/java/org/acme/observability/Routes.java#L28[injection]) and use it directly (see link:src/main/java/org/acme/observability/Routes.java#L36[registry call]): + +[source, java] +---- +registry.counter("org.acme.observability.greeting", "type", "events", "purpose", "example").increment(); +---- + +which will count each call to `from("platform-http:/greeting")` endpoint. + +Finally last approach is to use Micrometer annotations (see https://quarkus.io/guides/micrometer#does-micrometer-support-annotations[which] are supported by Quarkus) by defining bean link:src/main/java/org/acme/observability/micrometer/TimerCounter.java[TimerCounter.java] as follows: + +[source, java] +---- +@ApplicationScoped +@Named("timerCounter") +public class TimerCounter { + + @Counted(value = "org.acme.observability.timer-counter", extraTags = { "purpose", "example" }) + public void count() { + } +} +---- + +and invoking it from Camel via (see link:src/main/java/org/acme/observability/TimerRoute.java[TimerRoute.java]): + +[source, java] +---- +.bean("timerCounter", "count") +---- +It will count each timer fire. Review Comment: Maybe you can rephrase it as: "It will count each time the timer is fired?" -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org