gnodet commented on code in PR #31365:
URL: https://github.com/apache/camel/pull/31365#discussion_r4802552151


##########
components/camel-opentelemetry-metrics/src/test/java/org/apache/camel/opentelemetry/metrics/CounterRouteTest.java:
##########
@@ -97,6 +97,10 @@ public void configure() {
                 from("direct:in10")
                         
.to("opentelemetry-metrics:counter:J?attributes.a=${body.length}&attributes.b=uri")
                         .to("mock:result");
+
+                from("direct:in11")
+                        
.to("opentelemetry-metrics:counter:K?increment=${body.missing}")

Review Comment:
   Fixed: changed the route to `attributes.a=${body.missing}`, which is 
evaluated in `AbstractOpenTelemetryProducer.process()` — the code this PR moved 
into the `try` block.
   
   _Claude Code on behalf of Guillaume Nodet_



##########
components/camel-opentelemetry-metrics/src/test/java/org/apache/camel/opentelemetry/metrics/CounterRouteTest.java:
##########
@@ -345,6 +349,30 @@ public void 
testHeaderAttributeOverridesUriAttributeWithSameKey() throws Excepti
         MockEndpoint.assertIsSatisfied(context);
     }
 
+    @Test
+    public void testHeadersAreClearedEvenWhenExpressionFails() throws 
Exception {
+        MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
+        mockEndpoint.expectedMessageCount(0);
+
+        // Set headers that should be cleared even when the expression fails
+        Map<String, Object> headers = Map.of(
+                HEADER_METRIC_NAME, "CustomName",
+                HEADER_COUNTER_INCREMENT, 100L,
+                HEADER_METRIC_ATTRIBUTES, 
Attributes.of(AttributeKey.stringKey("test"), "value"),
+                "normalHeader", "keepThis");
+
+        // Verify that an exception is thrown when the expression fails
+        // (The specific exception type may vary - 
RuntimeBeanExpressionException for bean access,
+        // IllegalArgumentException for null values, etc.)
+        assertThrows(CamelExecutionException.class,
+                () -> template.sendBodyAndHeaders("direct:in11", 
Map.of("count", 5), headers));
+
+        // The important part: verify that no metric was recorded despite the 
headers being set
+        // (this confirms that the error occurred and headers were cleaned up 
properly)
+        assertNull(findMetric("K"));

Review Comment:
   Fixed: the test now uses `template.send()` to get the exchange back, and 
asserts that all `CamelMetrics*` headers are removed while `normalHeader` is 
kept. Also added the upgrade guide entry and component doc update for the 
summary behavior change.
   
   _Claude Code on behalf of Guillaume Nodet_



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