etzel-mes opened a new pull request, #30220:
URL: https://github.com/apache/camel/pull/30220

   # Description
   
   `MicrometerRoutePolicy` and `OpenTelemetryRoutePolicy` both keep the timer 
of an exchange in the exchange property 
`camel.route.policy-<routeId>-<exchangeId>`, named after the meter name that 
the two modules share. With both policies on one route (for example Camel Main 
with `camel.metrics.enabled=true` plus an `OpenTelemetryRoutePolicyFactory`), 
each overwrites the timer of the other, and the policy that finishes first 
fails with a `ClassCastException`, which `RoutePolicyAdvice` logs as a WARN for 
every exchange:
   
   ```
   java.lang.ClassCastException: class 
org.apache.camel.opentelemetry.metrics.TaskTimer cannot be cast to class 
io.micrometer.core.instrument.Timer$Sample
        at 
org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicy$MetricsStatistics.onExchangeDone(MicrometerRoutePolicy.java:139)
        at 
org.apache.camel.component.micrometer.routepolicy.ContextMetricsStatistics.onExchangeDone(ContextMetricsStatistics.java:65)
   ```
   
   Each policy now names the property after itself, as the camel-metrics route 
policy does (`MetricsRoutePolicy-<routeId>`):
   
   ```diff
    propertyName(exchange)
   -  "camel.route.policy-" + id + "-" + exchangeId          // both policies
   +  "MicrometerRoutePolicy-" + id + "-" + exchangeId       // camel-micrometer
   +  "OpenTelemetryRoutePolicy-" + id + "-" + exchangeId    // 
camel-opentelemetry-metrics
   ```
   
   Only the two policies read these properties, and the meter names do not 
change. The exchange event notifiers already use different property names 
(`eventTimer:` and `elapsedTimer:`).
   
   Test: `OpenTelemetryAndMicrometerRoutePolicyTest` 
(camel-opentelemetry-metrics, with camel-micrometer as a test dependency) adds 
both route policy factories, sends one exchange and checks the route and 
CamelContext timers of both policies:
   
   | timer | before | after |
   |---|---|---|
   | Micrometer route | missing | 1 |
   | Micrometer CamelContext | missing | 1 |
   | OpenTelemetry route | 1 | 1 |
   | OpenTelemetry CamelContext | missing | 1 |
   
   With the OpenTelemetry policy first, the cast fails the other way round 
(checked by hand); the test keeps the order of Camel Main, where the Micrometer 
policy comes first.
   
   The route policy tests of both modules and the integration tests of 
camel-opentelemetry-metrics pass. `mvn clean install -DskipTests` from the root 
folder was not run on this machine; the two modules were built with the 
formatter, and the change feeds no generator.
   
   cc @davsclaus @squakez
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   
   - [x] [CAMEL-27071](https://issues.apache.org/jira/browse/CAMEL-27071)
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes. (Only the two changed modules 
were built; see above.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   Written with Claude Code (Claude Opus 5.5); the change was reviewed by a 
separate Claude Opus run.
   
   _Claude Code on behalf of etzel-mes_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to