You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/02/15 15:32:01 UTC
[camel] branch main updated: CAMEL-19055: camel-core - Backlog tracer capture thread id of the processed exchange
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 99936661cde CAMEL-19055: camel-core - Backlog tracer capture thread id of the processed exchange
99936661cde is described below
commit 99936661cde9bb6a518676d2a13d82944eec70ed
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Feb 15 16:31:41 2023 +0100
CAMEL-19055: camel-core - Backlog tracer capture thread id of the processed exchange
---
.../camel/spi/BacklogTracerEventMessage.java | 5 +++
.../debugger/DefaultBacklogTracerEventMessage.java | 11 ++++-
.../core/commands/action/CamelTraceAction.java | 49 ++++++++++++++--------
3 files changed, 47 insertions(+), 18 deletions(-)
diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/BacklogTracerEventMessage.java b/core/camel-api/src/main/java/org/apache/camel/spi/BacklogTracerEventMessage.java
index d13dda1aac4..873b0cc54b4 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/BacklogTracerEventMessage.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/BacklogTracerEventMessage.java
@@ -66,6 +66,11 @@ public interface BacklogTracerEventMessage {
*/
String getExchangeId();
+ /**
+ * The name of the thread that is processing the message, when this event was captured.
+ */
+ String getProcessingThreadName();
+
/**
* The content of the message as XML (body and headers)
*/
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogTracerEventMessage.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogTracerEventMessage.java
index ae9b44fbefb..168a4f2eaca 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogTracerEventMessage.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogTracerEventMessage.java
@@ -35,10 +35,11 @@ public final class DefaultBacklogTracerEventMessage implements BacklogTracerEven
private final boolean last;
private final long uid;
private final long timestamp;
- private String location;
+ private final String location;
private final String routeId;
private final String toNode;
private final String exchangeId;
+ private final String threadName;
private final String messageAsXml;
private final String messageAsJSon;
private String exceptionAsXml;
@@ -60,6 +61,7 @@ public final class DefaultBacklogTracerEventMessage implements BacklogTracerEven
this.exchangeId = exchangeId;
this.messageAsXml = messageAsXml;
this.messageAsJSon = messageAsJSon;
+ this.threadName = Thread.currentThread().getName();
}
/**
@@ -110,6 +112,11 @@ public final class DefaultBacklogTracerEventMessage implements BacklogTracerEven
return exchangeId;
}
+ @Override
+ public String getProcessingThreadName() {
+ return threadName;
+ }
+
@Override
public String getMessageAsXml() {
return messageAsXml;
@@ -188,6 +195,7 @@ public final class DefaultBacklogTracerEventMessage implements BacklogTracerEven
String ts = new SimpleDateFormat(TIMESTAMP_FORMAT).format(timestamp);
sb.append(prefix).append(" <timestamp>").append(ts).append("</timestamp>\n");
sb.append(prefix).append(" <elapsed>").append(getElapsed()).append("</elapsed>\n");
+ sb.append(prefix).append(" <threadName>").append(getProcessingThreadName()).append("</threadName>\n");
sb.append(prefix).append(" <done>").append(isDone()).append("</done>\n");
sb.append(prefix).append(" <failed>").append(isFailed()).append("</failed>\n");
if (getLocation() != null) {
@@ -239,6 +247,7 @@ public final class DefaultBacklogTracerEventMessage implements BacklogTracerEven
jo.put("timestamp", timestamp);
}
jo.put("elapsed", getElapsed());
+ jo.put("threadName", getProcessingThreadName());
jo.put("done", isDone());
jo.put("failed", isFailed());
try {
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceAction.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceAction.java
index c71463539f8..364086f9439 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceAction.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceAction.java
@@ -77,9 +77,13 @@ public class CamelTraceAction extends ActionBaseCommand {
description = "Print prefix with running Camel integration name.")
boolean prefix = true;
+ @CommandLine.Option(names = { "--source" },
+ description = "Prefer to display source filename/code instead of IDs")
+ boolean source;
+
@CommandLine.Option(names = { "--level" }, defaultValue = "0",
description = "Detail level of tracing. 0=all events (default), 1=input+output")
- int level = 0;
+ int level;
@CommandLine.Option(names = { "--tail" },
description = "The number of traces from the end of the trace to show. Defaults to showing all traces.")
@@ -334,10 +338,12 @@ public class CamelTraceAction extends ActionBaseCommand {
row.elapsed = jo.getLong("elapsed");
row.failed = jo.getBoolean("failed");
row.done = jo.getBoolean("done");
+ row.threadName = jo.getString("threadName");
row.message = jo.getMap("message");
row.exception = jo.getMap("exception");
row.exchangeId = row.message.getString("exchangeId");
- row.message.remove("exchangeId");
+
+ row.message.remove("exchangeId"); // we should exchange id elsewhere
if (!showExchangeProperties) {
row.message.remove("exchangeProperties");
}
@@ -466,7 +472,7 @@ public class CamelTraceAction extends ActionBaseCommand {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String ts = sdf.format(new Date(row.timestamp));
if (loggingColor) {
- AnsiConsole.out().print(Ansi.ansi().fgBrightDefault().a(ts).reset());
+ AnsiConsole.out().print(Ansi.ansi().fgBrightDefault().a(Ansi.Attribute.INTENSITY_FAINT).a(ts).reset());
} else {
System.out.print(ts);
}
@@ -476,7 +482,7 @@ public class CamelTraceAction extends ActionBaseCommand {
String p = String.format("%5.5s", row.pid);
if (loggingColor) {
AnsiConsole.out().print(Ansi.ansi().fgMagenta().a(p).reset());
- AnsiConsole.out().print(Ansi.ansi().fgBrightDefault().a(" --- ").reset());
+ AnsiConsole.out().print(Ansi.ansi().fgBrightDefault().a(Ansi.Attribute.INTENSITY_FAINT).a(" --- ").reset());
} else {
System.out.print(p);
System.out.print(" --- ");
@@ -499,27 +505,35 @@ public class CamelTraceAction extends ActionBaseCommand {
System.out.print(eid);
}
System.out.print(" ");
- // route/node id
- String ids = row.routeId + "/" + getId(row);
- if (ids.length() > 25) {
- ids = ids.substring(ids.length() - 25);
+ // thread name
+ String tn = row.threadName;
+ if (tn.length() > 25) {
+ tn = tn.substring(tn.length() - 25);
}
- ids = String.format("[%25.25s]", ids);
+ tn = String.format("[%25.25s]", tn);
if (loggingColor) {
- AnsiConsole.out().print(Ansi.ansi().fgBrightDefault().a(ids).reset());
+ AnsiConsole.out().print(Ansi.ansi().fgBrightDefault().a(Ansi.Attribute.INTENSITY_FAINT).a(tn).reset());
} else {
- System.out.print(ids);
+ System.out.print(tn);
}
System.out.print(" ");
- // source location
- String code = String.format("%-35.35s", row.location != null ? row.location : "");
+ // node ids or source location
+ String ids;
+ if (source) {
+ ids = row.location;
+ } else {
+ ids = row.routeId + "/" + getId(row);
+ }
+ if (ids.length() > 25) {
+ ids = ids.substring(ids.length() - 25);
+ }
+ ids = String.format("%-25.25s", ids);
if (loggingColor) {
- AnsiConsole.out().print(Ansi.ansi().fgCyan().a(code).reset());
- AnsiConsole.out().print(Ansi.ansi().fgBrightDefault().a(" : ").reset());
+ AnsiConsole.out().print(Ansi.ansi().fgCyan().a(ids).reset());
} else {
- System.out.print(code);
- System.out.print(" : ");
+ System.out.print(ids);
}
+ System.out.print(" : ");
// uuid
String u = String.format("%5.5s", row.uid);
if (loggingColor) {
@@ -663,6 +677,7 @@ public class CamelTraceAction extends ActionBaseCommand {
boolean last;
long uid;
String exchangeId;
+ String threadName;
String location;
String routeId;
String nodeId;