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 b730c2ec730d chore: camel-jbang - an agent reads the Inspect history
without the tab being opened, and is told it holds one message (#31085)
b730c2ec730d is described below
commit b730c2ec730d77b1449621910ee241993a23be71
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 30 09:33:55 2026 +0100
chore: camel-jbang - an agent reads the Inspect history without the tab
being opened, and is told it holds one message (#31085)
The Inspect tab reads the message history when it opens (since
e24a751a5ec9), so tui_get_history and tui_get_table
gave an agent an empty list unless the user had opened the tab, with no
reason. The AI panel question runs called it
10 times and always got "rows": [].
- A read of the Inspect tab while it is not shown reads the history and the
traces first. While it is shown, the
reader gets the view the user sees.
- The History view says that it holds only the last completed message (the
exchange that finished last, with the
routes it reached downstream), and that the Traces view keeps many recent
exchanges when message tracing is on. An
empty history says why it can be empty.
- The tui_get_history description says the same.
- The Inspect help and the TUI observe page say the same, and show the
columns the two views have. Tracing for the
Traces view is camel run --backlog-trace or camel trace --action=start:
camel run --trace only logs to the console.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../ROOT/pages/camel-jbang-tui-observe.adoc | 25 ++++-
.../core/commands/tui/DataRefreshService.java | 3 +-
.../dsl/jbang/core/commands/tui/HistoryTab.java | 28 ++++++
.../dsl/jbang/core/commands/tui/McpFacade.java | 5 +
.../core/commands/tui/TuiToolDefinitions.java | 5 +-
.../src/main/resources/tui/help/history.md | 71 +++++++------
.../commands/tui/McpFacadeHistoryReadTest.java | 110 +++++++++++++++++++++
7 files changed, 209 insertions(+), 38 deletions(-)
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-observe.adoc
b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-observe.adoc
index 1ab94af1e54c..714bd3e4b021 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-observe.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-observe.adoc
@@ -100,8 +100,11 @@ image::jbang/camel-tui-inspect.png[Inspect tab showing
message history and excha
=== History of Last Exchange
-When you open the Inspect tab, it shows the last completed exchange. The top
panel lists
-every processing step with:
+When you open the Inspect tab, it shows the last completed message: the
exchange that finished last, with the steps
+of the routes it reached downstream (over direct, seda, kafka, and so on).
Only that one message is kept: the next one
+that completes replaces it. To see many recent exchanges, turn on tracing (see
<<_live_tracing,Live Tracing>>).
+
+The top panel lists every processing step with:
* *Step number* and direction (--> or <--)
* *Route* and *Node ID* of the processor
@@ -152,14 +155,26 @@ routed through direct, seda, or kafka endpoints between
routes.
=== Live Tracing
-When you run your integration with tracing enabled:
+Run your integration with backlog tracing enabled:
[source,bash]
----
-camel run my-route.yaml --trace
+camel run my-route.yaml --backlog-trace
----
-The Inspect tab gains a live trace panel showing every exchange as it flows
through the system.
+Or turn tracing on (and off) for an integration that is already running:
+
+[source,bash]
+----
+camel trace --action=start
+camel trace --action=stop
+----
+
+NOTE: `camel run --trace` is not the same: it only logs each step to the
console, and the Inspect tab does not show
+those traces.
+
+The Inspect tab gains a live trace panel showing the recent exchanges as they
flow through the system: many of them,
+not just the last one (up to 200 trace steps across them; the oldest go first).
Each exchange is listed with its timestamp, starting route, status
(Processing/Done/Failed),
elapsed time, and step count. Press *Enter* to drill into an exchange and see
every processor
step -- the same step-by-step view and diagram replay work here too.
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DataRefreshService.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DataRefreshService.java
index f8b8a34d1270..08f14b8b2ab9 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DataRefreshService.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DataRefreshService.java
@@ -53,7 +53,8 @@ class DataRefreshService {
private static final long VANISH_DURATION_MS = 6000;
private static final long LIVENESS_CHECK_INTERVAL_MS = 30_000;
- private static final int MAX_TRACES = 200;
+ // the trace steps kept, of all exchanges together (the Inspect tab's
Traces view groups them by exchange)
+ static final int MAX_TRACES = 200;
/**
* Callback interface for operations that remain in {@link CamelMonitor}
(UI state queries needed during refresh).
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HistoryTab.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HistoryTab.java
index c19fa55c5ad7..e00a71dc2e7d 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HistoryTab.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HistoryTab.java
@@ -747,6 +747,20 @@ class HistoryTab extends AbstractTab {
data.refreshTraceData(pids);
}
+ /**
+ * Reads the history and the traces of the selected integration, for a
caller that reads the tab while it is not
+ * shown (the AI panel, an MCP client): the tab itself reads them only
when it opens, and while it is shown.
+ */
+ void loadForRead() {
+ DataRefreshService data = ctx.dataService;
+ List<Long> pids = data != null ? data.selectedPidAsList() : List.of();
+ if (pids.isEmpty()) {
+ return;
+ }
+ historyEntries = data.loadHistoryData(pids);
+ data.refreshTraceData(pids);
+ }
+
/**
* The Diagram view draws the exchange of the history as it was when the
view opened: when the history was read
* again and is another exchange now, the diagram is drawn for that one,
so the screen and the table agree
@@ -2586,7 +2600,21 @@ class HistoryTab extends AbstractTab {
result.put("totalRows", entries.size());
Integer sel = historyTableState.selected();
result.put("selectedIndex", sel != null ? sel : -1);
+ result.put("note", entries.isEmpty() ? HISTORY_EMPTY_NOTE :
HISTORY_NOTE);
}
return result;
}
+
+ // the message history holds one message
(BacklogTracer.getLatestMessageHistory: replaced when the route that started
+ // a message finishes, with the routes it reached downstream by the same
breadcrumb): say so, as a reader asking
+ // about several messages would otherwise take the steps of one for all of
them
+ private static final String TRACES_KEPT = "with message tracing on, the
Traces view keeps many recent exchanges, not"
+ + " just one (up to " +
DataRefreshService.MAX_TRACES
+ + " trace steps across them).";
+ static final String HISTORY_NOTE = "These are the steps of the last
completed message only: the exchange that"
+ + " finished last, with the routes it
reached downstream. Earlier messages are"
+ + " not kept here; " + TRACES_KEPT;
+ static final String HISTORY_EMPTY_NOTE = "The message history is empty: no
message has completed yet, or the"
+ + " integration records no
message history. It holds only the last"
+ + " completed message; " +
TRACES_KEPT;
}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/McpFacade.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/McpFacade.java
index e0b9fcf597c7..ac3496866dc9 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/McpFacade.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/McpFacade.java
@@ -752,6 +752,11 @@ class McpFacade {
if (tab != null && tab == tabRegistry.overviewTab() && bridge != null
&& bridge.activeTab() != tab) {
awaitFullScan();
}
+ // Inspect reads the history when it opens: read it now when the tab
is not shown (when shown, the reader gets
+ // the view the user sees)
+ if (tab instanceof HistoryTab history && (bridge == null ||
bridge.activeTab() != tab)) {
+ history.loadForRead();
+ }
return tab != null ? awaitTableData(tab, ON_DEMAND_LOAD_TIMEOUT_MS) :
null;
}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiToolDefinitions.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiToolDefinitions.java
index cac1f7426bc3..1a38329cb417 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiToolDefinitions.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiToolDefinitions.java
@@ -373,7 +373,10 @@ final class TuiToolDefinitions {
"tui_get_history",
"Trace and history data of the Inspect tab with all exchange
details (body and headers with types, "
+ "properties, variables, thread, source
location, node labels); richer than "
- + "tui_get_table. The shape follows the
tab's mode: traces, trace steps or history.",
+ + "tui_get_table. The shape follows the
tab's mode: traces, trace steps or history. "
+ + "The history holds only the last
completed message (with the routes it reached "
+ + "downstream); the traces, when message
tracing is on, keep many recent exchanges "
+ + "(up to " + DataRefreshService.MAX_TRACES
+ " trace steps across them).",
Map.of("exchangeId", propDef("string",
"Trace steps of this exchange (the tab's view does not
change); otherwise the current Inspect tab view"))),
r::callGetHistory, READ_ONLY, CORE));
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/history.md
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/history.md
index d850be03b8d7..fbec99e4ac9a 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/history.md
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/history.md
@@ -1,37 +1,46 @@
# Inspect
-The Inspect tab shows a history of recently processed exchanges
-(messages). This is one of the most powerful debugging tools — it
-lets you see exactly what happened to each message as it traveled
-through the integration, including every step it passed through.
-
-Camel uses a BacklogTracer to record exchange details. The most
-recent exchanges are kept in memory for inspection.
-
-## Exchange List
-
-- **ID** — Unique exchange identifier (e.g., `ID-myhost-1234-5`). Every
message passing through Camel gets a unique ID
-- **STATUS** — Whether the exchange completed successfully (`done`) or failed
(`fail`). Failed exchanges also appear on the Errors tab
-- **ROUTE** — The route that processed this exchange
-- **AGO** — How long ago this exchange was processed (e.g., `2s`, `1m`, `5m`)
-- **ELAPSED** — Total processing time from when the exchange entered the route
until it completed. Long elapsed times may indicate slow downstream services
-
-## Example Screen
-
-```
- ID STATUS ROUTE AGO ELAPSED
- ID-myhost-1234-10 done timer-to-log 1s 0ms
- ID-myhost-1234-9 done seda-consumer 2s 0ms
- ID-myhost-1234-8 done timer-to-seda 2s 1ms
- ID-myhost-1234-7 fail kafka-route 5s 5023ms
-```
-
-The last exchange (`kafka-route`) failed after 5 seconds — likely a
-connection timeout to the Kafka broker.
+The Inspect tab shows what happened to a message as it traveled
+through the integration, with every step it passed through. Camel
+records it with its BacklogTracer. The tab has two views:
+
+- **History** (message tracing off) — the steps of the **last
+ completed message only**: the exchange that finished last, with the
+ steps of the routes it reached downstream (over direct, seda, kafka,
+ and so on). The next message that completes replaces it; earlier
+ messages are not kept.
+- **Traces** (message tracing on) — many recent exchanges, not just
+ one: up to 200 trace steps across them, the oldest go first.
+
+Message tracing is off by default. Turn it on with
+`camel run --backlog-trace`, or for a running integration with
+`camel trace --action=start` (`--action=stop` turns it off again).
+`camel run --trace` only logs each step to the console; it does not
+fill this tab.
+
+## History
+
+The title reads `History of last completed — N steps`, with the
+status and the elapsed time of that message. The table has a row per
+step: `#`, the direction arrow, `TIME`, `ROUTE`, `ID` (the node id),
+`PROCESSOR` (`DESCRIPTION` with `n`), `BHPV` and `ELAPSED`.
+
+## Traces
+
+The title reads `Traces [N]`, with N the number of exchanges. Each row
+is an exchange:
+
+- **TIME** — When the exchange started
+- **ROUTE** — The route it started in
+- **STATUS** — Processing, Done or Failed. Failed exchanges also appear on the
Errors tab
+- **ELAPSED** — Total processing time. Long elapsed times may indicate slow
downstream services
+- **STEPS** — The number of steps it passed through
+- **EXCHANGE** — The exchange id
## Detail View
-Press `Enter` on an exchange to see its full journey:
+In the History view the steps are the table itself. In the Traces
+view, press `Enter` on an exchange to see its full journey:
**Message History** — A step-by-step trace of every node the exchange
visited. This shows the exact path the message took through the route,
@@ -80,7 +89,7 @@ the border between them sets the height yourself.
**Follow** — the history is read when the tab opens and when `F5` asks
for it, so the steps stay put while you read them. `f` follows the last
-completed exchange instead: the history is read again on every refresh.
+completed message instead: the history is read again on every refresh.
## Direction Arrows
@@ -168,5 +177,5 @@ Press `Esc` to navigate back one route in drill-down mode.
- `S` — reverse sort order
- `Left/Right` — horizontal scroll (diagram or detail)
- `PgUp/PgDn` — page scroll
-- `f` — follow the last completed exchange (on) or keep the one shown (off)
+- `f` — follow the last completed message (on) or keep the one shown (off)
- `F5` — refresh data
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/McpFacadeHistoryReadTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/McpFacadeHistoryReadTest.java
new file mode 100644
index 000000000000..24b2eaf2fc5a
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/McpFacadeHistoryReadTest.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * The Inspect tab reads the message history when it opens. An agent (the AI
panel, an MCP client) that reads the tab
+ * while another tab is shown gets the history as of now, not an empty list,
and is told that the history holds only the
+ * last completed message.
+ */
+class McpFacadeHistoryReadTest {
+
+ private static final List<Long> PIDS = List.of(123L);
+
+ private final MonitorContext ctx = new MonitorContext(
+ new AtomicReference<>(List.of()), new
AtomicReference<>(List.of()));
+ private final DataRefreshService data = mock(DataRefreshService.class);
+ private final TabRegistry tabs = mock(TabRegistry.class);
+ private final McpFacade.MonitorBridge bridge =
mock(McpFacade.MonitorBridge.class);
+ private HistoryTab inspect;
+ private McpFacade facade;
+
+ @BeforeEach
+ void setUp() {
+ ctx.dataService = data;
+ ctx.selectedPid = "123";
+ when(data.selectedPidAsList()).thenReturn(PIDS);
+ when(data.loadHistoryData(PIDS)).thenReturn(List.of(step("from1",
true, false), step("log1", false, true)));
+ inspect = new HistoryTab(ctx, new AtomicReference<>(List.of()), new
HashMap<>());
+ when(tabs.findTabByName("Inspect")).thenReturn(inspect);
+ facade = new McpFacade(
+ ctx, new AtomicReference<>(List.of()), null, null, null, null,
null, null, null, null, tabs, null,
+ bridge);
+ }
+
+ @Test
+ void anAgentReadsTheHistoryWithoutTheTabBeingOpened() {
+ when(bridge.activeTab()).thenReturn(mock(MonitorTab.class));
+
+ JsonObject read = facade.getTableData("Inspect");
+
+ verify(data).loadHistoryData(PIDS);
+ verify(data).refreshTraceData(PIDS);
+ assertThat(read.getString("view")).isEqualTo("History");
+ assertThat((JsonArray) read.get("rows")).hasSize(2);
+ assertThat(read.getString("note")).isEqualTo(HistoryTab.HISTORY_NOTE)
+ .contains("last completed message only", "many recent
exchanges, not just one");
+ }
+
+ @Test
+ void whileTheTabIsShownTheAgentReadsTheViewTheUserSees() {
+ when(bridge.activeTab()).thenReturn(inspect);
+
+ JsonObject read = facade.getTableData("Inspect");
+
+ verify(data, never()).loadHistoryData(PIDS);
+ assertThat((JsonArray) read.get("rows")).isEmpty();
+ }
+
+ @Test
+ void anEmptyHistorySaysWhy() {
+ when(bridge.activeTab()).thenReturn(mock(MonitorTab.class));
+ when(data.loadHistoryData(PIDS)).thenReturn(List.of());
+
+ JsonObject read = facade.getTableData("Inspect");
+
+ assertThat((JsonArray) read.get("rows")).isEmpty();
+
assertThat(read.getString("note")).isEqualTo(HistoryTab.HISTORY_EMPTY_NOTE)
+ .contains("no message has completed yet", "records no message
history");
+ }
+
+ private static HistoryEntry step(String nodeId, boolean first, boolean
last) {
+ HistoryEntry e = new HistoryEntry();
+ e.pid = "123";
+ e.exchangeId = "EX-1";
+ e.routeId = "route1";
+ e.nodeId = nodeId;
+ e.first = first;
+ e.last = last;
+ return e;
+ }
+}