diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/PluginConfig.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/PluginConfig.java new file mode 100644 index 000000000..f7308ad4c --- /dev/null +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/boot/PluginConfig.java @@ -0,0 +1,39 @@ +/* + * 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.skywalking.apm.agent.core.boot; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * ConfigInitializationService provides the config class which should host all parameters originally from agent setup. + * {@link org.apache.skywalking.apm.agent.core.conf.Config} provides the core level config, all plugins could implement + * this interface to have the same capability about initializing config from agent.config, system properties and system + * environment variables. + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface PluginConfig { + /** + * @return Class as the root to do config initialization. + */ + Class root(); +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index 2e13d0119..1d89ec567 100755 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -27,7 +27,6 @@ import org.apache.skywalking.apm.agent.core.logging.core.WriterFactory; import org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ClassCacheMode; import org.apache.skywalking.apm.util.Length; - /** * This is the core config in sniffer agent. */ @@ -76,15 +75,15 @@ public class Config { public static boolean IS_OPEN_DEBUGGING_CLASS = false; /** - * If true, SkyWalking agent will cache all instrumented classes to memory or disk files (decided by class cache mode), - * allow other javaagent to enhance those classes that enhanced by SkyWalking agent. + * If true, SkyWalking agent will cache all instrumented classes to memory or disk files (decided by class cache + * mode), allow other javaagent to enhance those classes that enhanced by SkyWalking agent. */ public static boolean IS_CACHE_ENHANCED_CLASS = false; /** - * The instrumented classes cache mode: MEMORY or FILE - * MEMORY: cache class bytes to memory, if instrumented classes is too many or too large, it may take up more memory - * FILE: cache class bytes in `/class-cache` folder, automatically clean up cached class files when the application exits + * The instrumented classes cache mode: MEMORY or FILE MEMORY: cache class bytes to memory, if instrumented + * classes is too many or too large, it may take up more memory FILE: cache class bytes in `/class-cache` + * folder, automatically clean up cached class files when the application exits */ public static ClassCacheMode CLASS_CACHE_MODE = ClassCacheMode.MEMORY; @@ -94,10 +93,8 @@ public class Config { @Length(50) public volatile static String INSTANCE_NAME = ""; - /* - * service instance properties - * e.g. - * agent.instance_properties[org]=apache + /** + * service instance properties e.g. agent.instance_properties[org]=apache */ public static Map INSTANCE_PROPERTIES = new HashMap<>(); @@ -264,180 +261,10 @@ public class Config { } public static class Plugin { - /** * Control the length of the peer field. */ public static int PEER_MAX_LENGTH = 200; - - public static class MongoDB { - /** - * If true, trace all the parameters in MongoDB access, default is false. Only trace the operation, not - * include parameters. - */ - public static boolean TRACE_PARAM = false; - - /** - * For the sake of performance, SkyWalking won't save the entire parameters string into the tag, but only - * the first {@code FILTER_LENGTH_LIMIT} characters. - *

- * Set a negative number to save the complete parameter string to the tag. - */ - public static int FILTER_LENGTH_LIMIT = 256; - } - - public static class Elasticsearch { - /** - * If true, trace all the DSL(Domain Specific Language) in ElasticSearch access, default is false. - */ - public static boolean TRACE_DSL = false; - - public static int ELASTICSEARCH_DSL_LENGTH_THRESHOLD = 1024; - } - - public static class Customize { - /** - * Custom enhancement class configuration file path, recommended to use an absolute path. - */ - public static String ENHANCE_FILE = ""; - - /** - * Some information after custom enhancements, this configuration is used by the custom enhancement plugin. - * And using Map CONTEXT for avoiding classloader isolation issue. - */ - public static Map CONTEXT = new HashMap<>(); - } - - public static class Tomcat { - /** - * This config item controls that whether the Tomcat plugin should collect the parameters of the request. - */ - public static boolean COLLECT_HTTP_PARAMS = false; - } - - public static class SpringMVC { - /** - * If true, the fully qualified method name will be used as the endpoint name instead of the request URL, - * default is false. - */ - public static boolean USE_QUALIFIED_NAME_AS_ENDPOINT_NAME = false; - - /** - * This config item controls that whether the SpringMVC plugin should collect the parameters of the - * request. - */ - public static boolean COLLECT_HTTP_PARAMS = false; - } - - public static class Toolkit { - /** - * If true, the fully qualified method name will be used as the operation name instead of the given - * operation name, default is false. - */ - public static boolean USE_QUALIFIED_NAME_AS_OPERATION_NAME = false; - } - - public static class MySQL { - /** - * If set to true, the parameters of the sql (typically {@link java.sql.PreparedStatement}) would be - * collected. - */ - public static boolean TRACE_SQL_PARAMETERS = false; - /** - * For the sake of performance, SkyWalking won't save the entire parameters string into the tag, but only - * the first {@code SQL_PARAMETERS_MAX_LENGTH} characters. - *

- * Set a negative number to save the complete parameter string to the tag. - */ - public static int SQL_PARAMETERS_MAX_LENGTH = 512; - } - - public static class POSTGRESQL { - /** - * If set to true, the parameters of the sql (typically {@link java.sql.PreparedStatement}) would be - * collected. - */ - public static boolean TRACE_SQL_PARAMETERS = false; - - /** - * For the sake of performance, SkyWalking won't save the entire parameters string into the tag, but only - * the first {@code SQL_PARAMETERS_MAX_LENGTH} characters. - *

- * Set a negative number to save the complete parameter string to the tag. - */ - public static int SQL_PARAMETERS_MAX_LENGTH = 512; - } - - public static class MARIADB { - /** - * If set to true, the parameters of the sql (typically {@link java.sql.PreparedStatement}) would be - * collected. - */ - public static boolean TRACE_SQL_PARAMETERS = false; - - /** - * For the sake of performance, SkyWalking won't save the entire parameters string into the tag, but only - * the first {@code SQL_PARAMETERS_MAX_LENGTH} characters. - *

- * Set a negative number to save the complete parameter string to the tag. - */ - public static int SQL_PARAMETERS_MAX_LENGTH = 512; - } - - public static class SolrJ { - /** - * If true, trace all the query parameters(include deleteByIds and deleteByQuery) in Solr query request, - * default is false. - */ - public static boolean TRACE_STATEMENT = false; - - /** - * If true, trace all the operation parameters in Solr request, default is false. - */ - public static boolean TRACE_OPS_PARAMS = false; - } - - public static class Light4J { - /** - * If true, trace all middleware/business handlers that are part of the Light4J handler chain for a request, - * generating a local span for each. - */ - public static boolean TRACE_HANDLER_CHAIN = false; - } - - public static class SpringTransaction { - - /** - * If true, the transaction definition name will be simplified - */ - public static boolean SIMPLIFY_TRANSACTION_DEFINITION_NAME = false; - } - - public static class JdkThreading { - - /** - * Threading classes ({@link java.lang.Runnable} and {@link java.util.concurrent.Callable} and their - * subclasses, including anonymous inner classes) whose name matches any one of the {@code - * THREADING_CLASS_PREFIXES} (splitted by ,) will be instrumented - */ - public static String THREADING_CLASS_PREFIXES = ""; - } - - public static class Http { - /** - * When either {@link Tomcat#COLLECT_HTTP_PARAMS} or {@link SpringMVC#COLLECT_HTTP_PARAMS} is enabled, how - * many characters to keep and send to the OAP backend, use negative values to keep and send the complete - * parameters, NB. this config item is added for the sake of performance - */ - public static int HTTP_PARAMS_LENGTH_THRESHOLD = 1024; - } - - public static class InfluxDB { - /** - * If set to true, the parameters of the InfluxQL would be collected. - */ - public static boolean TRACE_INFLUXQL = true; - } } public static class Correlation { diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java index a4d8c1176..69042c8cd 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java @@ -44,6 +44,7 @@ public class SnifferConfigInitializer { private static final String SPECIFIED_CONFIG_PATH = "skywalking_config"; private static final String DEFAULT_CONFIG_FILE_NAME = "/config/agent.config"; private static final String ENV_KEY_PREFIX = "skywalking."; + private static Properties AGENT_SETTINGS; private static boolean IS_INIT_COMPLETED = false; /** @@ -57,15 +58,15 @@ public class SnifferConfigInitializer { *

* At the end, `agent.service_name` and `collector.servers` must not be blank. */ - public static void initialize(String agentOptions) { + public static void initializeCoreConfig(String agentOptions) { + AGENT_SETTINGS = new Properties(); try (final InputStreamReader configFileStream = loadConfig()) { - Properties properties = new Properties(); - properties.load(configFileStream); - for (String key : properties.stringPropertyNames()) { - String value = (String) properties.get(key); - properties.put(key, PropertyPlaceholderHelper.INSTANCE.replacePlaceholders(value, properties)); + AGENT_SETTINGS.load(configFileStream); + for (String key : AGENT_SETTINGS.stringPropertyNames()) { + String value = (String) AGENT_SETTINGS.get(key); + AGENT_SETTINGS.put(key, PropertyPlaceholderHelper.INSTANCE.replacePlaceholders(value, AGENT_SETTINGS)); } - ConfigInitializer.initialize(properties, Config.class); + } catch (Exception e) { logger.error(e, "Failed to read the config file, skywalking is going to run in default config."); } @@ -88,6 +89,8 @@ public class SnifferConfigInitializer { } } + initializeConfig(Config.class); + if (StringUtil.isEmpty(Config.Agent.SERVICE_NAME)) { throw new ExceptionInInitializerError("`agent.service_name` is missing."); } @@ -95,23 +98,43 @@ public class SnifferConfigInitializer { throw new ExceptionInInitializerError("`collector.backend_service` is missing."); } if (Config.Plugin.PEER_MAX_LENGTH <= 3) { - logger.warn("PEER_MAX_LENGTH configuration:{} error, the default value of 200 will be used.", Config.Plugin.PEER_MAX_LENGTH); + logger.warn( + "PEER_MAX_LENGTH configuration:{} error, the default value of 200 will be used.", + Config.Plugin.PEER_MAX_LENGTH + ); Config.Plugin.PEER_MAX_LENGTH = 200; } IS_INIT_COMPLETED = true; } + /** + * Initialize field values of any given config class. + * + * @param configClass to host the settings for code access. + */ + public static void initializeConfig(Class configClass) { + if (AGENT_SETTINGS == null) { + logger.error("Plugin configs have to be initialized after core config initialization."); + return; + } + try { + ConfigInitializer.initialize(AGENT_SETTINGS, configClass); + } catch (IllegalAccessException e) { + logger.error(e, + "Failed to set the agent settings {}" + + " to Config={} ", + AGENT_SETTINGS, configClass + ); + } + } + private static void overrideConfigByAgentOptions(String agentOptions) throws IllegalAccessException { - Properties properties = new Properties(); for (List terms : parseAgentOptions(agentOptions)) { if (terms.size() != 2) { throw new IllegalArgumentException("[" + terms + "] is not a key-value pair."); } - properties.put(terms.get(0), terms.get(1)); - } - if (!properties.isEmpty()) { - ConfigInitializer.initialize(properties, Config.class); + AGENT_SETTINGS.put(terms.get(0), terms.get(1)); } } @@ -153,19 +176,14 @@ public class SnifferConfigInitializer { * such as: Property key of `agent.service_name` should be `skywalking.agent.service_name` */ private static void overrideConfigBySystemProp() throws IllegalAccessException { - Properties properties = new Properties(); Properties systemProperties = System.getProperties(); for (final Map.Entry prop : systemProperties.entrySet()) { String key = prop.getKey().toString(); if (key.startsWith(ENV_KEY_PREFIX)) { String realKey = key.substring(ENV_KEY_PREFIX.length()); - properties.put(realKey, prop.getValue()); + AGENT_SETTINGS.put(realKey, prop.getValue()); } } - - if (!properties.isEmpty()) { - ConfigInitializer.initialize(properties, Config.class); - } } /** @@ -175,7 +193,8 @@ public class SnifferConfigInitializer { */ private static InputStreamReader loadConfig() throws AgentPackageNotFoundException, ConfigNotFoundException { String specifiedConfigPath = System.getProperty(SPECIFIED_CONFIG_PATH); - File configFile = StringUtil.isEmpty(specifiedConfigPath) ? new File(AgentPackagePath.getPath(), DEFAULT_CONFIG_FILE_NAME) : new File(specifiedConfigPath); + File configFile = StringUtil.isEmpty(specifiedConfigPath) ? new File( + AgentPackagePath.getPath(), DEFAULT_CONFIG_FILE_NAME) : new File(specifiedConfigPath); if (configFile.exists() && configFile.isFile()) { try { diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java index 776390a15..9b46c1476 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java @@ -34,6 +34,8 @@ import java.util.jar.JarFile; import lombok.RequiredArgsConstructor; import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath; +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; +import org.apache.skywalking.apm.agent.core.conf.SnifferConfigInitializer; import org.apache.skywalking.apm.agent.core.logging.api.ILog; import org.apache.skywalking.apm.agent.core.logging.api.LogManager; import org.apache.skywalking.apm.agent.core.plugin.PluginBootstrap; @@ -99,14 +101,15 @@ public class AgentClassLoader extends ClassLoader { try { URL classFileUrl = new URL("jar:file:" + jar.sourceFile.getAbsolutePath() + "!/" + path); byte[] data; - try (final BufferedInputStream is = new BufferedInputStream(classFileUrl.openStream()); final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { + try (final BufferedInputStream is = new BufferedInputStream( + classFileUrl.openStream()); final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { int ch; while ((ch = is.read()) != -1) { baos.write(ch); } data = baos.toByteArray(); } - return defineClass(name, data, 0, data.length); + return processLoadedClass(defineClass(name, data, 0, data.length)); } catch (IOException e) { logger.error(e, "find class fail."); } @@ -154,6 +157,18 @@ public class AgentClassLoader extends ClassLoader { }; } + private Class processLoadedClass(Class loadedClass) { + final PluginConfig pluginConfig = loadedClass.getAnnotation(PluginConfig.class); + if (pluginConfig != null) { + // Set up the plugin config when loaded by class loader at the first time. + // Agent class loader just loaded limited classes in the plugin jar(s), so the cost of this + // isAssignableFrom would be also very limited. + SnifferConfigInitializer.initializeConfig(pluginConfig.root()); + } + + return loadedClass; + } + private List getAllJars() { if (allJars == null) { jarScanLock.lock(); diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java index 15752610a..53061181c 100644 --- a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializerTest.java @@ -48,7 +48,7 @@ public class SnifferConfigInitializerTest { System.setProperty("skywalking.agent.service_name", "testApp"); System.setProperty("skywalking.collector.backend_service", "127.0.0.1:8090"); System.setProperty("skywalking.logging.level", "info"); - SnifferConfigInitializer.initialize(null); + SnifferConfigInitializer.initializeCoreConfig(null); assertThat(Config.Agent.SERVICE_NAME, is("testApp")); assertThat(Config.Collector.BACKEND_SERVICE, is("127.0.0.1:8090")); assertThat(Config.Logging.LEVEL, is(LogLevel.INFO)); @@ -57,7 +57,7 @@ public class SnifferConfigInitializerTest { @Test public void testLoadConfigFromAgentOptions() throws AgentPackageNotFoundException, ConfigNotFoundException { String agentOptions = "agent.service_name=testApp,collector.backend_service=127.0.0.1:8090,logging.level=info"; - SnifferConfigInitializer.initialize(agentOptions); + SnifferConfigInitializer.initializeCoreConfig(agentOptions); assertThat(Config.Agent.SERVICE_NAME, is("testApp")); assertThat(Config.Collector.BACKEND_SERVICE, is("127.0.0.1:8090")); assertThat(Config.Logging.LEVEL, is(LogLevel.INFO)); @@ -70,7 +70,7 @@ public class SnifferConfigInitializerTest { System.setProperty("skywalking.agent.instance_properties[key2]", "value2"); System.setProperty("skywalking.collector.backend_service", "127.0.0.1:8090"); String agentOptions = "agent.service_name=testAppFromAgentOptions,logging.level=debug"; - SnifferConfigInitializer.initialize(agentOptions); + SnifferConfigInitializer.initializeCoreConfig(agentOptions); assertThat(Config.Agent.SERVICE_NAME, is("testAppFromAgentOptions")); assertThat(Config.Collector.BACKEND_SERVICE, is("127.0.0.1:8090")); assertThat(Config.Logging.LEVEL, is(LogLevel.DEBUG)); @@ -98,7 +98,7 @@ public class SnifferConfigInitializerTest { System.setProperty("skywalking.agent.service_name", "testApp"); System.setProperty("skywalking.collector.backend_service", "127.0.0.1:8090"); String agentOptions = "agent.ignore_suffix='.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg'"; - SnifferConfigInitializer.initialize(agentOptions); + SnifferConfigInitializer.initializeCoreConfig(agentOptions); assertThat(Config.Agent.IGNORE_SUFFIX, is(".jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg")); } @@ -107,13 +107,13 @@ public class SnifferConfigInitializerTest { System.setProperty("skywalking.collector.backend_service", "127.0.0.1:8090"); String agentOptions = "agent.service_name=test=abc"; try { - SnifferConfigInitializer.initialize(agentOptions); + SnifferConfigInitializer.initializeCoreConfig(agentOptions); fail("test=abc without quotes is not a valid value"); } catch (ExceptionInInitializerError e) { // ignore } agentOptions = "agent.service_name='test=abc'"; - SnifferConfigInitializer.initialize(agentOptions); + SnifferConfigInitializer.initializeCoreConfig(agentOptions); assertThat(Config.Agent.SERVICE_NAME, is("test=abc")); } diff --git a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java index 3f0c259ed..1508a2e99 100644 --- a/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java +++ b/apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java @@ -61,10 +61,9 @@ public class SkyWalkingAgent { public static void premain(String agentArgs, Instrumentation instrumentation) throws PluginException { final PluginFinder pluginFinder; try { - SnifferConfigInitializer.initialize(agentArgs); + SnifferConfigInitializer.initializeCoreConfig(agentArgs); pluginFinder = new PluginFinder(new PluginBootstrap().loadPlugins()); - } catch (AgentPackageNotFoundException ape) { logger.error(ape, "Locate agent.jar failure. Shutting down."); return; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/ElasticsearchPluginConfig.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/ElasticsearchPluginConfig.java new file mode 100644 index 000000000..80fa2f68f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/ElasticsearchPluginConfig.java @@ -0,0 +1,35 @@ +/* + * 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.skywalking.apm.plugin.elasticsearch.v5; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class ElasticsearchPluginConfig { + public static class Plugin { + @PluginConfig(root = ElasticsearchPluginConfig.class) + public static class Elasticsearch { + /** + * If true, trace all the DSL(Domain Specific Language) in ElasticSearch access, default is false. + */ + public static boolean TRACE_DSL = false; + + public static int ELASTICSEARCH_DSL_LENGTH_THRESHOLD = 1024; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportActionNodeProxyInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportActionNodeProxyInterceptor.java index 59b3b3beb..9fbaa5f08 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportActionNodeProxyInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportActionNodeProxyInterceptor.java @@ -30,7 +30,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInt import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.elasticsearch.cluster.node.DiscoveryNode; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v5.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.apache.skywalking.apm.plugin.elasticsearch.v5.Constants.DB_TYPE; import static org.apache.skywalking.apm.plugin.elasticsearch.v5.Constants.ELASTICSEARCH_DB_OP_PREFIX; import static org.apache.skywalking.apm.plugin.elasticsearch.v5.Constants.ES_INDEX; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportProxyClientInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportProxyClientInterceptor.java index c707af823..1d8343a12 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportProxyClientInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v5/TransportProxyClientInterceptor.java @@ -33,7 +33,7 @@ import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v5.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; public class TransportProxyClientInterceptor implements InstanceConstructorInterceptor { diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/ElasticsearchPluginConfig.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/ElasticsearchPluginConfig.java new file mode 100644 index 000000000..49a313196 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/ElasticsearchPluginConfig.java @@ -0,0 +1,35 @@ +/* + * 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.skywalking.apm.plugin.elasticsearch.v6; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class ElasticsearchPluginConfig { + public static class Plugin { + @PluginConfig(root = ElasticsearchPluginConfig.class) + public static class Elasticsearch { + /** + * If true, trace all the DSL(Domain Specific Language) in ElasticSearch access, default is false. + */ + public static boolean TRACE_DSL = false; + + public static int ELASTICSEARCH_DSL_LENGTH_THRESHOLD = 1024; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java index 7a15809c7..5ac49f270 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java @@ -36,8 +36,8 @@ import org.elasticsearch.action.update.UpdateResponse; import java.lang.reflect.Method; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.ELASTICSEARCH_DSL_LENGTH_THRESHOLD; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.ELASTICSEARCH_DSL_LENGTH_THRESHOLD; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; public class AdapterActionFutureActionGetMethodsInterceptor implements InstanceMethodsAroundInterceptor { diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptor.java index 63aa133a0..bb4b77b9e 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptor.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE; import java.lang.reflect.Method; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptor.java index c48820f1d..46145cf21 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptor.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE; import java.lang.reflect.Method; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptor.java index a9df313ae..b181aac66 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptor.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE; import java.lang.reflect.Method; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptor.java index b9fa8ef9c..f7c497636 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptor.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE; import java.lang.reflect.Method; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptor.java index 6d33ea557..3439f3b19 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptor.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE; import java.lang.reflect.Method; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptor.java index c02599999..491b5a16f 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptor.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor.Constants.DB_TYPE; import java.lang.reflect.Method; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptor.java index af9d1e613..ad0f25219 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptor.java @@ -18,6 +18,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor; +import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; @@ -38,9 +39,7 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.cluster.node.DiscoveryNode; -import java.lang.reflect.Method; - -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; public class TransportActionNodeProxyExecuteMethodsInterceptor implements InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor { diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/AdapterActionFutureActionGetMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/AdapterActionFutureActionGetMethodsInterceptorTest.java index 3754c41bd..5d7a7a58f 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/AdapterActionFutureActionGetMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/AdapterActionFutureActionGetMethodsInterceptorTest.java @@ -44,7 +44,7 @@ import org.powermock.modules.junit4.PowerMockRunnerDelegate; import java.util.List; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.apache.skywalking.apm.network.trace.component.ComponentsDefine.TRANSPORT_CLIENT; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptorTest.java index fac1c2780..471e3dfa7 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/ClusterClientPutSettingsMethodsInterceptorTest.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.powermock.api.mockito.PowerMockito.when; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptorTest.java index 17e9e6c47..b5519bdb4 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/IndicesClientCreateMethodsInterceptorTest.java @@ -42,7 +42,7 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.powermock.api.mockito.PowerMockito.when; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptorTest.java index 10d2ff86b..2a0aee398 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientGetMethodsInterceptorTest.java @@ -41,7 +41,7 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.powermock.api.mockito.PowerMockito.when; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptorTest.java index 3580fdb3f..35e999ff9 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientIndexMethodsInterceptorTest.java @@ -41,7 +41,7 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.powermock.api.mockito.PowerMockito.when; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptorTest.java index 2969740b3..264de2a89 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientSearchMethodsInterceptorTest.java @@ -42,7 +42,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.powermock.api.mockito.PowerMockito.when; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptorTest.java index e6424203e..4b61ed3f8 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/RestHighLevelClientUpdateMethodsInterceptorTest.java @@ -41,7 +41,7 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.powermock.api.mockito.PowerMockito.when; diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptorTest.java index 68c1f28c5..e803acadd 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/TransportActionNodeProxyExecuteMethodsInterceptorTest.java @@ -18,6 +18,8 @@ package org.apache.skywalking.apm.plugin.elasticsearch.v6.interceptor; +import java.net.InetSocketAddress; +import java.util.List; import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; import org.apache.skywalking.apm.agent.core.context.trace.ExitSpan; import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; @@ -48,13 +50,10 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import java.net.InetSocketAddress; -import java.util.List; - -import static org.apache.skywalking.apm.agent.core.conf.Config.Plugin.Elasticsearch.TRACE_DSL; import static org.apache.skywalking.apm.network.trace.component.ComponentsDefine.TRANSPORT_CLIENT; -import static org.junit.Assert.assertThat; +import static org.apache.skywalking.apm.plugin.elasticsearch.v6.ElasticsearchPluginConfig.Plugin.Elasticsearch.TRACE_DSL; import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; import static org.powermock.api.mockito.PowerMockito.when; @RunWith(PowerMockRunner.class) @@ -116,7 +115,7 @@ public class TransportActionNodeProxyExecuteMethodsInterceptorTest { when(deleteRequest.index()).thenReturn("endpoint"); when(deleteRequest.type()).thenReturn("deleteType"); - when(deleteIndexRequest.indices()).thenReturn(new String[]{"endpoint"}); + when(deleteIndexRequest.indices()).thenReturn(new String[] {"endpoint"}); interceptor = new TransportActionNodeProxyExecuteMethodsInterceptor(); } @@ -153,7 +152,11 @@ public class TransportActionNodeProxyExecuteMethodsInterceptorTest { }; objInst1.setSkyWalkingDynamicField(123); - Object[] allArguments = new Object[]{null, null, objInst1}; + Object[] allArguments = new Object[] { + null, + null, + objInst1 + }; interceptor.onConstruct(objInst2, allArguments); assertThat(objInst1.getSkyWalkingDynamicField(), is(objInst2.getSkyWalkingDynamicField())); @@ -196,7 +199,10 @@ public class TransportActionNodeProxyExecuteMethodsInterceptorTest { private AbstractTracingSpan getSpan(ActionRequest actionRequest) throws Throwable { TRACE_DSL = true; - Object[] allArguments = new Object[]{discoveryNode, actionRequest}; + Object[] allArguments = new Object[] { + discoveryNode, + actionRequest + }; interceptor.beforeMethod(enhancedInstance, null, allArguments, null, null); interceptor.afterMethod(enhancedInstance, null, allArguments, null, null); diff --git a/apm-sniffer/apm-sdk-plugin/influxdb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/influxdb/InfluxDBPluginConfig.java b/apm-sniffer/apm-sdk-plugin/influxdb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/influxdb/InfluxDBPluginConfig.java new file mode 100644 index 000000000..e0dbdcf26 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/influxdb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/influxdb/InfluxDBPluginConfig.java @@ -0,0 +1,33 @@ +/* + * 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.skywalking.apm.plugin.influxdb; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class InfluxDBPluginConfig { + public static class Plugin { + @PluginConfig(root = InfluxDBPluginConfig.class) + public static class InfluxDB { + /** + * If set to true, the parameters of the InfluxQL would be collected. + */ + public static boolean TRACE_INFLUXQL = true; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/influxdb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/influxdb/interceptor/InfluxDBMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/influxdb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/influxdb/interceptor/InfluxDBMethodInterceptor.java index 252cc6434..4cd35cea7 100644 --- a/apm-sniffer/apm-sdk-plugin/influxdb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/influxdb/interceptor/InfluxDBMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/influxdb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/influxdb/interceptor/InfluxDBMethodInterceptor.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.influxdb.interceptor; -import org.apache.skywalking.apm.agent.core.conf.Config; +import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; @@ -27,20 +27,19 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.influxdb.InfluxDBPluginConfig; import org.apache.skywalking.apm.plugin.influxdb.define.Constants; import org.influxdb.dto.BatchPoints; import org.influxdb.dto.Point; import org.influxdb.dto.Query; -import java.lang.reflect.Method; - import static org.apache.skywalking.apm.plugin.influxdb.define.Constants.DB_TYPE; public class InfluxDBMethodInterceptor implements InstanceMethodsAroundInterceptor { @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { + MethodInterceptResult result) throws Throwable { String methodName = method.getName(); String peer = String.valueOf(objInst.getSkyWalkingDynamicField()); AbstractSpan span = ContextManager.createExitSpan("InfluxDB/" + methodName, peer); @@ -48,7 +47,7 @@ public class InfluxDBMethodInterceptor implements InstanceMethodsAroundIntercept SpanLayer.asDB(span); Tags.DB_TYPE.set(span, DB_TYPE); - if (allArguments.length <= 0 || !Config.Plugin.InfluxDB.TRACE_INFLUXQL) { + if (allArguments.length <= 0 || !InfluxDBPluginConfig.Plugin.InfluxDB.TRACE_INFLUXQL) { return; } @@ -85,14 +84,14 @@ public class InfluxDBMethodInterceptor implements InstanceMethodsAroundIntercept @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { + Object ret) throws Throwable { ContextManager.stopSpan(); return ret; } @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { + Class[] argumentsTypes, Throwable t) { ContextManager.activeSpan().errorOccurred().log(t); } } diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPluginConfig.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPluginConfig.java new file mode 100644 index 000000000..9a22acc35 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCPluginConfig.java @@ -0,0 +1,74 @@ +/* + * 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.skywalking.apm.plugin.jdbc; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class JDBCPluginConfig { + public static class Plugin { + @PluginConfig(root = JDBCPluginConfig.class) + public static class MySQL { + /** + * If set to true, the parameters of the sql (typically {@link java.sql.PreparedStatement}) would be + * collected. + */ + public static boolean TRACE_SQL_PARAMETERS = false; + /** + * For the sake of performance, SkyWalking won't save the entire parameters string into the tag, but only + * the first {@code SQL_PARAMETERS_MAX_LENGTH} characters. + *

+ * Set a negative number to save the complete parameter string to the tag. + */ + public static int SQL_PARAMETERS_MAX_LENGTH = 512; + } + + @PluginConfig(root = JDBCPluginConfig.class) + public static class POSTGRESQL { + /** + * If set to true, the parameters of the sql (typically {@link java.sql.PreparedStatement}) would be + * collected. + */ + public static boolean TRACE_SQL_PARAMETERS = false; + + /** + * For the sake of performance, SkyWalking won't save the entire parameters string into the tag, but only + * the first {@code SQL_PARAMETERS_MAX_LENGTH} characters. + *

+ * Set a negative number to save the complete parameter string to the tag. + */ + public static int SQL_PARAMETERS_MAX_LENGTH = 512; + } + + public static class MARIADB { + /** + * If set to true, the parameters of the sql (typically {@link java.sql.PreparedStatement}) would be + * collected. + */ + public static boolean TRACE_SQL_PARAMETERS = false; + + /** + * For the sake of performance, SkyWalking won't save the entire parameters string into the tag, but only + * the first {@code SQL_PARAMETERS_MAX_LENGTH} characters. + *

+ * Set a negative number to save the complete parameter string to the tag. + */ + public static int SQL_PARAMETERS_MAX_LENGTH = 512; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/PSSetterDefinitionOfJDBCInstrumentation.java b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/PSSetterDefinitionOfJDBCInstrumentation.java index d641ca6ec..43fe947b7 100644 --- a/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/PSSetterDefinitionOfJDBCInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/PSSetterDefinitionOfJDBCInstrumentation.java @@ -18,14 +18,12 @@ package org.apache.skywalking.apm.plugin.jdbc; +import java.util.Set; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.plugin.jdbc.define.Constants; -import java.util.Set; - import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.none; import static org.apache.skywalking.apm.plugin.jdbc.define.Constants.PS_IGNORABLE_SETTERS; @@ -42,7 +40,7 @@ public class PSSetterDefinitionOfJDBCInstrumentation implements InstanceMethodsI public ElementMatcher getMethodsMatcher() { ElementMatcher.Junction matcher = none(); - if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS || Config.Plugin.POSTGRESQL.TRACE_SQL_PARAMETERS || Config.Plugin.MARIADB.TRACE_SQL_PARAMETERS) { + if (JDBCPluginConfig.Plugin.MySQL.TRACE_SQL_PARAMETERS || JDBCPluginConfig.Plugin.POSTGRESQL.TRACE_SQL_PARAMETERS || JDBCPluginConfig.Plugin.MARIADB.TRACE_SQL_PARAMETERS) { final Set setters = ignorable ? PS_IGNORABLE_SETTERS : PS_SETTERS; for (String setter : setters) { matcher = matcher.or(named(setter)); diff --git a/apm-sniffer/apm-sdk-plugin/light4j-plugins/light4j-plugin/src/main/java/org/apache/skywalking/apm/plugin/light4j/HandleRequestInterceptor.java b/apm-sniffer/apm-sdk-plugin/light4j-plugins/light4j-plugin/src/main/java/org/apache/skywalking/apm/plugin/light4j/HandleRequestInterceptor.java index 4dc241703..8cd7a4650 100644 --- a/apm-sniffer/apm-sdk-plugin/light4j-plugins/light4j-plugin/src/main/java/org/apache/skywalking/apm/plugin/light4j/HandleRequestInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/light4j-plugins/light4j-plugin/src/main/java/org/apache/skywalking/apm/plugin/light4j/HandleRequestInterceptor.java @@ -24,7 +24,7 @@ import com.networknt.handler.MiddlewareHandler; import com.networknt.handler.OrchestrationHandler; import io.undertow.server.HttpServerExchange; import io.undertow.util.HeaderMap; -import org.apache.skywalking.apm.agent.core.conf.Config; +import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; @@ -37,14 +37,12 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceM import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; -import java.lang.reflect.Method; - /** * {@link HandleRequestInterceptor} creates an entry span before the execution of {@link * com.networknt.exception.ExceptionHandler#handleRequest(HttpServerExchange)} in the I/O thread. *

- * If the {@link Config.Plugin.Light4J#TRACE_HANDLER_CHAIN} flag is set, additionally a local span is produced for each - * {@link com.networknt.handler.MiddlewareHandler} and business handler before their respective {@link + * If the {@link Light4JPluginConfig.Plugin.Light4J#TRACE_HANDLER_CHAIN} flag is set, additionally a local span is produced + * for each {@link com.networknt.handler.MiddlewareHandler} and business handler before their respective {@link * com.networknt.handler.LightHttpHandler#handleRequest(HttpServerExchange)} method executes. Since {@link * com.networknt.handler.LightHttpHandler} is implemented by various middleware and business handlers and the Light4J * framework delegates to these in succession, a chain of {@link org.apache.skywalking.apm.agent.core.context.trace.LocalSpan}s @@ -54,7 +52,7 @@ public class HandleRequestInterceptor implements InstanceMethodsAroundIntercepto @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) { + MethodInterceptResult result) { if (isExceptionHandler(objInst)) { HttpServerExchange exchange = (HttpServerExchange) allArguments[0]; @@ -84,7 +82,7 @@ public class HandleRequestInterceptor implements InstanceMethodsAroundIntercepto ContextManager.stopSpan(span); objInst.setSkyWalkingDynamicField(ContextManager.capture()); - } else if (Config.Plugin.Light4J.TRACE_HANDLER_CHAIN) { + } else if (Light4JPluginConfig.Plugin.Light4J.TRACE_HANDLER_CHAIN) { String operationName = objInst.getClass().getName() + "." + method.getName(); ContextSnapshot snapshot = (ContextSnapshot) objInst.getSkyWalkingDynamicField(); @@ -92,7 +90,8 @@ public class HandleRequestInterceptor implements InstanceMethodsAroundIntercepto ContextManager.continued(snapshot); } - } else if (Config.Plugin.Light4J.TRACE_HANDLER_CHAIN && (isMiddlewareHandler(objInst) || isBusinessHandler(objInst))) { + } else if (Light4JPluginConfig.Plugin.Light4J.TRACE_HANDLER_CHAIN && (isMiddlewareHandler( + objInst) || isBusinessHandler(objInst))) { String operationName = objInst.getClass().getName() + "." + method.getName(); ContextManager.createLocalSpan(operationName).setComponent(ComponentsDefine.LIGHT_4J); @@ -101,14 +100,15 @@ public class HandleRequestInterceptor implements InstanceMethodsAroundIntercepto @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) { + Object ret) { if (isExceptionHandler(objInst)) { HttpServerExchange exchange = (HttpServerExchange) allArguments[0]; - if (Config.Plugin.Light4J.TRACE_HANDLER_CHAIN && !exchange.isInIoThread()) { + if (Light4JPluginConfig.Plugin.Light4J.TRACE_HANDLER_CHAIN && !exchange.isInIoThread()) { ContextManager.stopSpan(); } - } else if (Config.Plugin.Light4J.TRACE_HANDLER_CHAIN && (isMiddlewareHandler(objInst) || isBusinessHandler(objInst))) { + } else if (Light4JPluginConfig.Plugin.Light4J.TRACE_HANDLER_CHAIN && (isMiddlewareHandler( + objInst) || isBusinessHandler(objInst))) { ContextManager.stopSpan(); } return ret; @@ -116,13 +116,14 @@ public class HandleRequestInterceptor implements InstanceMethodsAroundIntercepto @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { + Class[] argumentsTypes, Throwable t) { ContextManager.activeSpan().errorOccurred().log(t); } private boolean isBusinessHandler(EnhancedInstance objInst) { return !objInst.getClass().getInterfaces()[0].equals(MiddlewareHandler.class) && !objInst.getClass() - .equals(OrchestrationHandler.class); + .equals( + OrchestrationHandler.class); } private boolean isMiddlewareHandler(EnhancedInstance objInst) { diff --git a/apm-sniffer/apm-sdk-plugin/light4j-plugins/light4j-plugin/src/main/java/org/apache/skywalking/apm/plugin/light4j/Light4JPluginConfig.java b/apm-sniffer/apm-sdk-plugin/light4j-plugins/light4j-plugin/src/main/java/org/apache/skywalking/apm/plugin/light4j/Light4JPluginConfig.java new file mode 100644 index 000000000..0aad669ed --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/light4j-plugins/light4j-plugin/src/main/java/org/apache/skywalking/apm/plugin/light4j/Light4JPluginConfig.java @@ -0,0 +1,34 @@ +/* + * 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.skywalking.apm.plugin.light4j; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class Light4JPluginConfig { + public static class Plugin { + @PluginConfig(root = Light4JPluginConfig.class) + public static class Light4J { + /** + * If true, trace all middleware/business handlers that are part of the Light4J handler chain for a request, + * generating a local span for each. + */ + public static boolean TRACE_HANDLER_CHAIN = false; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mariadb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mariadb/v2/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mariadb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mariadb/v2/PreparedStatementExecuteMethodsInterceptor.java index c17d94a88..9d7c219c9 100644 --- a/apm-sniffer/apm-sdk-plugin/mariadb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mariadb/v2/PreparedStatementExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/mariadb-2.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mariadb/v2/PreparedStatementExecuteMethodsInterceptor.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.jdbc.mariadb.v2; -import org.apache.skywalking.apm.agent.core.conf.Config; +import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; @@ -26,12 +26,11 @@ import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPluginConfig; import org.apache.skywalking.apm.plugin.jdbc.PreparedStatementParameterBuilder; import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import java.lang.reflect.Method; - import static org.apache.skywalking.apm.plugin.jdbc.mariadb.v2.Constants.SQL_PARAMETERS; public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { @@ -45,13 +44,13 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho return; } AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject - .getStatementName()), connectInfo.getDatabasePeer()); + .getStatementName()), connectInfo.getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); Tags.DB_STATEMENT.set(span, cacheObject.getSql()); span.setComponent(connectInfo.getComponent()); - if (Config.Plugin.MARIADB.TRACE_SQL_PARAMETERS) { + if (JDBCPluginConfig.Plugin.MARIADB.TRACE_SQL_PARAMETERS) { final Object[] parameters = cacheObject.getParameters(); if (parameters != null && parameters.length > 0) { int maxIndex = cacheObject.getMaxIndex(); @@ -87,9 +86,9 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho private String getParameterString(Object[] parameters, int maxIndex) { return new PreparedStatementParameterBuilder() - .setParameters(parameters) - .setMaxIndex(maxIndex) - .setMaxLength(Config.Plugin.MARIADB.SQL_PARAMETERS_MAX_LENGTH) - .build(); + .setParameters(parameters) + .setMaxIndex(maxIndex) + .setMaxLength(JDBCPluginConfig.Plugin.MARIADB.SQL_PARAMETERS_MAX_LENGTH) + .build(); } } diff --git a/apm-sniffer/apm-sdk-plugin/mariadb-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mariadb/v2/PreparedStatementExecuteMethodsInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mariadb-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mariadb/v2/PreparedStatementExecuteMethodsInterceptorTest.java index 874284246..c603f4731 100644 --- a/apm-sniffer/apm-sdk-plugin/mariadb-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mariadb/v2/PreparedStatementExecuteMethodsInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/mariadb-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/jdbc/mariadb/v2/PreparedStatementExecuteMethodsInterceptorTest.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.jdbc.mariadb.v2; -import org.apache.skywalking.apm.agent.core.conf.Config; +import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; @@ -27,9 +27,10 @@ import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; -import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPluginConfig; import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInterceptor; import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; @@ -41,8 +42,6 @@ import org.mockito.Mock; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import java.lang.reflect.Method; - import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.powermock.api.mockito.PowerMockito.when; @@ -73,7 +72,7 @@ public class PreparedStatementExecuteMethodsInterceptorTest { @Before public void setUp() { - Config.Plugin.MARIADB.TRACE_SQL_PARAMETERS = true; + JDBCPluginConfig.Plugin.MARIADB.TRACE_SQL_PARAMETERS = true; preparedStatementSetterInterceptor = new JDBCPreparedStatementSetterInterceptor(); serviceMethodInterceptor = new PreparedStatementExecuteMethodsInterceptor(); @@ -88,11 +87,19 @@ public class PreparedStatementExecuteMethodsInterceptorTest { @Test public void testExecutePreparedStatement() throws Throwable { - preparedStatementSetterInterceptor.beforeMethod(objectInstance, method, new Object[]{1, "abcd"}, null, null); - preparedStatementSetterInterceptor.beforeMethod(objectInstance, method, new Object[]{2, "efgh"}, null, null); + preparedStatementSetterInterceptor.beforeMethod( + objectInstance, method, new Object[] { + 1, + "abcd" + }, null, null); + preparedStatementSetterInterceptor.beforeMethod( + objectInstance, method, new Object[] { + 2, + "efgh" + }, null, null); - serviceMethodInterceptor.beforeMethod(objectInstance, method, new Object[]{SQL}, null, null); - serviceMethodInterceptor.afterMethod(objectInstance, method, new Object[]{SQL}, null, null); + serviceMethodInterceptor.beforeMethod(objectInstance, method, new Object[] {SQL}, null, null); + serviceMethodInterceptor.afterMethod(objectInstance, method, new Object[] {SQL}, null, null); assertThat(segmentStorage.getTraceSegments().size(), is(1)); TraceSegment segment = segmentStorage.getTraceSegments().get(0); diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java index 49f352f1e..8fb7267b4 100644 --- a/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/mongodb-2.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v2/MongoDBCollectionMethodInterceptorTest.java @@ -22,7 +22,6 @@ import com.mongodb.DBCollection; import com.mongodb.DBObject; import java.lang.reflect.Method; import java.util.List; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; @@ -74,13 +73,8 @@ public class MongoDBCollectionMethodInterceptorTest { }) @Before public void setUp() throws Exception { - interceptor = new MongoDBCollectionMethodInterceptor(); - - Config.Plugin.MongoDB.TRACE_PARAM = true; - when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:27017"); - } @Test diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/MongoPluginConfig.java b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/MongoPluginConfig.java new file mode 100644 index 000000000..75f8a4a66 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/MongoPluginConfig.java @@ -0,0 +1,42 @@ +/* + * 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.skywalking.apm.plugin.mongodb.v3; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class MongoPluginConfig { + public static class Plugin { + @PluginConfig(root = MongoPluginConfig.class) + public static class MongoDB { + /** + * If true, trace all the parameters in MongoDB access, default is false. Only trace the operation, not + * include parameters. + */ + public static boolean TRACE_PARAM = false; + + /** + * For the sake of performance, SkyWalking won't save the entire parameters string into the tag, but only + * the first {@code FILTER_LENGTH_LIMIT} characters. + *

+ * Set a negative number to save the complete parameter string to the tag. + */ + public static int FILTER_LENGTH_LIMIT = 256; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoOperationHelper.java b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoOperationHelper.java index 42e5ecdad..99ab80c05 100644 --- a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoOperationHelper.java +++ b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoOperationHelper.java @@ -39,10 +39,9 @@ import com.mongodb.operation.MapReduceToCollectionOperation; import com.mongodb.operation.MapReduceWithInlineResultsOperation; import com.mongodb.operation.MixedBulkWriteOperation; import com.mongodb.operation.UpdateOperation; -import org.apache.skywalking.apm.agent.core.conf.Config; -import org.bson.BsonDocument; - import java.util.List; +import org.apache.skywalking.apm.plugin.mongodb.v3.MongoPluginConfig; +import org.bson.BsonDocument; @SuppressWarnings({ "deprecation", @@ -126,7 +125,7 @@ public class MongoOperationHelper { } else if (request instanceof UpdateRequest) { params.append(((UpdateRequest) request).getFilter()).append(","); } - final int filterLengthLimit = Config.Plugin.MongoDB.FILTER_LENGTH_LIMIT; + final int filterLengthLimit = MongoPluginConfig.Plugin.MongoDB.FILTER_LENGTH_LIMIT; if (filterLengthLimit > 0 && params.length() > filterLengthLimit) { return params.substring(0, filterLengthLimit) + "..."; } @@ -136,7 +135,7 @@ public class MongoOperationHelper { private static String limitFilter(String filter) { final StringBuilder params = new StringBuilder(); - final int filterLengthLimit = Config.Plugin.MongoDB.FILTER_LENGTH_LIMIT; + final int filterLengthLimit = MongoPluginConfig.Plugin.MongoDB.FILTER_LENGTH_LIMIT; if (filterLengthLimit > 0 && filter.length() > filterLengthLimit) { return params.append(filter, 0, filterLengthLimit).append("...").toString(); } else { diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoSpanHelper.java b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoSpanHelper.java index 418707e43..f79c9ccf4 100644 --- a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoSpanHelper.java +++ b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/mongodb/v3/support/MongoSpanHelper.java @@ -18,13 +18,13 @@ package org.apache.skywalking.apm.plugin.mongodb.v3.support; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.apache.skywalking.apm.plugin.mongodb.v3.MongoPluginConfig; public class MongoSpanHelper { @@ -32,12 +32,13 @@ public class MongoSpanHelper { } public static void createExitSpan(String executeMethod, String remotePeer, Object operation) { - AbstractSpan span = ContextManager.createExitSpan(MongoConstants.MONGO_DB_OP_PREFIX + executeMethod, new ContextCarrier(), remotePeer); + AbstractSpan span = ContextManager.createExitSpan( + MongoConstants.MONGO_DB_OP_PREFIX + executeMethod, new ContextCarrier(), remotePeer); span.setComponent(ComponentsDefine.MONGO_DRIVER); Tags.DB_TYPE.set(span, MongoConstants.DB_TYPE); SpanLayer.asDB(span); - if (Config.Plugin.MongoDB.TRACE_PARAM) { + if (MongoPluginConfig.Plugin.MongoDB.TRACE_PARAM) { Tags.DB_STATEMENT.set(span, executeMethod + " " + MongoOperationHelper.getTraceParam(operation)); } } diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v3/interceptor/v30/MongoDBInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v3/interceptor/v30/MongoDBInterceptorTest.java index e0b32b2f7..49dba58d1 100644 --- a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v3/interceptor/v30/MongoDBInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v3/interceptor/v30/MongoDBInterceptorTest.java @@ -23,7 +23,6 @@ import com.mongodb.MongoNamespace; import com.mongodb.operation.FindOperation; import java.lang.reflect.Method; import java.util.List; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; @@ -37,6 +36,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.plugin.mongodb.v3.MongoPluginConfig; import org.bson.BsonDocument; import org.bson.BsonString; import org.bson.codecs.Decoder; @@ -82,7 +82,7 @@ public class MongoDBInterceptorTest { interceptor = new MongoDBInterceptor(); - Config.Plugin.MongoDB.TRACE_PARAM = true; + MongoPluginConfig.Plugin.MongoDB.TRACE_PARAM = true; when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:27017"); @@ -111,7 +111,8 @@ public class MongoDBInterceptorTest { @Test public void testInterceptWithException() throws Throwable { interceptor.beforeMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null); - interceptor.handleMethodException(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, new RuntimeException()); + interceptor.handleMethodException( + enhancedInstance, getExecuteMethod(), arguments, argumentTypes, new RuntimeException()); interceptor.afterMethod(enhancedInstance, getExecuteMethod(), arguments, argumentTypes, null); MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); diff --git a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v3/interceptor/v37/MongoDBOperationExecutorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v3/interceptor/v37/MongoDBOperationExecutorInterceptorTest.java index fe06f4f43..2986b06e2 100644 --- a/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v3/interceptor/v37/MongoDBOperationExecutorInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/mongodb-3.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/mongodb/v3/interceptor/v37/MongoDBOperationExecutorInterceptorTest.java @@ -25,7 +25,6 @@ import com.mongodb.operation.FindOperation; import com.mongodb.operation.WriteOperation; import java.lang.reflect.Method; import java.util.List; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity; import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; @@ -39,6 +38,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.plugin.mongodb.v3.MongoPluginConfig; import org.bson.BsonDocument; import org.bson.BsonString; import org.bson.codecs.Decoder; @@ -81,7 +81,7 @@ public class MongoDBOperationExecutorInterceptorTest { interceptor = new MongoDBOperationExecutorInterceptor(); - Config.Plugin.MongoDB.TRACE_PARAM = true; + MongoPluginConfig.Plugin.MongoDB.TRACE_PARAM = true; when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:27017"); @@ -110,7 +110,8 @@ public class MongoDBOperationExecutorInterceptorTest { @Test public void testInterceptWithException() throws Throwable { interceptor.beforeMethod(enhancedInstance, getMethod(), arguments, argumentTypes, null); - interceptor.handleMethodException(enhancedInstance, getMethod(), arguments, argumentTypes, new RuntimeException()); + interceptor.handleMethodException( + enhancedInstance, getMethod(), arguments, argumentTypes, new RuntimeException()); interceptor.afterMethod(enhancedInstance, getMethod(), arguments, argumentTypes, null); MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1)); diff --git a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java index 27f4c6b94..2ae7b0577 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-common/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/PreparedStatementExecuteMethodsInterceptor.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql; -import org.apache.skywalking.apm.agent.core.conf.Config; +import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; @@ -26,12 +26,11 @@ import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPluginConfig; import org.apache.skywalking.apm.plugin.jdbc.PreparedStatementParameterBuilder; import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import java.lang.reflect.Method; - import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.SQL_PARAMETERS; public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { @@ -49,14 +48,15 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho */ if (cacheObject != null && cacheObject.getConnectionInfo() != null) { ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); - AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject + AbstractSpan span = ContextManager.createExitSpan( + buildOperationName(connectInfo, method.getName(), cacheObject .getStatementName()), connectInfo.getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); Tags.DB_STATEMENT.set(span, cacheObject.getSql()); span.setComponent(connectInfo.getComponent()); - if (Config.Plugin.MySQL.TRACE_SQL_PARAMETERS) { + if (JDBCPluginConfig.Plugin.MySQL.TRACE_SQL_PARAMETERS) { final Object[] parameters = cacheObject.getParameters(); if (parameters != null && parameters.length > 0) { int maxIndex = cacheObject.getMaxIndex(); @@ -94,9 +94,9 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho private String getParameterString(Object[] parameters, int maxIndex) { return new PreparedStatementParameterBuilder() - .setParameters(parameters) - .setMaxIndex(maxIndex) - .setMaxLength(Config.Plugin.MySQL.SQL_PARAMETERS_MAX_LENGTH) - .build(); + .setParameters(parameters) + .setMaxIndex(maxIndex) + .setMaxLength(JDBCPluginConfig.Plugin.MySQL.SQL_PARAMETERS_MAX_LENGTH) + .build(); } } diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/PreparedStatementExecuteMethodsInterceptor.java index 151c37ecb..d359976f9 100755 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/PreparedStatementExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/PreparedStatementExecuteMethodsInterceptor.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.jdbc.postgresql; -import org.apache.skywalking.apm.agent.core.conf.Config; +import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.StringTag; import org.apache.skywalking.apm.agent.core.context.tag.Tags; @@ -27,12 +27,11 @@ import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.JDBCPluginConfig; import org.apache.skywalking.apm.plugin.jdbc.PreparedStatementParameterBuilder; import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import java.lang.reflect.Method; - /** * {@link PreparedStatementExecuteMethodsInterceptor} create the exit span when the client call the interceptor * methods. @@ -46,14 +45,15 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho Class[] argumentsTypes, MethodInterceptResult result) { StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField(); ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); - AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo + AbstractSpan span = ContextManager.createExitSpan( + buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo .getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); Tags.DB_STATEMENT.set(span, cacheObject.getSql()); span.setComponent(connectInfo.getComponent()); - if (Config.Plugin.POSTGRESQL.TRACE_SQL_PARAMETERS) { + if (JDBCPluginConfig.Plugin.POSTGRESQL.TRACE_SQL_PARAMETERS) { final Object[] parameters = cacheObject.getParameters(); if (parameters != null && parameters.length > 0) { int maxIndex = cacheObject.getMaxIndex(); @@ -90,9 +90,9 @@ public class PreparedStatementExecuteMethodsInterceptor implements InstanceMetho private String getParameterString(Object[] parameters, int maxIndex) { return new PreparedStatementParameterBuilder() - .setParameters(parameters) - .setMaxIndex(maxIndex) - .setMaxLength(Config.Plugin.POSTGRESQL.SQL_PARAMETERS_MAX_LENGTH) - .build(); + .setParameters(parameters) + .setMaxIndex(maxIndex) + .setMaxLength(JDBCPluginConfig.Plugin.POSTGRESQL.SQL_PARAMETERS_MAX_LENGTH) + .build(); } } diff --git a/apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/solrj/SolrClientInterceptor.java b/apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/solrj/SolrClientInterceptor.java index b819763a2..ab55f91ce 100644 --- a/apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/solrj/SolrClientInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/solrj/SolrClientInterceptor.java @@ -18,7 +18,12 @@ package org.apache.skywalking.apm.plugin.solrj; -import org.apache.skywalking.apm.agent.core.conf.Config; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; @@ -44,13 +49,6 @@ import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.UpdateParams; import org.apache.solr.common.util.NamedList; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - public class SolrClientInterceptor implements InstanceMethodsAroundInterceptor, InstanceConstructorInterceptor { private static final String DB_TYPE = "Solr"; @@ -75,7 +73,7 @@ public class SolrClientInterceptor implements InstanceMethodsAroundInterceptor, @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { + MethodInterceptResult result) throws Throwable { SolrRequest request = (SolrRequest) allArguments[0]; SolrjInstance instance = (SolrjInstance) objInst.getSkyWalkingDynamicField(); @@ -101,21 +99,21 @@ public class SolrClientInterceptor implements InstanceMethodsAroundInterceptor, deleteBy = ur.getDeleteQuery(); } if (deleteBy == null) { - deleteBy = new ArrayList(); + deleteBy = new ArrayList<>(); } String operator = getOperatorNameWithAction(collection, request.getPath(), actionName); span = getSpan(operator, instance.getRemotePeer()); - if (Config.Plugin.SolrJ.TRACE_STATEMENT) { + if (SolrJPluginConfig.Plugin.SolrJ.TRACE_STATEMENT) { span.tag(Tags.DB_STATEMENT, deleteBy.toString()); } } else { String operator = getOperatorNameWithAction(collection, request.getPath(), "ADD"); span = getSpan(operator, instance.getRemotePeer()); - if (Config.Plugin.SolrJ.TRACE_STATEMENT) { + if (SolrJPluginConfig.Plugin.SolrJ.TRACE_STATEMENT) { span.tag(SolrjTags.TAG_DOCS_SIZE, String.valueOf(documents.size())); } } - if (Config.Plugin.SolrJ.TRACE_OPS_PARAMS) { + if (SolrJPluginConfig.Plugin.SolrJ.TRACE_OPS_PARAMS) { span.tag(SolrjTags.TAG_COMMIT_WITHIN, String.valueOf(ur.getCommitWithin())); } } else { @@ -125,11 +123,12 @@ public class SolrClientInterceptor implements InstanceMethodsAroundInterceptor, String operator = getOperatorNameWithAction(collection, request.getPath(), action.name()); AbstractSpan span = getSpan(operator, instance.getRemotePeer()); - if (Config.Plugin.SolrJ.TRACE_OPS_PARAMS) { + if (SolrJPluginConfig.Plugin.SolrJ.TRACE_OPS_PARAMS) { if (action == AbstractUpdateRequest.ACTION.COMMIT) { span.tag(SolrjTags.TAG_SOFT_COMMIT, params.get(UpdateParams.SOFT_COMMIT, "")); } else { - span.tag(SolrjTags.TAG_MAX_OPTIMIZE_SEGMENTS, params.get(UpdateParams.MAX_OPTIMIZE_SEGMENTS, "1")); + span.tag( + SolrjTags.TAG_MAX_OPTIMIZE_SEGMENTS, params.get(UpdateParams.MAX_OPTIMIZE_SEGMENTS, "1")); } } } @@ -139,7 +138,7 @@ public class SolrClientInterceptor implements InstanceMethodsAroundInterceptor, span.tag(SolrjTags.TAG_START, params.get(CommonParams.START, "0")); span.tag(SolrjTags.TAG_QT, params.get(CommonParams.QT, request.getPath())); - if (Config.Plugin.SolrJ.TRACE_STATEMENT) { + if (SolrJPluginConfig.Plugin.SolrJ.TRACE_STATEMENT) { span.tag(Tags.DB_STATEMENT, toQueryString(params)); } } else { @@ -150,7 +149,7 @@ public class SolrClientInterceptor implements InstanceMethodsAroundInterceptor, @Override @SuppressWarnings("unchecked") public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { + Object ret) throws Throwable { if (!ContextManager.isActive()) { return ret; } @@ -175,7 +174,7 @@ public class SolrClientInterceptor implements InstanceMethodsAroundInterceptor, @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { + Class[] argumentsTypes, Throwable t) { if (ContextManager.isActive()) { AbstractSpan span = ContextManager.activeSpan(); int code = 500; diff --git a/apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/solrj/SolrJPluginConfig.java b/apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/solrj/SolrJPluginConfig.java new file mode 100644 index 000000000..ac3d8dd02 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/solrj/SolrJPluginConfig.java @@ -0,0 +1,39 @@ +/* + * 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.skywalking.apm.plugin.solrj; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class SolrJPluginConfig { + public static class Plugin { + @PluginConfig(root = SolrJPluginConfig.class) + public static class SolrJ { + /** + * If true, trace all the query parameters(include deleteByIds and deleteByQuery) in Solr query request, + * default is false. + */ + public static boolean TRACE_STATEMENT = false; + + /** + * If true, trace all the operation parameters in Solr request, default is false. + */ + public static boolean TRACE_OPS_PARAMS = false; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/solrj/SolrClientInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/solrj/SolrClientInterceptorTest.java index 93381f7f9..e51a2a35d 100644 --- a/apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/solrj/SolrClientInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/solrj/SolrClientInterceptorTest.java @@ -21,7 +21,6 @@ package org.apache.skywalking.apm.plugin.solrj; import com.google.common.collect.Lists; import java.lang.reflect.Method; import java.util.List; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; @@ -104,9 +103,6 @@ public class SolrClientInterceptorTest { header = new NamedList(); header.add("status", 0); header.add("QTime", 5); - - // Config.Plugin.SolrJ.TRACE_STATEMENT = true; - // Config.Plugin.SolrJ.TRACE_OPS_PARAMS = true; } @Test @@ -143,10 +139,10 @@ public class SolrClientInterceptorTest { AbstractTracingSpan span = spans.get(0); int pox = 0; - if (Config.Plugin.SolrJ.TRACE_STATEMENT) { + if (SolrJPluginConfig.Plugin.SolrJ.TRACE_STATEMENT) { SpanAssert.assertTag(span, ++pox, "100"); } - if (Config.Plugin.SolrJ.TRACE_OPS_PARAMS) { + if (SolrJPluginConfig.Plugin.SolrJ.TRACE_OPS_PARAMS) { SpanAssert.assertTag(span, ++pox, "-1"); } spanCommonAssert(span, pox, "solrJ/collection/update/ADD"); @@ -155,7 +151,8 @@ public class SolrClientInterceptorTest { @Test public void testUpdateWithCommit() throws Throwable { final boolean softCommit = false; - AbstractUpdateRequest request = (new UpdateRequest()).setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true, false); + AbstractUpdateRequest request = (new UpdateRequest()).setAction( + AbstractUpdateRequest.ACTION.COMMIT, true, true, false); arguments = new Object[] { request, null, @@ -172,7 +169,7 @@ public class SolrClientInterceptorTest { int start = 0; AbstractTracingSpan span = spans.get(0); - if (Config.Plugin.SolrJ.TRACE_OPS_PARAMS) { + if (SolrJPluginConfig.Plugin.SolrJ.TRACE_OPS_PARAMS) { SpanAssert.assertTag(span, ++start, String.valueOf(softCommit)); } spanCommonAssert(span, start, "solrJ/collection/update/COMMIT"); @@ -181,7 +178,8 @@ public class SolrClientInterceptorTest { @Test public void testUpdateWithOptimize() throws Throwable { final int maxSegments = 1; - AbstractUpdateRequest request = (new UpdateRequest()).setAction(AbstractUpdateRequest.ACTION.OPTIMIZE, false, true, maxSegments); + AbstractUpdateRequest request = (new UpdateRequest()).setAction( + AbstractUpdateRequest.ACTION.OPTIMIZE, false, true, maxSegments); arguments = new Object[] { request, null, @@ -198,7 +196,7 @@ public class SolrClientInterceptorTest { AbstractTracingSpan span = spans.get(0); int start = 0; - if (Config.Plugin.SolrJ.TRACE_OPS_PARAMS) { + if (SolrJPluginConfig.Plugin.SolrJ.TRACE_OPS_PARAMS) { SpanAssert.assertTag(span, ++start, String.valueOf(maxSegments)); } spanCommonAssert(span, start, "solrJ/collection/update/OPTIMIZE"); @@ -312,7 +310,10 @@ public class SolrClientInterceptorTest { response.add("responseHeader", header); interceptor.beforeMethod(enhancedInstance, method, arguments, argumentType, null); - interceptor.handleMethodException(enhancedInstance, method, arguments, argumentType, new SolrException(SolrException.ErrorCode.SERVER_ERROR, "for test", new Exception())); + interceptor.handleMethodException( + enhancedInstance, method, arguments, argumentType, + new SolrException(SolrException.ErrorCode.SERVER_ERROR, "for test", new Exception()) + ); interceptor.afterMethod(enhancedInstance, method, arguments, argumentType, response); List segments = segmentStorage.getTraceSegments(); @@ -332,7 +333,7 @@ public class SolrClientInterceptorTest { SpanAssert.assertTag(span, 2, qt); int start = 3; - if (Config.Plugin.SolrJ.TRACE_STATEMENT) { + if (SolrJPluginConfig.Plugin.SolrJ.TRACE_STATEMENT) { start++; } SpanAssert.assertTag(span, start++, "5"); @@ -361,10 +362,10 @@ public class SolrClientInterceptorTest { SpanAssert.assertTag(span, 0, "Solr"); int start = 0; - if (Config.Plugin.SolrJ.TRACE_STATEMENT) { + if (SolrJPluginConfig.Plugin.SolrJ.TRACE_STATEMENT) { SpanAssert.assertTag(span, ++start, statement); } - if (Config.Plugin.SolrJ.TRACE_OPS_PARAMS) { + if (SolrJPluginConfig.Plugin.SolrJ.TRACE_OPS_PARAMS) { SpanAssert.assertTag(span, ++start, "-1"); } diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/SpringMVCPluginConfig.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/SpringMVCPluginConfig.java new file mode 100644 index 000000000..4a3386dbc --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/SpringMVCPluginConfig.java @@ -0,0 +1,50 @@ +/* + * 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.skywalking.apm.plugin.spring.mvc.commons; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class SpringMVCPluginConfig { + public static class Plugin { + @PluginConfig(root = SpringMVCPluginConfig.class) + public static class SpringMVC { + /** + * If true, the fully qualified method name will be used as the endpoint name instead of the request URL, + * default is false. + */ + public static boolean USE_QUALIFIED_NAME_AS_ENDPOINT_NAME = false; + + /** + * This config item controls that whether the SpringMVC plugin should collect the parameters of the + * request. + */ + public static boolean COLLECT_HTTP_PARAMS = false; + } + + @PluginConfig(root = SpringMVCPluginConfig.class) + public static class Http { + /** + * When either {@link Plugin.SpringMVC#COLLECT_HTTP_PARAMS} is enabled, how many characters to keep and send + * to the OAP backend, use negative values to keep and send the complete parameters, NB. this config item is + * added for the sake of performance + */ + public static int HTTP_PARAMS_LENGTH_THRESHOLD = 1024; + } + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java index 669d2e87a..911ec74c3 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java @@ -22,7 +22,6 @@ import java.lang.reflect.Method; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; @@ -36,6 +35,7 @@ import org.apache.skywalking.apm.agent.core.util.CollectionUtil; import org.apache.skywalking.apm.agent.core.util.MethodUtil; import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; +import org.apache.skywalking.apm.plugin.spring.mvc.commons.SpringMVCPluginConfig; import org.apache.skywalking.apm.plugin.spring.mvc.commons.exception.IllegalMethodStackDepthException; import org.apache.skywalking.apm.plugin.spring.mvc.commons.exception.ServletResponseNotFoundException; import org.apache.skywalking.apm.util.StringUtil; @@ -55,7 +55,8 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround private static final String GET_STATUS_METHOD = "getStatus"; static { - IS_SERVLET_GET_STATUS_METHOD_EXIST = MethodUtil.isMethodExist(AbstractMethodInterceptor.class.getClassLoader(), SERVLET_RESPONSE_CLASS, GET_STATUS_METHOD); + IS_SERVLET_GET_STATUS_METHOD_EXIST = MethodUtil.isMethodExist( + AbstractMethodInterceptor.class.getClassLoader(), SERVLET_RESPONSE_CLASS, GET_STATUS_METHOD); } public abstract String getRequestURL(Method method); @@ -64,7 +65,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { + MethodInterceptResult result) throws Throwable { Boolean forwardRequestFlag = (Boolean) ContextManager.getRuntimeContext().get(FORWARD_REQUEST_FLAG); /** @@ -76,7 +77,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround } String operationName; - if (Config.Plugin.SpringMVC.USE_QUALIFIED_NAME_AS_ENDPOINT_NAME) { + if (SpringMVCPluginConfig.Plugin.SpringMVC.USE_QUALIFIED_NAME_AS_ENDPOINT_NAME) { operationName = MethodUtil.generateOperationName(method); } else { EnhanceRequireObjectCache pathMappingCache = (EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField(); @@ -108,7 +109,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION); SpanLayer.asHttp(span); - if (Config.Plugin.SpringMVC.COLLECT_HTTP_PARAMS) { + if (SpringMVCPluginConfig.Plugin.SpringMVC.COLLECT_HTTP_PARAMS) { collectHttpParam(request, span); } @@ -140,7 +141,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { + Object ret) throws Throwable { Boolean forwardRequestFlag = (Boolean) ContextManager.getRuntimeContext().get(FORWARD_REQUEST_FLAG); /** * Spring MVC plugin do nothing if current request is forward request. @@ -165,7 +166,8 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround if (stackDepth.depth() == 0) { HttpServletResponse response = (HttpServletResponse) ContextManager.getRuntimeContext() - .get(RESPONSE_KEY_IN_RUNTIME_CONTEXT); + .get( + RESPONSE_KEY_IN_RUNTIME_CONTEXT); if (response == null) { throw new ServletResponseNotFoundException(); } @@ -181,7 +183,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround } // Active HTTP parameter collection automatically in the profiling context. - if (!Config.Plugin.SpringMVC.COLLECT_HTTP_PARAMS && span.isProfiling()) { + if (!SpringMVCPluginConfig.Plugin.SpringMVC.COLLECT_HTTP_PARAMS && span.isProfiling()) { collectHttpParam(request, span); } @@ -193,7 +195,7 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { + Class[] argumentsTypes, Throwable t) { ContextManager.activeSpan().errorOccurred().log(t); } @@ -201,7 +203,8 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround final Map parameterMap = request.getParameterMap(); if (parameterMap != null && !parameterMap.isEmpty()) { String tagValue = CollectionUtil.toString(parameterMap); - tagValue = Config.Plugin.Http.HTTP_PARAMS_LENGTH_THRESHOLD > 0 ? StringUtil.cut(tagValue, Config.Plugin.Http.HTTP_PARAMS_LENGTH_THRESHOLD) : tagValue; + tagValue = SpringMVCPluginConfig.Plugin.Http.HTTP_PARAMS_LENGTH_THRESHOLD > 0 ? + StringUtil.cut(tagValue, SpringMVCPluginConfig.Plugin.Http.HTTP_PARAMS_LENGTH_THRESHOLD) : tagValue; Tags.HTTP.PARAMS.set(span, tagValue); } } diff --git a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java index aa37060c1..7c897fdca 100644 --- a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatInvokeInterceptor.java @@ -18,15 +18,13 @@ package org.apache.skywalking.apm.plugin.tomcat78x; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Method; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; - +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import org.apache.catalina.connector.Request; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.context.CarrierItem; import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; @@ -55,7 +53,8 @@ public class TomcatInvokeInterceptor implements InstanceMethodsAroundInterceptor private static final String GET_STATUS_METHOD = "getStatus"; static { - IS_SERVLET_GET_STATUS_METHOD_EXIST = MethodUtil.isMethodExist(TomcatInvokeInterceptor.class.getClassLoader(), SERVLET_RESPONSE_CLASS, GET_STATUS_METHOD); + IS_SERVLET_GET_STATUS_METHOD_EXIST = MethodUtil.isMethodExist( + TomcatInvokeInterceptor.class.getClassLoader(), SERVLET_RESPONSE_CLASS, GET_STATUS_METHOD); } /** @@ -66,7 +65,7 @@ public class TomcatInvokeInterceptor implements InstanceMethodsAroundInterceptor */ @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { + MethodInterceptResult result) throws Throwable { Request request = (Request) allArguments[0]; ContextCarrier contextCarrier = new ContextCarrier(); @@ -82,14 +81,14 @@ public class TomcatInvokeInterceptor implements InstanceMethodsAroundInterceptor span.setComponent(ComponentsDefine.TOMCAT); SpanLayer.asHttp(span); - if (Config.Plugin.Tomcat.COLLECT_HTTP_PARAMS) { + if (TomcatPluginConfig.Plugin.Tomcat.COLLECT_HTTP_PARAMS) { collectHttpParam(request, span); } } @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { + Object ret) throws Throwable { Request request = (Request) allArguments[0]; HttpServletResponse response = (HttpServletResponse) allArguments[1]; @@ -99,7 +98,7 @@ public class TomcatInvokeInterceptor implements InstanceMethodsAroundInterceptor Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); } // Active HTTP parameter collection automatically in the profiling context. - if (!Config.Plugin.Tomcat.COLLECT_HTTP_PARAMS && span.isProfiling()) { + if (!TomcatPluginConfig.Plugin.Tomcat.COLLECT_HTTP_PARAMS && span.isProfiling()) { collectHttpParam(request, span); } ContextManager.stopSpan(); @@ -109,7 +108,7 @@ public class TomcatInvokeInterceptor implements InstanceMethodsAroundInterceptor @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { + Class[] argumentsTypes, Throwable t) { AbstractSpan span = ContextManager.activeSpan(); span.log(t); span.errorOccurred(); @@ -126,7 +125,9 @@ public class TomcatInvokeInterceptor implements InstanceMethodsAroundInterceptor if (!parameterMap.isEmpty()) { String tagValue = CollectionUtil.toString(parameterMap); - tagValue = Config.Plugin.Http.HTTP_PARAMS_LENGTH_THRESHOLD > 0 ? StringUtil.cut(tagValue, Config.Plugin.Http.HTTP_PARAMS_LENGTH_THRESHOLD) : tagValue; + tagValue = TomcatPluginConfig.Plugin.Http.HTTP_PARAMS_LENGTH_THRESHOLD > 0 ? + StringUtil.cut(tagValue, TomcatPluginConfig.Plugin.Http.HTTP_PARAMS_LENGTH_THRESHOLD) : + tagValue; Tags.HTTP.PARAMS.set(span, tagValue); } } diff --git a/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatPluginConfig.java b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatPluginConfig.java new file mode 100644 index 000000000..4bc6174d7 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/tomcat78x/TomcatPluginConfig.java @@ -0,0 +1,43 @@ +/* + * 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.skywalking.apm.plugin.tomcat78x; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class TomcatPluginConfig { + public static class Plugin { + @PluginConfig(root = TomcatPluginConfig.class) + public static class Tomcat { + /** + * This config item controls that whether the Tomcat plugin should collect the parameters of the request. + */ + public static boolean COLLECT_HTTP_PARAMS = false; + } + + @PluginConfig(root = TomcatPluginConfig.class) + public static class Http { + /** + * When either {@link Tomcat#COLLECT_HTTP_PARAMS} is enabled, how many characters to keep and send to the + * OAP backend, use negative values to keep and send the complete parameters, NB. this config item is added + * for the sake of performance + */ + public static int HTTP_PARAMS_LENGTH_THRESHOLD = 1024; + } + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/ToolkitPluginConfig.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/ToolkitPluginConfig.java new file mode 100644 index 000000000..37d2a8d1d --- /dev/null +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/ToolkitPluginConfig.java @@ -0,0 +1,34 @@ +/* + * 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.skywalking.apm.toolkit.activation; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class ToolkitPluginConfig { + public static class Plugin { + @PluginConfig(root = ToolkitPluginConfig.class) + public static class Toolkit { + /** + * If true, the fully qualified method name will be used as the operation name instead of the given + * operation name, default is false. + */ + public static boolean USE_QUALIFIED_NAME_AS_OPERATION_NAME = false; + } + } +} diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java index 95c4fb5d5..eaf8b9038 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-trace-activation/src/main/java/org/apache/skywalking/apm/toolkit/activation/trace/TraceAnnotationMethodInterceptor.java @@ -20,19 +20,18 @@ package org.apache.skywalking.apm.toolkit.activation.trace; import java.lang.reflect.Method; import java.util.Map; - -import org.apache.skywalking.apm.agent.core.conf.Config; -import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; -import org.apache.skywalking.apm.toolkit.activation.util.TagUtil; -import org.apache.skywalking.apm.agent.core.util.CustomizeExpression; -import org.apache.skywalking.apm.toolkit.trace.Tag; -import org.apache.skywalking.apm.toolkit.trace.Tags; -import org.apache.skywalking.apm.toolkit.trace.Trace; import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.agent.core.util.CustomizeExpression; import org.apache.skywalking.apm.agent.core.util.MethodUtil; +import org.apache.skywalking.apm.toolkit.activation.ToolkitPluginConfig; +import org.apache.skywalking.apm.toolkit.activation.util.TagUtil; +import org.apache.skywalking.apm.toolkit.trace.Tag; +import org.apache.skywalking.apm.toolkit.trace.Tags; +import org.apache.skywalking.apm.toolkit.trace.Trace; /** * {@link TraceAnnotationMethodInterceptor} create a local span and set the operation name which fetch from @@ -42,10 +41,10 @@ import org.apache.skywalking.apm.agent.core.util.MethodUtil; public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundInterceptor { @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { + MethodInterceptResult result) throws Throwable { Trace trace = method.getAnnotation(Trace.class); String operationName = trace.operationName(); - if (operationName.length() == 0 || Config.Plugin.Toolkit.USE_QUALIFIED_NAME_AS_OPERATION_NAME) { + if (operationName.length() == 0 || ToolkitPluginConfig.Plugin.Toolkit.USE_QUALIFIED_NAME_AS_OPERATION_NAME) { operationName = MethodUtil.generateOperationName(method); } @@ -69,7 +68,7 @@ public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundIn @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { + Object ret) throws Throwable { try { if (ret == null) { return ret; @@ -96,7 +95,7 @@ public class TraceAnnotationMethodInterceptor implements InstanceMethodsAroundIn @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { + Class[] argumentsTypes, Throwable t) { ContextManager.activeSpan().errorOccurred().log(t); } } diff --git a/apm-sniffer/bootstrap-plugins/jdk-threading-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/threading/JDKThreadingPluginConfig.java b/apm-sniffer/bootstrap-plugins/jdk-threading-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/threading/JDKThreadingPluginConfig.java new file mode 100644 index 000000000..15dad7c57 --- /dev/null +++ b/apm-sniffer/bootstrap-plugins/jdk-threading-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/threading/JDKThreadingPluginConfig.java @@ -0,0 +1,36 @@ +/* + * 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.skywalking.apm.plugin.jdk.threading; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class JDKThreadingPluginConfig { + public static class Plugin { + @PluginConfig(root = JDKThreadingPluginConfig.class) + public static class JdkThreading { + + /** + * Threading classes ({@link java.lang.Runnable} and {@link java.util.concurrent.Callable} and their + * subclasses, including anonymous inner classes) whose name matches any one of the {@code + * THREADING_CLASS_PREFIXES} (splitted by ,) will be instrumented + */ + public static String THREADING_CLASS_PREFIXES = ""; + } + } +} diff --git a/apm-sniffer/bootstrap-plugins/jdk-threading-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/threading/ThreadingConfig.java b/apm-sniffer/bootstrap-plugins/jdk-threading-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/threading/ThreadingConfig.java index fb4736fe7..b032abef0 100644 --- a/apm-sniffer/bootstrap-plugins/jdk-threading-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/threading/ThreadingConfig.java +++ b/apm-sniffer/bootstrap-plugins/jdk-threading-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/threading/ThreadingConfig.java @@ -20,13 +20,11 @@ package org.apache.skywalking.apm.plugin.jdk.threading; import java.util.ArrayList; import java.util.List; - -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.logging.api.ILog; import org.apache.skywalking.apm.agent.core.logging.api.LogManager; import org.apache.skywalking.apm.agent.core.plugin.match.IndirectMatch; -import org.apache.skywalking.apm.agent.core.plugin.match.logical.LogicalMatchOperation; import org.apache.skywalking.apm.agent.core.plugin.match.PrefixMatch; +import org.apache.skywalking.apm.agent.core.plugin.match.logical.LogicalMatchOperation; import static org.apache.skywalking.apm.agent.core.plugin.match.PrefixMatch.nameStartsWith; @@ -34,7 +32,7 @@ public class ThreadingConfig { private static final ILog LOGGER = LogManager.getLogger(ThreadingConfig.class); public static IndirectMatch prefixesMatchesForJdkThreading() { - final String jointPrefixes = Config.Plugin.JdkThreading.THREADING_CLASS_PREFIXES; + final String jointPrefixes = JDKThreadingPluginConfig.Plugin.JdkThreading.THREADING_CLASS_PREFIXES; if (jointPrefixes == null || jointPrefixes.trim().isEmpty()) { return null; diff --git a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java index 11ab13c60..6c7914461 100644 --- a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java +++ b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java @@ -26,11 +26,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import net.bytebuddy.matcher.ElementMatcher; -import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.logging.api.ILog; import org.apache.skywalking.apm.agent.core.logging.api.LogManager; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassEnhancePluginDefine; @@ -60,13 +60,41 @@ public enum CustomizeConfiguration { private static final ILog logger = LogManager.getLogger(CustomizeConfiguration.class); /** - * The load method is resolver configuration file, and parse it to kernel. + * Some information after custom enhancements, this configuration is used by the custom enhancement plugin. + * And using Map CONTEXT for avoiding classloader isolation issue. */ - public void load() { + private static final Map> CONTEXT_METHOD_CONFIGURATIONS = new HashMap<>(); + private static final Map CONTEXT_ENHANCE_CLASSES = new HashMap<>(); + private static final AtomicBoolean LOAD_FOR_CONFIGURATION = new AtomicBoolean(false); + + /** + * The loadForEnhance method is resolver configuration file, and parse it + */ + public void loadForEnhance() { try { - parse(resolver()); + for (Map configuration : resolver()) { + addContextEnhanceClass(configuration); + } } catch (Exception e) { - logger.error("CustomizeConfiguration load fail", e); + logger.error("CustomizeConfiguration loadForAgent fail", e); + } + } + + /** + * The loadForConfiguration method is resolver configuration file, and parse it + */ + public synchronized void loadForConfiguration() { + if (LOAD_FOR_CONFIGURATION.get()) { + return; + } + try { + for (Map configuration : resolver()) { + addContextMethodConfiguration(configuration); + } + } catch (Exception e) { + logger.error("CustomizeConfiguration loadForConfiguration fail", e); + } finally { + LOAD_FOR_CONFIGURATION.set(true); } } @@ -80,7 +108,7 @@ public enum CustomizeConfiguration { */ private List> resolver() throws ParserConfigurationException, IOException, SAXException { List> customizeMethods = new ArrayList>(); - File file = new File(Config.Plugin.Customize.ENHANCE_FILE); + File file = new File(CustomizePluginConfig.Plugin.Customize.ENHANCE_FILE); if (file.exists() && file.isFile()) { NodeList classNodeList = resolverFileClassDesc(file); resolverClassNodeList(classNodeList, customizeMethods); @@ -118,8 +146,8 @@ public enum CustomizeConfiguration { Node methodDesc = methodNodeList.item(ms); if (methodDesc.getNodeType() == Node.ELEMENT_NODE) { String className = classDesc.getAttributes() - .getNamedItem(Constants.XML_ELEMENT_CLASS_NAME) - .getNodeValue(); + .getNamedItem(Constants.XML_ELEMENT_CLASS_NAME) + .getNodeValue(); Map configuration = resolverMethodNodeDesc(className, methodDesc); if (configuration != null) { customizeMethods.add(configuration); @@ -140,32 +168,36 @@ public enum CustomizeConfiguration { Map configuration = new HashMap(); if (methodDesc.getAttributes().getNamedItem(Constants.XML_ELEMENT_OPERATION_NAME) != null) { MethodConfiguration.setOperationName(configuration, methodDesc.getAttributes() - .getNamedItem(Constants.XML_ELEMENT_OPERATION_NAME) - .getNodeValue()); + .getNamedItem( + Constants.XML_ELEMENT_OPERATION_NAME) + .getNodeValue()); } if (methodDesc.getAttributes().getNamedItem(Constants.XML_ELEMENT_CLOSE_BEFORE_METHOD) != null) { MethodConfiguration.setCloseBeforeMethod(configuration, Boolean.valueOf(methodDesc.getAttributes() - .getNamedItem(Constants.XML_ELEMENT_CLOSE_BEFORE_METHOD) - .getNodeValue())); + .getNamedItem( + Constants.XML_ELEMENT_CLOSE_BEFORE_METHOD) + .getNodeValue())); } else { MethodConfiguration.setCloseBeforeMethod(configuration, false); } if (methodDesc.getAttributes().getNamedItem(Constants.XML_ELEMENT_CLOSE_AFTER_METHOD) != null) { MethodConfiguration.setCloseAfterMethod(configuration, Boolean.valueOf(methodDesc.getAttributes() - .getNamedItem(Constants.XML_ELEMENT_CLOSE_AFTER_METHOD) - .getNodeValue())); + .getNamedItem( + Constants.XML_ELEMENT_CLOSE_AFTER_METHOD) + .getNodeValue())); } else { MethodConfiguration.setCloseAfterMethod(configuration, false); } if (methodDesc.getAttributes().getNamedItem(Constants.XML_ELEMENT_METHOD_IS_STATIC) != null) { MethodConfiguration.setStatic(configuration, Boolean.valueOf(methodDesc.getAttributes() - .getNamedItem(Constants.XML_ELEMENT_METHOD_IS_STATIC) - .getNodeValue())); + .getNamedItem( + Constants.XML_ELEMENT_METHOD_IS_STATIC) + .getNodeValue())); } setAdvancedField(configuration, methodDesc); return resolverClassAndMethod(className, methodDesc.getAttributes() - .getNamedItem(Constants.XML_ELEMENT_METHOD) - .getNodeValue(), configuration); + .getNamedItem(Constants.XML_ELEMENT_METHOD) + .getNodeValue(), configuration); } /** @@ -183,14 +215,16 @@ public enum CustomizeConfiguration { MethodConfiguration.addOperationNameSuffixes(configuration, methodContentNode.getTextContent()); } if (Constants.XML_ELEMENT_TAG.equals(methodContentNode.getNodeName())) { - MethodConfiguration.addTag(configuration, methodContentNode.getAttributes() - .getNamedItem(Constants.XML_ELEMENT_KEY) - .getNodeValue(), methodContentNode.getTextContent()); + MethodConfiguration.addTag( + configuration, methodContentNode.getAttributes() + .getNamedItem(Constants.XML_ELEMENT_KEY) + .getNodeValue(), methodContentNode.getTextContent()); } if (Constants.XML_ELEMENT_LOG.equals(methodContentNode.getNodeName())) { - MethodConfiguration.addLog(configuration, methodContentNode.getAttributes() - .getNamedItem(Constants.XML_ELEMENT_KEY) - .getNodeValue(), methodContentNode.getTextContent()); + MethodConfiguration.addLog( + configuration, methodContentNode.getAttributes() + .getNamedItem(Constants.XML_ELEMENT_KEY) + .getNodeValue(), methodContentNode.getTextContent()); } } } @@ -206,16 +240,18 @@ public enum CustomizeConfiguration { * @return configuration of method. */ private Map resolverClassAndMethod(String className, String methodDesc, - Map configuration) { + Map configuration) { try { int openParen = methodDesc.indexOf(Constants.LEFT_PARENTHESIS); int closeParen = methodDesc.indexOf(Constants.RIGHT_PARENTHESIS); String methodName = methodDesc.substring(0, openParen); String[] arguments = methodDesc.substring(openParen + 1, closeParen).split(Constants.COMMA); MethodConfiguration.setClz(configuration, className); - MethodConfiguration.setMethod(configuration, CustomizeUtil.generateOperationName(className, methodName, arguments)); + MethodConfiguration.setMethod( + configuration, CustomizeUtil.generateOperationName(className, methodName, arguments)); MethodConfiguration.setMethodName(configuration, methodName); - MethodConfiguration.setArguments(configuration, StringUtil.isEmpty(arguments[0]) ? new String[0] : arguments); + MethodConfiguration.setArguments( + configuration, StringUtil.isEmpty(arguments[0]) ? new String[0] : arguments); if (StringUtil.isEmpty(MethodConfiguration.getOperationName(configuration))) { MethodConfiguration.setOperationName(configuration, MethodConfiguration.getMethod(configuration)); } @@ -226,27 +262,6 @@ public enum CustomizeConfiguration { return null; } - /** - * Put the plugin configuration into the kernel according to the configuration. - * - * @param configurations is a bridge resolver method and parse method, mainly used for decoupling. - */ - private void parse(List> configurations) { - init(); - for (Map configuration : configurations) { - addContextMethodConfiguration(configuration); - addContextEnhanceClass(configuration); - } - } - - /** - * In order to avoid the judgment of the useless null pointer exception. - */ - private void init() { - Config.Plugin.Customize.CONTEXT.put(Constants.CONTEXT_METHOD_CONFIGURATIONS, new HashMap>()); - Config.Plugin.Customize.CONTEXT.put(Constants.CONTEXT_ENHANCE_CLASSES, new HashMap()); - } - /** * The configuration of each method is put into the kernel. * @@ -263,7 +278,7 @@ public enum CustomizeConfiguration { */ @SuppressWarnings("unchecked") private Map> getMethodConfigurations() { - return (Map>) Config.Plugin.Customize.CONTEXT.get(Constants.CONTEXT_METHOD_CONFIGURATIONS); + return CONTEXT_METHOD_CONFIGURATIONS; } /** @@ -272,11 +287,13 @@ public enum CustomizeConfiguration { * @param configuration {@link MethodConfiguration} */ private void addContextEnhanceClass(Map configuration) { - String key = CustomizeUtil.generateClassDesc(MethodConfiguration.getClz(configuration), MethodConfiguration.isStatic(configuration)); + String key = CustomizeUtil.generateClassDesc( + MethodConfiguration.getClz(configuration), MethodConfiguration.isStatic(configuration)); HashMap enhanceClasses = getEnhanceClasses(); ElementMatcher matcher = enhanceClasses.get(key); - enhanceClasses.put(key, matcher == null ? parserMethodsMatcher(configuration) : ((ElementMatcher.Junction) matcher) - .or(parserMethodsMatcher(configuration))); + enhanceClasses.put( + key, matcher == null ? parserMethodsMatcher(configuration) : ((ElementMatcher.Junction) matcher) + .or(parserMethodsMatcher(configuration))); } /** @@ -287,11 +304,13 @@ public enum CustomizeConfiguration { */ private ElementMatcher parserMethodsMatcher(Map configuration) { String[] arguments = MethodConfiguration.getArguments(configuration); - ElementMatcher matcher = named(MethodConfiguration.getMethodName(configuration)).and(takesArguments(arguments.length)); + ElementMatcher matcher = named(MethodConfiguration.getMethodName(configuration)).and( + takesArguments(arguments.length)); if (arguments.length > 0) { for (int i = 0; i < arguments.length; i++) { - matcher = ((ElementMatcher.Junction) matcher).and(CustomizeUtil.isJavaClass(arguments[i]) ? takesArgument(i, CustomizeUtil - .getJavaClass(arguments[i])) : takesArgumentWithType(i, arguments[i])); + matcher = ((ElementMatcher.Junction) matcher).and( + CustomizeUtil.isJavaClass(arguments[i]) ? takesArgument(i, CustomizeUtil + .getJavaClass(arguments[i])) : takesArgumentWithType(i, arguments[i])); } } return matcher; @@ -327,10 +346,13 @@ public enum CustomizeConfiguration { */ @SuppressWarnings("unchecked") private HashMap getEnhanceClasses() { - return (HashMap) Config.Plugin.Customize.CONTEXT.get(Constants.CONTEXT_ENHANCE_CLASSES); + return (HashMap) CONTEXT_ENHANCE_CLASSES; } public Map getConfiguration(Method method) { + if (!LOAD_FOR_CONFIGURATION.get()) { + loadForConfiguration(); + } return getMethodConfigurations().get(MethodUtil.generateOperationName(method)); } } diff --git a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizePluginConfig.java b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizePluginConfig.java new file mode 100644 index 000000000..ddf071ac7 --- /dev/null +++ b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizePluginConfig.java @@ -0,0 +1,33 @@ +/* + * 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.skywalking.apm.plugin.customize.conf; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class CustomizePluginConfig { + public static class Plugin { + @PluginConfig(root = CustomizePluginConfig.class) + public static class Customize { + /** + * Custom enhancement class configuration file path, recommended to use an absolute path. + */ + public static String ENHANCE_FILE = ""; + } + } +} diff --git a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/loader/CustomizeInstrumentationLoader.java b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/loader/CustomizeInstrumentationLoader.java index c9078acd7..d044f418c 100644 --- a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/loader/CustomizeInstrumentationLoader.java +++ b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/loader/CustomizeInstrumentationLoader.java @@ -43,7 +43,7 @@ public class CustomizeInstrumentationLoader implements InstrumentationLoader { @Override public List load(AgentClassLoader classLoader) { List instrumentations = new ArrayList(); - CustomizeConfiguration.INSTANCE.load(); + CustomizeConfiguration.INSTANCE.loadForEnhance(); Set enhanceClasses = CustomizeConfiguration.INSTANCE.getInstrumentations(); try { for (String enhanceClass : enhanceClasses) { diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-tx-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/transaction/GetTransactionMethodInterceptor.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-tx-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/transaction/GetTransactionMethodInterceptor.java index 6521d13ce..bb9cfa1b6 100644 --- a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-tx-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/transaction/GetTransactionMethodInterceptor.java +++ b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-tx-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/transaction/GetTransactionMethodInterceptor.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.plugin.spring.transaction; -import org.apache.skywalking.apm.agent.core.conf.Config; +import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; @@ -28,41 +28,42 @@ import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.apache.skywalking.apm.plugin.spring.transaction.context.Constants; import org.springframework.transaction.TransactionDefinition; -import java.lang.reflect.Method; - public class GetTransactionMethodInterceptor implements InstanceMethodsAroundInterceptor { @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - MethodInterceptResult result) throws Throwable { + MethodInterceptResult result) throws Throwable { if (allArguments[0] == null) { - AbstractSpan span = ContextManager.createLocalSpan(Constants.OPERATION_NAME_SPRING_TRANSACTION_NO_TRANSACTION_DEFINITION_GIVEN); + AbstractSpan span = ContextManager.createLocalSpan( + Constants.OPERATION_NAME_SPRING_TRANSACTION_NO_TRANSACTION_DEFINITION_GIVEN); span.setComponent(ComponentsDefine.SPRING_TX); return; } TransactionDefinition definition = (TransactionDefinition) allArguments[0]; - AbstractSpan span = ContextManager.createLocalSpan(Constants.OPERATION_NAME_SPRING_TRANSACTION_GET_TRANSACTION_METHOD + buildOperationName(definition - .getName())); + AbstractSpan span = ContextManager.createLocalSpan( + Constants.OPERATION_NAME_SPRING_TRANSACTION_GET_TRANSACTION_METHOD + buildOperationName(definition + .getName())); span.tag(Constants.TAG_SPRING_TRANSACTION_ISOLATION_LEVEL, String.valueOf(definition.getIsolationLevel())); - span.tag(Constants.TAG_SPRING_TRANSACTION_PROPAGATION_BEHAVIOR, String.valueOf(definition.getPropagationBehavior())); + span.tag( + Constants.TAG_SPRING_TRANSACTION_PROPAGATION_BEHAVIOR, String.valueOf(definition.getPropagationBehavior())); span.tag(Constants.TAG_SPRING_TRANSACTION_TIMEOUT, String.valueOf(definition.getTimeout())); span.setComponent(ComponentsDefine.SPRING_TX); } @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, - Object ret) throws Throwable { + Object ret) throws Throwable { ContextManager.stopSpan(); return ret; } @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, - Class[] argumentsTypes, Throwable t) { + Class[] argumentsTypes, Throwable t) { ContextManager.activeSpan().errorOccurred().log(t); } private String buildOperationName(String transactionDefinitionName) { - if (!Config.Plugin.SpringTransaction.SIMPLIFY_TRANSACTION_DEFINITION_NAME) { + if (!SpringTXPluginConfig.Plugin.SpringTransaction.SIMPLIFY_TRANSACTION_DEFINITION_NAME) { return transactionDefinitionName; } String[] ss = transactionDefinitionName.split("\\."); diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-tx-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/transaction/SpringTXPluginConfig.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-tx-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/transaction/SpringTXPluginConfig.java new file mode 100644 index 000000000..f30a14fa4 --- /dev/null +++ b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-tx-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/transaction/SpringTXPluginConfig.java @@ -0,0 +1,34 @@ +/* + * 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.skywalking.apm.plugin.spring.transaction; + +import org.apache.skywalking.apm.agent.core.boot.PluginConfig; + +public class SpringTXPluginConfig { + public static class Plugin { + @PluginConfig(root = SpringTXPluginConfig.class) + public static class SpringTransaction { + + /** + * If true, the transaction definition name will be simplified + */ + public static boolean SIMPLIFY_TRANSACTION_DEFINITION_NAME = false; + } + } +}