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


##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AiTraceTools.java:
##########
@@ -109,6 +117,48 @@ public AiTraceResult camel_runtime_ai_trace(
         }
     }
 
+    @ToolGuardrails(input = McpArgumentGuardrail.class, output = 
McpArgumentGuardrail.class)
+    @Tool(annotations = @Tool.Annotations(readOnlyHint = true, destructiveHint 
= false, openWorldHint = false),
+          description = "The conversation of one GenAI agent run of a running 
Camel application: the system "
+                        + "instructions, the user and assistant messages, and 
each tool call with its arguments and "
+                        + "result, in order. Take the runId from 
camel_runtime_ai_trace. The messages are recorded "
+                        + "at camel.aiObservability.level=full only and may 
hold customers' data; long texts are "
+                        + "cut, and the answer says what was cut.")
+    public GenAiTraceReport.Conversation camel_runtime_ai_conversation(
+            @ToolArg(description = NAME_OR_PID_DESC, required = false) String 
nameOrPid,
+            @ToolArg(description = "The runId of an agent run, as 
camel_runtime_ai_trace lists it") String runId) {
+
+        RuntimeService.ProcessInfo p = 
runtimeService.findSingleProcess(nameOrPid);
+        ToolContext ctx = new ToolContext();
+        ctx.selectProcess(p.pid());
+        List<SpanEntry> spans = loadSpans(ctx);
+        if (spans.isEmpty()) {
+            throw new ToolCallException(GenAiTraceReport.NO_SPANS, null);
+        }
+        GenAiTraceReport.Conversation conversation = 
GenAiTraceReport.conversation(spans, runId);
+        if (conversation == null) {
+            throw new ToolCallException(
+                    "No GenAI span with runId " + runId + ": 
camel_runtime_ai_trace lists the runIds of the newest "
+                                        + "agent runs, and older spans may 
have left the span dump.",
+                    null);
+        }
+        return conversation;
+    }
+
+    /**
+     * The spans of the span dump, or none when tracing is off or the dump 
cannot be read: the GenAI part of the trace
+     * then says how to turn it on. Not passed through {@link McpToolNames}, 
as the spans carry the messages of the
+     * models as they were.
+     */
+    List<SpanEntry> loadSpans(ToolContext ctx) {
+        try {
+            Object result = ToolRegistry.execute("get_spans", ctx, 
Map.of("limit", String.valueOf(SPAN_LIMIT)));
+            return GenAiTraceReport.spans(RuntimeTools.toJsonObject(result));
+        } catch (Exception e) {
+            return List.of();
+        }

Review Comment:
   ⚠️ **Silent exception swallowing:** `loadSpans()` catches all exceptions and 
returns an empty list with no logging. When the span load fails at runtime, the 
GenAI section of the trace silently shows "No GenAI spans" with no indication 
that something went wrong — making it very hard to diagnose why spans aren't 
showing up.
   
   Consider adding at least a debug log before the return:
   ```suggestion
           } catch (Exception e) {
               LOG.debug("Failed to load GenAI spans, tracing may be off or the 
span dump is unreadable: {}", e.getMessage());
               return List.of();
           }
   ```
   The Javadoc already documents the silent behavior, but a debug log would 
surface it in the logs when operators are troubleshooting missing spans.



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