Skip to content

Commit

Permalink
Var trace (#13088)
Browse files Browse the repository at this point in the history
CAMEL-20408: camel-core - Tracer should include exchange variables
  • Loading branch information
davsclaus authored Feb 11, 2024
1 parent 6cf17ad commit 400db38
Show file tree
Hide file tree
Showing 24 changed files with 256 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
{ "name": "camel.debug.fallbackTimeout", "description": "Fallback Timeout in seconds (300 seconds as default) when block the message processing in Camel. A timeout used for waiting for a message to arrive at a given breakpoint.", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "integer", "javaType": "long", "defaultValue": 300 },
{ "name": "camel.debug.includeException", "description": "Trace messages to include exception if the message failed", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
{ "name": "camel.debug.includeExchangeProperties", "description": "Whether to include the exchange properties in the traced message", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
{ "name": "camel.debug.includeExchangeVariables", "description": "Whether to include the exchange variables in the traced message", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
{ "name": "camel.debug.loggingLevel", "description": "The debugger logging level to use when logging activity.", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "object", "javaType": "org.apache.camel.LoggingLevel", "defaultValue": "INFO", "enum": [ "ERROR", "WARN", "INFO", "DEBUG", "TRACE", "OFF" ] },
{ "name": "camel.debug.singleStepIncludeStartEnd", "description": "In single step mode, then when the exchange is created and completed, then simulate a breakpoint at start and end, that allows to suspend and watch the incoming\/complete exchange at the route (you can see message body as response, failed exception etc).", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
{ "name": "camel.debug.standby", "description": "To set the debugger in standby mode, where the debugger will be installed by not automatic enabled. The debugger can then later be enabled explicit from Java, JMX or tooling.", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected JsonObject doCallJson(Map<String, Object> options) {
for (Exchange exchange : copy) {
try {
JsonObject msg
= MessageHelper.dumpAsJSonObject(exchange.getMessage(), false, true, true, false, true,
= MessageHelper.dumpAsJSonObject(exchange.getMessage(), false, true, true,true, false, true,
128 * 1024);
arr.add(msg);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@ void setExchangePropertyOnBreakpoint(String nodeId, String exchangePropertyName,
*/
void setIncludeExchangeProperties(boolean includeExchangeProperties);

/**
* Whether to include the exchange variables in the traced message
*/
boolean isIncludeExchangeVariables();

/**
* Whether to include the exchange variables in the traced message
*/
void setIncludeExchangeVariables(boolean includeExchangeVariables);

/**
* Trace messages to include exception if the message failed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ public interface BacklogTracer {
*/
void setIncludeExchangeProperties(boolean includeExchangeProperties);

/**
* Trace messages to include exchange variables
*/
boolean isIncludeExchangeVariables();

/**
* Trace messages to include exchange variables
*/
void setIncludeExchangeVariables(boolean includeExchangeVariables);

/**
* Trace messages to include exception if the message failed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public final class BacklogTracer extends ServiceSupport implements org.apache.ca
private boolean bodyIncludeStreams;
private boolean bodyIncludeFiles = true;
private boolean includeExchangeProperties = true;
private boolean includeExchangeVariables = true;
private boolean includeException = true;
private boolean traceRests;
private boolean traceTemplates;
Expand Down Expand Up @@ -236,6 +237,16 @@ public void setIncludeExchangeProperties(boolean includeExchangeProperties) {
this.includeExchangeProperties = includeExchangeProperties;
}

@Override
public boolean isIncludeExchangeVariables() {
return includeExchangeVariables;
}

@Override
public void setIncludeExchangeVariables(boolean includeExchangeVariables) {
this.includeExchangeVariables = includeExchangeVariables;
}

@Override
public boolean isIncludeException() {
return includeException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public final class DefaultBacklogDebugger extends ServiceSupport implements Back
private boolean bodyIncludeStreams;
private boolean bodyIncludeFiles = true;
private boolean includeExchangeProperties = true;
private boolean includeExchangeVariables = true;
private boolean includeException = true;

/**
Expand Down Expand Up @@ -677,6 +678,16 @@ public void setIncludeExchangeProperties(boolean includeExchangeProperties) {
this.includeExchangeProperties = includeExchangeProperties;
}

@Override
public boolean isIncludeExchangeVariables() {
return includeExchangeVariables;
}

@Override
public void setIncludeExchangeVariables(boolean includeExchangeVariables) {
this.includeExchangeVariables = includeExchangeVariables;
}

@Override
public boolean isIncludeException() {
return includeException;
Expand Down Expand Up @@ -792,7 +803,7 @@ private void refreshBacklogTracerEventMessage(String nodeId, SuspendedExchange s
* @return the XML
*/
private String dumpAsXml(Exchange exchange) {
return MessageHelper.dumpAsXml(exchange.getIn(), includeExchangeProperties, true, 2, true,
return MessageHelper.dumpAsXml(exchange.getIn(), includeExchangeProperties, includeExchangeVariables, true, 2, true,
isBodyIncludeStreams(), isBodyIncludeFiles(),
getBodyMaxChars());
}
Expand All @@ -804,7 +815,7 @@ private String dumpAsXml(Exchange exchange) {
* @return the JSon
*/
private String dumpAsJSon(Exchange exchange) {
return MessageHelper.dumpAsJSon(exchange.getIn(), includeExchangeProperties, true, 2, true,
return MessageHelper.dumpAsJSon(exchange.getIn(), includeExchangeProperties, includeExchangeVariables, true, 2, true,
isBodyIncludeStreams(), isBodyIncludeFiles(),
getBodyMaxChars(), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,13 @@ public DefaultBacklogTracerEventMessage before(Exchange exchange) throws Excepti
String toNode = processorDefinition.getId();
String exchangeId = exchange.getExchangeId();
boolean includeExchangeProperties = backlogTracer.isIncludeExchangeProperties();
String messageAsXml = MessageHelper.dumpAsXml(exchange.getIn(), includeExchangeProperties, true, 4,
boolean includeExchangeVariables = backlogTracer.isIncludeExchangeVariables();
String messageAsXml = MessageHelper.dumpAsXml(exchange.getIn(), includeExchangeProperties,
includeExchangeVariables, true, 4,
true, backlogTracer.isBodyIncludeStreams(), backlogTracer.isBodyIncludeFiles(),
backlogTracer.getBodyMaxChars());
String messageAsJSon = MessageHelper.dumpAsJSon(exchange.getIn(), includeExchangeProperties, true, 4,
String messageAsJSon = MessageHelper.dumpAsJSon(exchange.getIn(), includeExchangeProperties,
includeExchangeVariables, true, 4,
true, backlogTracer.isBodyIncludeStreams(), backlogTracer.isBodyIncludeFiles(),
backlogTracer.getBodyMaxChars(), true);

Expand Down Expand Up @@ -675,12 +678,15 @@ public void onDone(Exchange exchange) {
String routeId = routeDefinition != null ? routeDefinition.getRouteId() : null;
String exchangeId = exchange.getExchangeId();
boolean includeExchangeProperties = backlogTracer.isIncludeExchangeProperties();
boolean includeExchangeVariables = backlogTracer.isIncludeExchangeVariables();
long created = exchange.getClock().getCreated();
String messageAsXml = MessageHelper.dumpAsXml(exchange.getIn(), includeExchangeProperties, true, 4,
String messageAsXml = MessageHelper.dumpAsXml(exchange.getIn(), includeExchangeProperties,
includeExchangeVariables, true, 4,
true, backlogTracer.isBodyIncludeStreams(), backlogTracer.isBodyIncludeFiles(),
backlogTracer.getBodyMaxChars());
String messageAsJSon
= MessageHelper.dumpAsJSon(exchange.getIn(), includeExchangeProperties, true, 4,
= MessageHelper.dumpAsJSon(exchange.getIn(), includeExchangeProperties, includeExchangeVariables,
true, 4,
true, backlogTracer.isBodyIncludeStreams(), backlogTracer.isBodyIncludeFiles(),
backlogTracer.getBodyMaxChars(), true);
DefaultBacklogTracerEventMessage pseudoLast = new DefaultBacklogTracerEventMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
case "IncludeException": target.setIncludeException(property(camelContext, boolean.class, value)); return true;
case "includeexchangeproperties":
case "IncludeExchangeProperties": target.setIncludeExchangeProperties(property(camelContext, boolean.class, value)); return true;
case "includeexchangevariables":
case "IncludeExchangeVariables": target.setIncludeExchangeVariables(property(camelContext, boolean.class, value)); return true;
case "logginglevel":
case "LoggingLevel": target.setLoggingLevel(property(camelContext, org.apache.camel.LoggingLevel.class, value)); return true;
case "singlestepincludestartend":
Expand Down Expand Up @@ -68,6 +70,8 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
case "IncludeException": return boolean.class;
case "includeexchangeproperties":
case "IncludeExchangeProperties": return boolean.class;
case "includeexchangevariables":
case "IncludeExchangeVariables": return boolean.class;
case "logginglevel":
case "LoggingLevel": return org.apache.camel.LoggingLevel.class;
case "singlestepincludestartend":
Expand Down Expand Up @@ -100,6 +104,8 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "IncludeException": return target.isIncludeException();
case "includeexchangeproperties":
case "IncludeExchangeProperties": return target.isIncludeExchangeProperties();
case "includeexchangevariables":
case "IncludeExchangeVariables": return target.isIncludeExchangeVariables();
case "logginglevel":
case "LoggingLevel": return target.getLoggingLevel();
case "singlestepincludestartend":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
{ "name": "camel.debug.fallbackTimeout", "description": "Fallback Timeout in seconds (300 seconds as default) when block the message processing in Camel. A timeout used for waiting for a message to arrive at a given breakpoint.", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "integer", "javaType": "long", "defaultValue": 300 },
{ "name": "camel.debug.includeException", "description": "Trace messages to include exception if the message failed", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
{ "name": "camel.debug.includeExchangeProperties", "description": "Whether to include the exchange properties in the traced message", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
{ "name": "camel.debug.includeExchangeVariables", "description": "Whether to include the exchange variables in the traced message", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
{ "name": "camel.debug.loggingLevel", "description": "The debugger logging level to use when logging activity.", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "object", "javaType": "org.apache.camel.LoggingLevel", "defaultValue": "INFO", "enum": [ "ERROR", "WARN", "INFO", "DEBUG", "TRACE", "OFF" ] },
{ "name": "camel.debug.singleStepIncludeStartEnd", "description": "In single step mode, then when the exchange is created and completed, then simulate a breakpoint at start and end, that allows to suspend and watch the incoming\/complete exchange at the route (you can see message body as response, failed exception etc).", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
{ "name": "camel.debug.standby", "description": "To set the debugger in standby mode, where the debugger will be installed by not automatic enabled. The debugger can then later be enabled explicit from Java, JMX or tooling.", "sourceType": "org.apache.camel.main.DebuggerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
Expand Down
3 changes: 2 additions & 1 deletion core/camel-main/src/main/docs/main.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ The camel.server supports 12 options, which are listed below.


=== Camel Debugger configurations
The camel.debug supports 12 options, which are listed below.
The camel.debug supports 13 options, which are listed below.

[width="100%",cols="2,5,^1,2",options="header"]
|===
Expand All @@ -200,6 +200,7 @@ The camel.debug supports 12 options, which are listed below.
| *camel.debug.fallbackTimeout* | Fallback Timeout in seconds (300 seconds as default) when block the message processing in Camel. A timeout used for waiting for a message to arrive at a given breakpoint. | 300 | long
| *camel.debug.includeException* | Trace messages to include exception if the message failed | true | boolean
| *camel.debug.includeExchange{zwsp}Properties* | Whether to include the exchange properties in the traced message | true | boolean
| *camel.debug.includeExchange{zwsp}Variables* | Whether to include the exchange variables in the traced message | true | boolean
| *camel.debug.loggingLevel* | The debugger logging level to use when logging activity. | INFO | LoggingLevel
| *camel.debug.singleStepInclude{zwsp}StartEnd* | In single step mode, then when the exchange is created and completed, then simulate a breakpoint at start and end, that allows to suspend and watch the incoming/complete exchange at the route (you can see message body as response, failed exception etc). | false | boolean
| *camel.debug.standby* | To set the debugger in standby mode, where the debugger will be installed by not automatic enabled. The debugger can then later be enabled explicit from Java, JMX or tooling. | false | boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,7 @@ private void setDebuggerProperties(
debugger.setBodyIncludeStreams(config.isBodyIncludeStreams());
debugger.setBodyIncludeFiles(config.isBodyIncludeFiles());
debugger.setIncludeExchangeProperties(config.isIncludeExchangeProperties());
debugger.setIncludeExchangeVariables(config.isIncludeExchangeVariables());
debugger.setIncludeException(config.isIncludeException());
debugger.setLoggingLevel(config.getLoggingLevel().name());
debugger.setSuspendMode(config.isWaitForAttach());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class DebuggerConfigurationProperties implements BootstrapCloseable {
@Metadata(defaultValue = "true")
private boolean includeExchangeProperties = true;
@Metadata(defaultValue = "true")
private boolean includeExchangeVariables = true;
@Metadata(defaultValue = "true")
private boolean includeException = true;
@Metadata(label = "advanced", defaultValue = "300")
private long fallbackTimeout = 300;
Expand Down Expand Up @@ -185,6 +187,17 @@ public void setIncludeExchangeProperties(boolean includeExchangeProperties) {
this.includeExchangeProperties = includeExchangeProperties;
}

public boolean isIncludeExchangeVariables() {
return includeExchangeVariables;
}

/**
* Whether to include the exchange variables in the traced message
*/
public void setIncludeExchangeVariables(boolean includeExchangeVariables) {
this.includeExchangeVariables = includeExchangeVariables;
}

public boolean isIncludeException() {
return includeException;
}
Expand Down Expand Up @@ -296,6 +309,14 @@ public DebuggerConfigurationProperties withIncludeExchangeProperties(boolean inc
return this;
}

/**
* Whether to include the exchange variables in the traced message
*/
public DebuggerConfigurationProperties withIncludeExchangeVariables(boolean includeExchangeVariables) {
this.includeExchangeVariables = includeExchangeVariables;
return this;
}

/**
* Trace messages to include exception if the message failed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ public interface ManagedBacklogDebuggerMBean {
@ManagedAttribute(description = "Whether to include exchange properties in the trace message.")
void setIncludeExchangeProperties(boolean includeExchangeProperties);

@ManagedAttribute(description = "Whether to include exchange variables in the trace message.")
boolean isIncludeExchangeVariables();

@ManagedAttribute(description = "Whether to include exchange variables in the trace message.")
void setIncludeExchangeVariables(boolean includeExchangeVariables);

@ManagedOperation(description = "Dumps the messages in XML format from the suspended breakpoint at the given node.")
String dumpTracedMessagesAsXml(String nodeId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,21 @@ public interface ManagedBacklogTracerMBean {
@ManagedAttribute(description = "Whether to include exchange properties in the trace message.")
boolean isIncludeExchangeProperties();

@ManagedAttribute(description = "Whether to include exchange properties in the trace message.")
void setIncludeExchangeProperties(boolean includeExchangeProperties);

@ManagedAttribute(description = "Whether to include exchange variables in the trace message.")
boolean isIncludeExchangeVariables();

@ManagedAttribute(description = "Whether to include exchange variables in the trace message.")
void setIncludeExchangeVariables(boolean includeExchangeVariables);

@ManagedAttribute(description = "Whether tracing routes created from Rest DSL.")
boolean isTraceRests();

@ManagedAttribute(description = "Whether tracing routes created from route templates or kamelets.")
boolean isTraceTemplates();

@ManagedAttribute(description = "Whether to include exchange properties in the trace message.")
void setIncludeExchangeProperties(boolean includeExchangeProperties);

@ManagedOperation(description = "Dumps the traced messages for the given node or route")
List<BacklogTracerEventMessage> dumpTracedMessages(String nodeOrRouteId);

Expand Down
Loading

0 comments on commit 400db38

Please sign in to comment.