Serdar Gökay created CAMEL-27071:
------------------------------------
Summary: camel-micrometer / camel-opentelemetry-metrics - Both
route policies on one route fail with ClassCastException, as they share an
exchange property name
Key: CAMEL-27071
URL: https://issues.apache.org/jira/browse/CAMEL-27071
Project: Camel
Issue Type: Bug
Components: camel-micrometer, camel-opentelemetry
Affects Versions: 4.23.0
Reporter: Serdar Gökay
The Micrometer and the OpenTelemetry metrics route policies can both measure
the same route, for example Camel Main with {{camel.metrics.enabled=true}} plus
an {{OpenTelemetryRoutePolicyFactory}} added to the CamelContext. They then
overwrite each other's per-exchange timer: {{MicrometerRoutePolicy}} and
{{OpenTelemetryRoutePolicy}} both keep it in the exchange property
{{camel.route.policy-<routeId>-<exchangeId>}} (and {{..._long_task}}), as both
build the name from the meter name {{camel.route.policy}}, which the two
modules share.
When the exchange is done, the policy that runs first casts the other policy's
timer:
{noformat}
WARN Error occurred during onExchangeDone on RoutePolicy:
org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicy@67c5ac52.
This exception will be ignored
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)
at
org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicy.onExchangeDone(MicrometerRoutePolicy.java:373)
at
org.apache.camel.impl.engine.CamelInternalProcessor$RoutePolicyAdvice.after(CamelInternalProcessor.java:746)
{noformat}
This is logged for every exchange. The policy that runs first records nothing
for the exchange, and the other one loses its CamelContext timer, as the
property is already gone. With {{longTask}} enabled, the long task of the first
policy is never stopped either. With the OpenTelemetry policy first, the same
happens the other way round ({{Timer$Sample}} cannot be cast to {{TaskTimer}}).
It is there since the OpenTelemetry route policy was added (CAMEL-16866,
4.17.0), and still on main.
Proposed change: name the property after the policy,
{{MicrometerRoutePolicy-<routeId>-<exchangeId>}} and
{{OpenTelemetryRoutePolicy-<routeId>-<exchangeId>}}, as the camel-metrics route
policy does ({{MetricsRoutePolicy-<routeId>}}). Only the policies themselves
read these properties. The exchange event notifiers already use different names
({{eventTimer:}} and {{elapsedTimer:}}). A test with both route policy
factories on one route and one exchange misses three of the four timers before
the change and passes after it; I can open the PR.
_Claude Code on behalf of etzel-mes_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)