This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 37edb6f1eea7 CAMEL-27987: camel-opentelemetry2 - the dev console dumps
spans with dump=false (#31271)
37edb6f1eea7 is described below
commit 37edb6f1eea70bc31843721806b3f40a1e578a13
Author: Guillaume Nodet <[email protected]>
AuthorDate: Fri Dec 4 09:29:33 2026 +0100
CAMEL-27987: camel-opentelemetry2 - the dev console dumps spans with
dump=false (#31271)
The dump option was checked with optionString(), which treats any
non-null value - including the string "false" - as truthy, so dump=false
dumped the spans instead of returning the count and capacity summary.
Use optionBoolean() so the option is parsed as a boolean, and declare the
dump option as a Boolean with default false in the console metadata.
Clamp the limit with Math.max(0, ...) in the text and JSON output, so a
negative limit no longer throws IllegalArgumentException.
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: Claus Ibsen <[email protected]>
---
.../apache/camel/catalog/dev-consoles-openapi.json | 9 +--
.../camel/catalog/dev-consoles/opentelemetry.json | 11 ++--
.../apache/camel/dev-console/opentelemetry.json | 11 ++--
.../opentelemetry2/OpenTelemetryDevConsole.java | 17 +++--
.../OpenTelemetryDevConsoleTest.java | 72 +++++++++++++++++++++-
5 files changed, 89 insertions(+), 31 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
index 35eacfc83e6f..0b5a2ace804c 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
@@ -5230,14 +5230,11 @@
{
"name": "dump",
"in": "query",
- "description": "Set to list the
latest finished spans instead of the span count and capacity; any value, also
false, lists them",
+ "description": "Whether to list
the latest finished spans instead of the span count and capacity",
"required": false,
"schema": {
- "type": "string",
- "enum": [
- "true",
- "false"
- ]
+ "type": "boolean",
+ "default": false
}
},
{
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/opentelemetry.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/opentelemetry.json
index d136e70cf690..b876dcafe453 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/opentelemetry.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/opentelemetry.json
@@ -20,16 +20,13 @@
"group": "query",
"label": "query",
"required": false,
- "type": "string",
- "javaType": "java.lang.String",
- "enum": [
- "true",
- "false"
- ],
+ "type": "boolean",
+ "javaType": "java.lang.Boolean",
"deprecated": false,
"autowired": false,
"secret": false,
- "description": "Set to list the latest finished spans instead of the
span count and capacity; any value, also false, lists them"
+ "defaultValue": false,
+ "description": "Whether to list the latest finished spans instead of the
span count and capacity"
},
"limit": {
"index": 1,
diff --git
a/components/camel-opentelemetry2/src/generated/resources/META-INF/org/apache/camel/dev-console/opentelemetry.json
b/components/camel-opentelemetry2/src/generated/resources/META-INF/org/apache/camel/dev-console/opentelemetry.json
index d136e70cf690..b876dcafe453 100644
---
a/components/camel-opentelemetry2/src/generated/resources/META-INF/org/apache/camel/dev-console/opentelemetry.json
+++
b/components/camel-opentelemetry2/src/generated/resources/META-INF/org/apache/camel/dev-console/opentelemetry.json
@@ -20,16 +20,13 @@
"group": "query",
"label": "query",
"required": false,
- "type": "string",
- "javaType": "java.lang.String",
- "enum": [
- "true",
- "false"
- ],
+ "type": "boolean",
+ "javaType": "java.lang.Boolean",
"deprecated": false,
"autowired": false,
"secret": false,
- "description": "Set to list the latest finished spans instead of the
span count and capacity; any value, also false, lists them"
+ "defaultValue": false,
+ "description": "Whether to list the latest finished spans instead of the
span count and capacity"
},
"limit": {
"index": 1,
diff --git
a/components/camel-opentelemetry2/src/main/java/org/apache/camel/opentelemetry2/OpenTelemetryDevConsole.java
b/components/camel-opentelemetry2/src/main/java/org/apache/camel/opentelemetry2/OpenTelemetryDevConsole.java
index e4568f5596e8..c7da0770be73 100644
---
a/components/camel-opentelemetry2/src/main/java/org/apache/camel/opentelemetry2/OpenTelemetryDevConsole.java
+++
b/components/camel-opentelemetry2/src/main/java/org/apache/camel/opentelemetry2/OpenTelemetryDevConsole.java
@@ -35,9 +35,8 @@ import org.apache.camel.util.json.JsonRecordSupport;
description = "Lists the OpenTelemetry spans kept in memory in the
dev profile, or their count and capacity")
public class OpenTelemetryDevConsole extends AbstractDevConsole {
- @Metadata(label = "query",
- description = "Set to list the latest finished spans instead of
the span count and capacity; any value, also false, lists them",
- javaType = "java.lang.String", enums = "true,false")
+ @Metadata(label = "query", description = "Whether to list the latest
finished spans instead of the span count and capacity",
+ javaType = "java.lang.Boolean", defaultValue = "false")
public static final String DUMP = "dump";
@Metadata(label = "query", description = "The maximum number of spans to
list, the latest ones", defaultValue = "100",
@@ -79,9 +78,9 @@ public class OpenTelemetryDevConsole extends
AbstractDevConsole {
return "OpenTelemetry in-memory exporter is not enabled (requires
dev profile)\n";
}
- String dump = optionString(options, DUMP);
- if (dump != null) {
- int limit = optionInt(options, LIMIT, 100);
+ boolean dump = optionBoolean(options, DUMP, false);
+ if (dump) {
+ int limit = Math.max(0, optionInt(options, LIMIT, 100));
List<SpanData> spans = exporter.getFinishedSpans();
int start = Math.max(0, spans.size() - limit);
StringBuilder sb = new StringBuilder();
@@ -111,9 +110,9 @@ public class OpenTelemetryDevConsole extends
AbstractDevConsole {
List<SpanEntry> spanEntries = null;
if (exporter != null) {
- String dump = optionString(options, DUMP);
- if (dump != null) {
- int limit = optionInt(options, LIMIT, 100);
+ boolean dump = optionBoolean(options, DUMP, false);
+ if (dump) {
+ int limit = Math.max(0, optionInt(options, LIMIT, 100));
List<SpanData> spans = exporter.getFinishedSpans();
int start = Math.max(0, spans.size() - limit);
List<SpanData> selected = spans.subList(start, spans.size());
diff --git
a/components/camel-opentelemetry2/src/test/java/org/apache/camel/opentelemetry2/OpenTelemetryDevConsoleTest.java
b/components/camel-opentelemetry2/src/test/java/org/apache/camel/opentelemetry2/OpenTelemetryDevConsoleTest.java
index 485467cdfd18..07d67d9427ce 100644
---
a/components/camel-opentelemetry2/src/test/java/org/apache/camel/opentelemetry2/OpenTelemetryDevConsoleTest.java
+++
b/components/camel-opentelemetry2/src/test/java/org/apache/camel/opentelemetry2/OpenTelemetryDevConsoleTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.opentelemetry2;
+import java.util.Map;
+
import org.apache.camel.console.DevConsole;
import org.apache.camel.support.PluginHelper;
import org.apache.camel.test.junit6.CamelTestSupport;
@@ -25,11 +27,12 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
-public class OpenTelemetryDevConsoleTest extends CamelTestSupport {
+class OpenTelemetryDevConsoleTest extends CamelTestSupport {
@Test
- public void testOpenTelemetryConsoleNoExporter() {
+ void testOpenTelemetryConsoleNoExporter() {
DevConsole con =
PluginHelper.getDevConsoleResolver(context).resolveDevConsole("opentelemetry");
assertNotNull(con);
assertEquals("camel", con.getGroup());
@@ -42,4 +45,69 @@ public class OpenTelemetryDevConsoleTest extends
CamelTestSupport {
assertNotNull(out);
assertFalse(out.getBoolean("enabled"));
}
+
+ /**
+ * CAMEL-27987: dump=false must NOT trigger span dumping. The console must
return span count/capacity, not spans.
+ */
+ @Test
+ void testDumpFalseDoesNotDumpSpans() {
+ // Register a DevSpanExporter in the registry (simulates dev profile)
+ DevSpanExporter exporter = new DevSpanExporter();
+ context.getRegistry().bind("DevSpanExporter", exporter);
+
+ DevConsole con =
PluginHelper.getDevConsoleResolver(context).resolveDevConsole("opentelemetry");
+ assertNotNull(con);
+
+ // TEXT: dump=false must NOT output span lines; it should output the
count/capacity summary
+ String text = (String) con.call(DevConsole.MediaType.TEXT,
Map.of(OpenTelemetryDevConsole.DUMP, "false"));
+ assertNotNull(text);
+ assertFalse(text.contains("TraceId:"),
+ "dump=false must not dump spans, but got: " + text);
+ // Should show the summary instead
+ assertFalse(text.isBlank(), "Summary must not be blank");
+
+ // JSON: dump=false must NOT return a spans array; it must return
spanCount + capacity
+ JsonObject out = (JsonObject) con.call(DevConsole.MediaType.JSON,
Map.of(OpenTelemetryDevConsole.DUMP, "false"));
+ assertNotNull(out);
+ assertNull(out.get("spans"), "dump=false must not include spans in
JSON response");
+ assertNotNull(out.get("spanCount"), "dump=false must include spanCount
in JSON response");
+ assertNotNull(out.get("capacity"), "dump=false must include capacity
in JSON response");
+ }
+
+ /**
+ * CAMEL-27987: dump=true must trigger span dumping.
+ */
+ @Test
+ void testDumpTrueDumpsSpans() {
+ DevSpanExporter exporter = new DevSpanExporter();
+ context.getRegistry().bind("DevSpanExporter", exporter);
+
+ DevConsole con =
PluginHelper.getDevConsoleResolver(context).resolveDevConsole("opentelemetry");
+ assertNotNull(con);
+
+ // JSON: dump=true must return spans array (empty since no spans were
exported)
+ JsonObject out = (JsonObject) con.call(DevConsole.MediaType.JSON,
Map.of(OpenTelemetryDevConsole.DUMP, "true"));
+ assertNotNull(out);
+ assertNull(out.get("spanCount"), "dump=true must not include
spanCount");
+ assertNull(out.get("capacity"), "dump=true must not include capacity");
+ // spans key must be present (empty list when no spans)
+ assertNotNull(out.get("spans"), "dump=true must include spans in JSON
response");
+ }
+
+ /**
+ * CAMEL-27987: negative limit must not cause IllegalArgumentException in
subList.
+ */
+ @Test
+ void testNegativeLimitDoesNotThrow() {
+ DevSpanExporter exporter = new DevSpanExporter();
+ context.getRegistry().bind("DevSpanExporter", exporter);
+
+ DevConsole con =
PluginHelper.getDevConsoleResolver(context).resolveDevConsole("opentelemetry");
+ assertNotNull(con);
+
+ // Must not throw IllegalArgumentException
+ JsonObject out = (JsonObject) con.call(DevConsole.MediaType.JSON,
+ Map.of(OpenTelemetryDevConsole.DUMP, "true",
OpenTelemetryDevConsole.LIMIT, "-1"));
+ assertNotNull(out);
+ }
}