davsclaus commented on code in PR #23864:
URL: https://github.com/apache/camel/pull/23864#discussion_r3375125713


##########
components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java:
##########
@@ -73,22 +75,29 @@ default Tags getTags(ExchangeEvent event, Endpoint 
endpoint) {
             }
         }
         String routeId = event.getExchange().getFromRouteId();
-        if (routeId != null) {
-            return Tags.of(
-                    CAMEL_CONTEXT_TAG, 
event.getExchange().getContext().getName(),
-                    KIND, KIND_EXCHANGE,
-                    EVENT_TYPE_TAG, event.getClass().getSimpleName(),
-                    ROUTE_ID_TAG, routeId,
-                    ENDPOINT_NAME, uri,
-                    FAILED_TAG, 
Boolean.toString(event.getExchange().isFailed()));
-        } else {
-            return Tags.of(
-                    CAMEL_CONTEXT_TAG, 
event.getExchange().getContext().getName(),
-                    KIND, KIND_EXCHANGE,
-                    EVENT_TYPE_TAG, event.getClass().getSimpleName(),
-                    ENDPOINT_NAME, uri,
-                    FAILED_TAG, 
Boolean.toString(event.getExchange().isFailed()));
+        if (routeId == null) {
+            final String finalUri = uri;
+            final Optional<Route> eventRoute = 
event.getExchange().getContext().getRoutes().stream()
+                    .filter(route -> 
finalUri.equals(route.getEndpoint().getEndpointBaseUri())).findFirst();
+
+            if (eventRoute.isEmpty()) {
+                return Tags.of(
+                        CAMEL_CONTEXT_TAG, 
event.getExchange().getContext().getName(),
+                        KIND, KIND_EXCHANGE,
+                        EVENT_TYPE_TAG, event.getClass().getSimpleName(),
+                        ENDPOINT_NAME, uri,
+                        FAILED_TAG, 
Boolean.toString(event.getExchange().isFailed()));
+            }
+

Review Comment:
   This route lookup by endpoint URI is problematic:
   
   1. It finds the *destination* route, but `fromRouteId` should be the 
*originating* route
   2. Multiple routes can share the same `from` endpoint — `findFirst()` is 
arbitrary
   3. Iterating all routes on every exchange event doesn't scale
   
   The simpler fix is to always include the `routeId` tag with an empty string 
when null:
   
   ```suggestion
           if (routeId == null) {
               routeId = "";
           }
   ```
   
   This ensures Prometheus always sees the same tag keys, which is the actual 
root cause of the error.



-- 
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