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-spring-boot.git
The following commit(s) were added to refs/heads/main by this push: new 3e8de47443d CAMEL-20472: camel-main - Add group for configuring tracing 3e8de47443d is described below commit 3e8de47443debcf6c1372f53312961fbd6e0be37 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Feb 29 20:04:48 2024 +0100 CAMEL-20472: camel-main - Add group for configuring tracing --- .../src/main/docs/spring-boot.json | 101 ++++++++++ .../boot/trace/CamelTraceAutoConfiguration.java | 70 +++++++ .../trace/CamelTraceConfigurationProperties.java | 217 +++++++++++++++++++++ ...rk.boot.autoconfigure.AutoConfiguration.imports | 1 + 4 files changed, 389 insertions(+) diff --git a/core/camel-spring-boot/src/main/docs/spring-boot.json b/core/camel-spring-boot/src/main/docs/spring-boot.json index 5083b65d34f..ef41fed1f36 100644 --- a/core/camel-spring-boot/src/main/docs/spring-boot.json +++ b/core/camel-spring-boot/src/main/docs/spring-boot.json @@ -124,6 +124,11 @@ "type": "org.apache.camel.spring.boot.threadpool.CamelThreadPoolConfigurationProperties$ThreadPoolProfileConfigurationProperties", "sourceType": "org.apache.camel.spring.boot.threadpool.CamelThreadPoolConfigurationProperties$ThreadPoolProfileConfigurationProperties" }, + { + "name": "camel.trace", + "type": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties" + }, { "name": "camel.vault.aws", "type": "org.apache.camel.spring.boot.vault.AwsVaultConfigurationProperties", @@ -1595,6 +1600,102 @@ "description": "Sets the default time unit used for keep alive time", "sourceType": "org.apache.camel.spring.boot.threadpool.CamelThreadPoolConfigurationProperties" }, + { + "name": "camel.trace.backlog-size", + "type": "java.lang.Integer", + "description": "Defines how many of the last messages to keep in the tracer.", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "defaultValue": 1000 + }, + { + "name": "camel.trace.body-include-files", + "type": "java.lang.Boolean", + "description": "Whether to include the message body of file based messages. The overhead is that the file content has to be read from the file.", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "defaultValue": true + }, + { + "name": "camel.trace.body-include-streams", + "type": "java.lang.Boolean", + "description": "Whether to include the message body of stream based messages. If enabled then beware the stream may not be re-readable later. See more about Stream Caching.", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "defaultValue": false + }, + { + "name": "camel.trace.body-max-chars", + "type": "java.lang.Integer", + "description": "To limit the message body to a maximum size in the traced message. Use 0 or negative value to use unlimited size.", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "defaultValue": 0 + }, + { + "name": "camel.trace.enabled", + "type": "java.lang.Boolean", + "description": "Enables tracer in your Camel application.", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "defaultValue": false + }, + { + "name": "camel.trace.include-exception", + "type": "java.lang.Boolean", + "description": "Trace messages to include exception if the message failed", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "defaultValue": true + }, + { + "name": "camel.trace.include-exchange-properties", + "type": "java.lang.Boolean", + "description": "Whether to include the exchange properties in the traced message", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "defaultValue": true + }, + { + "name": "camel.trace.include-exchange-variables", + "type": "java.lang.Boolean", + "description": "Whether to include the exchange variables in the traced message", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "defaultValue": true + }, + { + "name": "camel.trace.remove-on-dump", + "type": "java.lang.Boolean", + "description": "Whether all traced messages should be removed when the tracer is dumping. By default, the messages are removed, which means that dumping will not contain previous dumped messages.", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "defaultValue": true + }, + { + "name": "camel.trace.standby", + "type": "java.lang.Boolean", + "description": "To set the tracer in standby mode, where the tracer will be installed by not automatic enabled. The tracer can then later be enabled explicit from Java, JMX or tooling.", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "defaultValue": false + }, + { + "name": "camel.trace.trace-filter", + "type": "java.lang.String", + "description": "Filter for tracing messages", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties" + }, + { + "name": "camel.trace.trace-pattern", + "type": "java.lang.String", + "description": "Filter for tracing by route or node id", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties" + }, + { + "name": "camel.trace.trace-rests", + "type": "java.lang.Boolean", + "description": "Whether to trace routes that is created from Rest DSL.", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "defaultValue": false + }, + { + "name": "camel.trace.trace-templates", + "type": "java.lang.Boolean", + "description": "Whether to trace routes that is created from route templates or kamelets.", + "sourceType": "org.apache.camel.spring.boot.trace.CamelTraceConfigurationProperties", + "defaultValue": false + }, { "name": "camel.vault.aws.access-key", "type": "java.lang.String", diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/trace/CamelTraceAutoConfiguration.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/trace/CamelTraceAutoConfiguration.java new file mode 100644 index 00000000000..2356047852e --- /dev/null +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/trace/CamelTraceAutoConfiguration.java @@ -0,0 +1,70 @@ +/* + * 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.spring.boot.trace; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.BacklogTracer; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +@ConditionalOnBean(CamelAutoConfiguration.class) +@EnableConfigurationProperties(CamelTraceConfigurationProperties.class) +@AutoConfigureAfter(CamelAutoConfiguration.class) +public class CamelTraceAutoConfiguration { + + @Bean + public BacklogTracer backlogTracer(CamelContext camelContext, CamelTraceConfigurationProperties config) throws Exception { + if (!config.isEnabled() && !config.isStandby()) { + return null; + } + + // must enable source location so tracer tooling knows to map breakpoints to source code + camelContext.setSourceLocationEnabled(true); + + // enable tracer on camel + camelContext.setBacklogTracing(config.isEnabled()); + camelContext.setBacklogTracingStandby(config.isStandby()); + camelContext.setBacklogTracingTemplates(config.isTraceTemplates()); + + BacklogTracer tracer = org.apache.camel.impl.debugger.BacklogTracer.createTracer(camelContext); + tracer.setEnabled(config.isEnabled()); + tracer.setStandby(config.isStandby()); + tracer.setBacklogSize(config.getBacklogSize()); + tracer.setRemoveOnDump(config.isRemoveOnDump()); + tracer.setBodyMaxChars(config.getBodyMaxChars()); + tracer.setBodyIncludeStreams(config.isBodyIncludeStreams()); + tracer.setBodyIncludeFiles(config.isBodyIncludeFiles()); + tracer.setIncludeExchangeProperties(config.isIncludeExchangeProperties()); + tracer.setIncludeExchangeVariables(config.isIncludeExchangeVariables()); + tracer.setIncludeException(config.isIncludeException()); + tracer.setTraceRests(config.isTraceRests()); + tracer.setTraceTemplates(config.isTraceTemplates()); + tracer.setTracePattern(config.getTracePattern()); + tracer.setTraceFilter(config.getTraceFilter()); + + camelContext.getCamelContextExtension().addContextPlugin(BacklogTracer.class, tracer); + camelContext.addService(tracer); + + return tracer; + } + +} diff --git a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/trace/CamelTraceConfigurationProperties.java b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/trace/CamelTraceConfigurationProperties.java new file mode 100644 index 00000000000..32574b4305e --- /dev/null +++ b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/trace/CamelTraceConfigurationProperties.java @@ -0,0 +1,217 @@ +/* + * 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.spring.boot.trace; + +import org.apache.camel.LoggingLevel; +import org.apache.camel.spi.Metadata; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "camel.trace") +public class CamelTraceConfigurationProperties { + + /** + * Enables tracer in your Camel application. + */ + private boolean enabled; + + /** + * To set the tracer in standby mode, where the tracer will be installed by not automatic enabled. The tracer can + * then later be enabled explicit from Java, JMX or tooling. + */ + private boolean standby; + + /** + * Defines how many of the last messages to keep in the tracer. + */ + @Metadata(label = "advanced", defaultValue = "1000") + private int backlogSize = 1000; + + /** + * Whether all traced messages should be removed when the tracer is dumping. By default, the messages are removed, + * which means that dumping will not contain previous dumped messages. + */ + @Metadata(label = "advanced", defaultValue = "true") + private boolean removeOnDump = true; + + /** + * To limit the message body to a maximum size in the traced message. Use 0 or negative value to use unlimited size. + */ + @Metadata(label = "advanced", defaultValue = "131072") + private int bodyMaxChars = 128 * 1024; + + /** + * Whether to include the message body of stream based messages. If enabled then beware the stream may not be + * re-readable later. See more about Stream Caching. + */ + private boolean bodyIncludeStreams; + + /** + * Whether to include the message body of file based messages. The overhead is that the file content has to be read + * from the file. + */ + @Metadata(defaultValue = "true") + private boolean bodyIncludeFiles = true; + + /** + * Whether to include the exchange properties in the traced message + */ + private boolean includeExchangeProperties = true; + + /** + * Whether to include the exchange variables in the traced message + */ + private boolean includeExchangeVariables = true; + + /** + * Trace messages to include exception if the message failed + */ + private boolean includeException = true; + + /** + * Whether to trace routes that is created from Rest DSL. + */ + @Metadata(label = "advanced") + private boolean traceRests; + + /** + * Whether to trace routes that is created from route templates or kamelets. + */ + @Metadata(label = "advanced") + private boolean traceTemplates; + + /** + * Filter for tracing by route or node id + */ + private String tracePattern; + + /** + * Filter for tracing messages + */ + private String traceFilter; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public boolean isStandby() { + return standby; + } + + public void setStandby(boolean standby) { + this.standby = standby; + } + + public int getBacklogSize() { + return backlogSize; + } + + public void setBacklogSize(int backlogSize) { + this.backlogSize = backlogSize; + } + + public boolean isRemoveOnDump() { + return removeOnDump; + } + + public void setRemoveOnDump(boolean removeOnDump) { + this.removeOnDump = removeOnDump; + } + + public int getBodyMaxChars() { + return bodyMaxChars; + } + + public void setBodyMaxChars(int bodyMaxChars) { + this.bodyMaxChars = bodyMaxChars; + } + + public boolean isBodyIncludeStreams() { + return bodyIncludeStreams; + } + + public void setBodyIncludeStreams(boolean bodyIncludeStreams) { + this.bodyIncludeStreams = bodyIncludeStreams; + } + + public boolean isBodyIncludeFiles() { + return bodyIncludeFiles; + } + + public void setBodyIncludeFiles(boolean bodyIncludeFiles) { + this.bodyIncludeFiles = bodyIncludeFiles; + } + + public boolean isIncludeExchangeProperties() { + return includeExchangeProperties; + } + + public void setIncludeExchangeProperties(boolean includeExchangeProperties) { + this.includeExchangeProperties = includeExchangeProperties; + } + + public boolean isIncludeExchangeVariables() { + return includeExchangeVariables; + } + + public void setIncludeExchangeVariables(boolean includeExchangeVariables) { + this.includeExchangeVariables = includeExchangeVariables; + } + + public boolean isIncludeException() { + return includeException; + } + + public void setIncludeException(boolean includeException) { + this.includeException = includeException; + } + + public boolean isTraceRests() { + return traceRests; + } + + public void setTraceRests(boolean traceRests) { + this.traceRests = traceRests; + } + + public boolean isTraceTemplates() { + return traceTemplates; + } + + public void setTraceTemplates(boolean traceTemplates) { + this.traceTemplates = traceTemplates; + } + + public String getTracePattern() { + return tracePattern; + } + + public void setTracePattern(String tracePattern) { + this.tracePattern = tracePattern; + } + + public String getTraceFilter() { + return traceFilter; + } + + public void setTraceFilter(String traceFilter) { + this.traceFilter = traceFilter; + } +} diff --git a/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index cf103fe6f22..98002faf2f0 100644 --- a/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/core/camel-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -34,6 +34,7 @@ org.apache.camel.spring.boot.properties.PropertiesComponentAutoConfiguration org.apache.camel.spring.boot.routecontroller.SupervisingRouteControllerAutoConfiguration org.apache.camel.spring.boot.security.CamelSSLAutoConfiguration org.apache.camel.spring.boot.threadpool.CamelThreadPoolAutoConfiguration +org.apache.camel.spring.boot.trace.CamelTraceAutoConfiguration org.apache.camel.spring.boot.routetemplate.CamelRouteTemplateAutoConfiguration org.apache.camel.spring.boot.vault.AwsVaultAutoConfiguration org.apache.camel.spring.boot.vault.GcpVaultAutoConfiguration