gnodet-bot commented on code in PR #26626:
URL: https://github.com/apache/camel/pull/26626#discussion_r4056792180


##########
core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultMessageHistoryFactory.java:
##########
@@ -65,6 +67,16 @@ public MessageHistory newMessageHistory(String routeId, 
NamedNode node, Exchange
 
         DefaultMessageHistory answer = new DefaultMessageHistory(routeId, 
node, msg);
         answer.setAcceptDebugger(node.acceptDebugger(exchange));
+        // the body's type and size as it reaches the node: the type is one 
class lookup, the size is the message
+        // size strategy's (lengths only, no reading or conversion) and only 
when that is enabled (CAMEL-24844)
+        Message current = exchange.getMessage();
+        Object body = current.getBody();
+        // a null body is a fact worth showing (a timer route has none), not 
the same as "not captured"
+        answer.setBodyType(body != null ? 
ObjectHelper.classCanonicalName(body) : "null");
+        MessageSizeStrategy sizeStrategy = camelContext != null ? 
camelContext.getMessageSizeStrategy() : null;

Review Comment:
   ⚠️ **Gap: capture only wired in this factory**
   
   `MetricsMessageHistoryFactory`, `MicrometerMessageHistoryFactory`, and 
`OpenTelemetryMessageHistoryFactory` each call `newMessageHistory()` and return 
a `DefaultMessageHistory` subclass — but none of them call 
`setBodyType()`/`setBodySize()`. Their history rows will always show an empty 
body-type and size (-1), silently.
   
   All three factories follow the same pattern:
   ```java
   return new MetricsMessageHistory(routeId, node, timer, msg);
   // → extends DefaultMessageHistory, bodyType = null, bodySize = -1
   ```
   
   The fix is to extract a static helper here (or in `DefaultMessageHistory`) 
that the other three factories can call after constructing their objects:
   ```java
   public static void captureBodyInfo(DefaultMessageHistory history, Exchange 
exchange, CamelContext ctx) {
       Message current = exchange.getMessage();
       Object body = current.getBody();
       history.setBodyType(body != null ? ObjectHelper.classCanonicalName(body) 
: "null");
       MessageSizeStrategy sizeStrategy = ctx != null ? 
ctx.getMessageSizeStrategy() : null;
       if (sizeStrategy != null && sizeStrategy.isEnabled()) {
           history.setBodySize(sizeStrategy.computeBodySize(current));
       }
   }
   ```
   Then each alternative factory calls this helper after constructing its 
history object. The feature is otherwise invisible to users of Micrometer or 
OpenTelemetry metrics.



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