From 04e07f7c97a43ed8bee812e2e3a20958cec65155 Mon Sep 17 00:00:00 2001 From: Felix Barnsteiner Date: Tue, 29 May 2018 15:09:12 +0200 Subject: [PATCH] Add ability to disable certain instrumentations closes #87 Signed-off-by: Felix Barnsteiner --- .../co/elastic/apm/bci/ElasticApmAgent.java | 17 +++++++- .../apm/bci/ElasticApmInstrumentation.java | 10 +++++ .../apm/configuration/CoreConfiguration.java | 12 ++++++ .../elastic/apm/bci/InstrumentationTest.java | 41 ++++++++++++++----- ....elastic.apm.bci.ElasticApmInstrumentation | 1 - .../api/ElasticApmApiInstrumentation.java | 6 +++ .../apm/plugin/api/SpanInstrumentation.java | 6 +++ .../api/TransactionInstrumentation.java | 6 +++ .../apm/jdbc/ConnectionInstrumentation.java | 6 +++ .../PreparedStatementInstrumentation.java | 6 +++ .../apm/jdbc/StatementInstrumentation.java | 6 +++ .../impl/ApmScopeInstrumentation.java | 10 ++++- .../impl/ApmSpanBuilderInstrumentation.java | 10 ++++- .../impl/ApmSpanInstrumentation.java | 7 ++++ .../impl/ScopeManagerInstrumentation.java | 6 +++ .../servlet/FilterChainInstrumentation.java | 7 ++++ .../apm/servlet/ServletInstrumentation.java | 7 ++++ .../servlet/ServletInstrumentationTest.java | 5 +++ .../SpringTransactionNameInstrumentation.java | 9 +++- docs/configuration.asciidoc | 20 +++++++++ 20 files changed, 178 insertions(+), 20 deletions(-) delete mode 100644 apm-agent-core/src/test/resources/META-INF/services/co.elastic.apm.bci.ElasticApmInstrumentation diff --git a/apm-agent-core/src/main/java/co/elastic/apm/bci/ElasticApmAgent.java b/apm-agent-core/src/main/java/co/elastic/apm/bci/ElasticApmAgent.java index a2efae848c..6cf107c1b7 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/bci/ElasticApmAgent.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/bci/ElasticApmAgent.java @@ -37,6 +37,7 @@ import javax.annotation.Nullable; import java.lang.instrument.Instrumentation; import java.security.ProtectionDomain; +import java.util.Collection; import java.util.ServiceLoader; import static co.elastic.apm.bci.bytebuddy.ClassLoaderNameMatcher.classLoaderWithName; @@ -91,9 +92,8 @@ public static void initInstrumentation(ElasticApmTracer tracer, Instrumentation .with(MethodGraph.Compiler.ForDeclaredMethods.INSTANCE); AgentBuilder agentBuilder = getAgentBuilder(byteBuddy); int numberOfAdvices = 0; - final boolean instrument = tracer.getConfig(CoreConfiguration.class).isInstrument(); for (final ElasticApmInstrumentation advice : instrumentations) { - if (advice.includeWhenInstrumentationIsDisabled() || instrument) { + if (isIncluded(advice, tracer.getConfig(CoreConfiguration.class))) { numberOfAdvices++; agentBuilder = applyAdvice(tracer, agentBuilder, advice); } @@ -103,6 +103,19 @@ public static void initInstrumentation(ElasticApmTracer tracer, Instrumentation resettableClassFileTransformer = agentBuilder.installOn(ElasticApmAgent.instrumentation); } + private static boolean isIncluded(ElasticApmInstrumentation advice, CoreConfiguration coreConfiguration) { + final Collection disabledInstrumentations = coreConfiguration.getDisabledInstrumentations(); + return !isGroupDisabled(disabledInstrumentations, advice.getInstrumentationGroupName()) && isInstrumentationEnabled(advice, coreConfiguration); + } + + private static boolean isGroupDisabled(Collection disabledInstrumentations, String instrumentationGroupName) { + return disabledInstrumentations.contains(instrumentationGroupName); + } + + private static boolean isInstrumentationEnabled(ElasticApmInstrumentation advice, CoreConfiguration coreConfiguration) { + return advice.includeWhenInstrumentationIsDisabled() || coreConfiguration.isInstrument(); + } + private static AgentBuilder applyAdvice(final ElasticApmTracer tracer, final AgentBuilder agentBuilder, final ElasticApmInstrumentation advice) { logger.debug("Applying advice {}", advice.getClass().getName()); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/bci/ElasticApmInstrumentation.java b/apm-agent-core/src/main/java/co/elastic/apm/bci/ElasticApmInstrumentation.java index 45a22bd4bc..51da67dbd6 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/bci/ElasticApmInstrumentation.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/bci/ElasticApmInstrumentation.java @@ -89,4 +89,14 @@ public boolean includeWhenInstrumentationIsDisabled() { return false; } + /** + * Returns a name which groups several instrumentations into a logical group. + *

+ * This name is used in {@link co.elastic.apm.configuration.CoreConfiguration#disabledInstrumentations} to exclude a logical group + * of instrumentations. + *

+ * @return a name which groups several instrumentations into a logical group + */ + public abstract String getInstrumentationGroupName(); + } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/configuration/CoreConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/configuration/CoreConfiguration.java index d14464ff22..c6c80ada1e 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/configuration/CoreConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/configuration/CoreConfiguration.java @@ -27,6 +27,8 @@ import org.stagemonitor.configuration.converter.ListValueConverter; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.List; public class CoreConfiguration extends ConfigurationOptionProvider { @@ -164,6 +166,12 @@ public void assertValid(Double value) { .description("Enables distributed tracing and uses the updated json schema to serialize payloads, transactions and spans") .buildWithDefault(false); + private final ConfigurationOption> disabledInstrumentations = ConfigurationOption.stringsOption() + .key("disabled_instrumentations") + .configurationCategory(CORE_CATEGORY) + .description("A list of instrumentations which should be disabled. Valid options are `jdbc`, `servlet-api` and `spring-mvc`.") + .buildWithDefault(Collections.emptyList()); + public boolean isActive() { return active.get(); } @@ -199,4 +207,8 @@ public List getSanitizeFieldNames() { public boolean isDistributedTracingEnabled() { return distributedTracing.get(); } + + public Collection getDisabledInstrumentations() { + return disabledInstrumentations.get(); + } } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/bci/InstrumentationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/bci/InstrumentationTest.java index 9982c258e2..693020e752 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/bci/InstrumentationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/bci/InstrumentationTest.java @@ -19,6 +19,7 @@ */ package co.elastic.apm.bci; +import co.elastic.apm.configuration.CoreConfiguration; import co.elastic.apm.configuration.SpyConfiguration; import co.elastic.apm.impl.ElasticApmTracer; import net.bytebuddy.agent.ByteBuddyAgent; @@ -27,31 +28,44 @@ import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.matcher.ElementMatchers; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; +import org.stagemonitor.configuration.ConfigurationRegistry; + +import java.util.Collections; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; class InstrumentationTest { - @BeforeEach - void setUp() { - ElasticApmAgent.initInstrumentation(ElasticApmTracer.builder() - .configurationRegistry(SpyConfiguration.createSpyConfig()) - .build(), ByteBuddyAgent.install()); - } - - @AfterAll - static void afterAll() { + @AfterEach + void afterAll() { ElasticApmAgent.reset(); } @Test void testIntercept() { + init(SpyConfiguration.createSpyConfig()); assertThat(interceptMe()).isEqualTo("intercepted"); } + @Test + void testDisabled() { + final ConfigurationRegistry config = SpyConfiguration.createSpyConfig(); + when(config.getConfig(CoreConfiguration.class).getDisabledInstrumentations()).thenReturn(Collections.singletonList("test")); + init(config); + assertThat(interceptMe()).isEmpty(); + } + + private void init(ConfigurationRegistry config) { + ElasticApmAgent.initInstrumentation(ElasticApmTracer.builder() + .configurationRegistry(config) + .build(), + ByteBuddyAgent.install(), + Collections.singletonList(new TestInstrumentation())); + } + private String interceptMe() { return ""; } @@ -71,5 +85,10 @@ public ElementMatcher getTypeMatcher() { public ElementMatcher getMethodMatcher() { return ElementMatchers.named("interceptMe"); } + + @Override + public String getInstrumentationGroupName() { + return "test"; + } } } diff --git a/apm-agent-core/src/test/resources/META-INF/services/co.elastic.apm.bci.ElasticApmInstrumentation b/apm-agent-core/src/test/resources/META-INF/services/co.elastic.apm.bci.ElasticApmInstrumentation deleted file mode 100644 index 81f4e4b091..0000000000 --- a/apm-agent-core/src/test/resources/META-INF/services/co.elastic.apm.bci.ElasticApmInstrumentation +++ /dev/null @@ -1 +0,0 @@ -co.elastic.apm.bci.InstrumentationTest$TestInstrumentation diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/ElasticApmApiInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/ElasticApmApiInstrumentation.java index ea12bd68e7..9d994fd888 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/ElasticApmApiInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/ElasticApmApiInstrumentation.java @@ -35,6 +35,7 @@ */ public class ElasticApmApiInstrumentation extends ElasticApmInstrumentation { + static final String PUBLIC_API_INSTRUMENTATION_GROUP = "public-api"; private final ElementMatcher methodMatcher; ElasticApmApiInstrumentation(ElementMatcher methodMatcher) { @@ -56,6 +57,11 @@ public boolean includeWhenInstrumentationIsDisabled() { return true; } + @Override + public String getInstrumentationGroupName() { + return PUBLIC_API_INSTRUMENTATION_GROUP; + } + public static class StartTransactionInstrumentation extends ElasticApmApiInstrumentation { public StartTransactionInstrumentation() { super(named("doStartTransaction")); diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/SpanInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/SpanInstrumentation.java index 1e375ade1e..9d78fa1642 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/SpanInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/SpanInstrumentation.java @@ -28,6 +28,7 @@ import net.bytebuddy.implementation.bytecode.assign.Assigner; import net.bytebuddy.matcher.ElementMatcher; +import static co.elastic.apm.plugin.api.ElasticApmApiInstrumentation.PUBLIC_API_INSTRUMENTATION_GROUP; import static net.bytebuddy.matcher.ElementMatchers.named; /** @@ -56,6 +57,11 @@ public boolean includeWhenInstrumentationIsDisabled() { return true; } + @Override + public String getInstrumentationGroupName() { + return PUBLIC_API_INSTRUMENTATION_GROUP; + } + public static class SetNameInstrumentation extends SpanInstrumentation { public SetNameInstrumentation() { super(named("setName")); diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java index 71ab60a876..b8bd36b76a 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/plugin/api/TransactionInstrumentation.java @@ -28,6 +28,7 @@ import net.bytebuddy.implementation.bytecode.assign.Assigner; import net.bytebuddy.matcher.ElementMatcher; +import static co.elastic.apm.plugin.api.ElasticApmApiInstrumentation.PUBLIC_API_INSTRUMENTATION_GROUP; import static net.bytebuddy.matcher.ElementMatchers.named; /** @@ -51,6 +52,11 @@ public ElementMatcher getMethodMatcher() { return methodMatcher; } + @Override + public String getInstrumentationGroupName() { + return PUBLIC_API_INSTRUMENTATION_GROUP; + } + @Override public boolean includeWhenInstrumentationIsDisabled() { return true; diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/jdbc/ConnectionInstrumentation.java b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/jdbc/ConnectionInstrumentation.java index 6ccea467ef..2ade5fd6cc 100644 --- a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/jdbc/ConnectionInstrumentation.java +++ b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/jdbc/ConnectionInstrumentation.java @@ -48,6 +48,7 @@ */ public class ConnectionInstrumentation extends ElasticApmInstrumentation { + static final String JDBC_INSTRUMENTATION_GROUP = "jdbc"; private static final Map statementSqlMap = Collections.synchronizedMap(new WeakHashMap()); @@ -90,4 +91,9 @@ public ElementMatcher getMethodMatcher() { .and(takesArgument(0, String.class)); } + @Override + public String getInstrumentationGroupName() { + return JDBC_INSTRUMENTATION_GROUP; + } + } diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/jdbc/PreparedStatementInstrumentation.java b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/jdbc/PreparedStatementInstrumentation.java index 5505f94c49..19e8e8cb81 100644 --- a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/jdbc/PreparedStatementInstrumentation.java +++ b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/jdbc/PreparedStatementInstrumentation.java @@ -32,6 +32,7 @@ import java.sql.PreparedStatement; import java.sql.SQLException; +import static co.elastic.apm.jdbc.ConnectionInstrumentation.JDBC_INSTRUMENTATION_GROUP; import static net.bytebuddy.matcher.ElementMatchers.isInterface; import static net.bytebuddy.matcher.ElementMatchers.isPublic; import static net.bytebuddy.matcher.ElementMatchers.isSubTypeOf; @@ -90,4 +91,9 @@ public ElementMatcher getMethodMatcher() { .and(isPublic()) .and(takesArguments(0)); } + + @Override + public String getInstrumentationGroupName() { + return JDBC_INSTRUMENTATION_GROUP; + } } diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/jdbc/StatementInstrumentation.java b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/jdbc/StatementInstrumentation.java index 6f32e23f78..c6c8f044f5 100644 --- a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/jdbc/StatementInstrumentation.java +++ b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/jdbc/StatementInstrumentation.java @@ -32,6 +32,7 @@ import java.sql.SQLException; import java.sql.Statement; +import static co.elastic.apm.jdbc.ConnectionInstrumentation.JDBC_INSTRUMENTATION_GROUP; import static net.bytebuddy.matcher.ElementMatchers.isInterface; import static net.bytebuddy.matcher.ElementMatchers.isPublic; import static net.bytebuddy.matcher.ElementMatchers.isSubTypeOf; @@ -92,4 +93,9 @@ public ElementMatcher getMethodMatcher() { .and(isPublic()) .and(takesArgument(0, String.class)); } + + @Override + public String getInstrumentationGroupName() { + return JDBC_INSTRUMENTATION_GROUP; + } } diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ApmScopeInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ApmScopeInstrumentation.java index 46c0bcaf8e..447d79069e 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ApmScopeInstrumentation.java +++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ApmScopeInstrumentation.java @@ -7,9 +7,9 @@ * Licensed 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. @@ -28,6 +28,7 @@ import javax.annotation.Nullable; +import static co.elastic.apm.opentracing.impl.ApmSpanInstrumentation.OPENTRACING_INSTRUMENTATION_GROUP; import static net.bytebuddy.matcher.ElementMatchers.named; public class ApmScopeInstrumentation extends ElasticApmInstrumentation { @@ -59,4 +60,9 @@ public ElementMatcher getMethodMatcher() { public boolean includeWhenInstrumentationIsDisabled() { return true; } + + @Override + public String getInstrumentationGroupName() { + return OPENTRACING_INSTRUMENTATION_GROUP; + } } diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ApmSpanBuilderInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ApmSpanBuilderInstrumentation.java index 34a7509fa6..79f47076c1 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ApmSpanBuilderInstrumentation.java +++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ApmSpanBuilderInstrumentation.java @@ -7,9 +7,9 @@ * Licensed 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. @@ -37,6 +37,7 @@ import javax.annotation.Nullable; import java.util.Map; +import static co.elastic.apm.opentracing.impl.ApmSpanInstrumentation.OPENTRACING_INSTRUMENTATION_GROUP; import static net.bytebuddy.matcher.ElementMatchers.named; public class ApmSpanBuilderInstrumentation extends ElasticApmInstrumentation { @@ -68,6 +69,11 @@ public boolean includeWhenInstrumentationIsDisabled() { return true; } + @Override + public String getInstrumentationGroupName() { + return OPENTRACING_INSTRUMENTATION_GROUP; + } + public static class StartApmSpanInstrumentation extends ApmSpanBuilderInstrumentation { public StartApmSpanInstrumentation() { diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ApmSpanInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ApmSpanInstrumentation.java index 179253e097..0ade3c18f7 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ApmSpanInstrumentation.java +++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ApmSpanInstrumentation.java @@ -39,6 +39,8 @@ public class ApmSpanInstrumentation extends ElasticApmInstrumentation { + static final String OPENTRACING_INSTRUMENTATION_GROUP = "opentracing"; + private final ElementMatcher methodMatcher; public ApmSpanInstrumentation(ElementMatcher methodMatcher) { @@ -60,6 +62,11 @@ public boolean includeWhenInstrumentationIsDisabled() { return true; } + @Override + public String getInstrumentationGroupName() { + return OPENTRACING_INSTRUMENTATION_GROUP; + } + public static class FinishInstrumentation extends ApmSpanInstrumentation { public FinishInstrumentation() { super(named("finishInternal")); diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ScopeManagerInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ScopeManagerInstrumentation.java index 750ae4582a..1cf3c9678f 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ScopeManagerInstrumentation.java +++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/opentracing/impl/ScopeManagerInstrumentation.java @@ -31,6 +31,7 @@ import javax.annotation.Nullable; +import static co.elastic.apm.opentracing.impl.ApmSpanInstrumentation.OPENTRACING_INSTRUMENTATION_GROUP; import static net.bytebuddy.matcher.ElementMatchers.named; public class ScopeManagerInstrumentation extends ElasticApmInstrumentation { @@ -56,6 +57,11 @@ public boolean includeWhenInstrumentationIsDisabled() { return true; } + @Override + public String getInstrumentationGroupName() { + return OPENTRACING_INSTRUMENTATION_GROUP; + } + public static class ActivateInstrumentation extends ScopeManagerInstrumentation { public ActivateInstrumentation() { diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/servlet/FilterChainInstrumentation.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/servlet/FilterChainInstrumentation.java index 24a277381c..52fda053c8 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/servlet/FilterChainInstrumentation.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/servlet/FilterChainInstrumentation.java @@ -40,6 +40,7 @@ import java.security.Principal; import java.util.Enumeration; +import static co.elastic.apm.servlet.ServletInstrumentation.SERVLET_API; import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; import static net.bytebuddy.matcher.ElementMatchers.isInterface; import static net.bytebuddy.matcher.ElementMatchers.nameContains; @@ -52,6 +53,7 @@ */ public class FilterChainInstrumentation extends ElasticApmInstrumentation { + @VisibleForAdvice public static final String EXCLUDE_REQUEST = "elastic.apm.servlet.request.exclude"; @Override @@ -81,6 +83,11 @@ public Class getAdviceClass() { return FilterChainAdvice.class; } + @Override + public String getInstrumentationGroupName() { + return SERVLET_API; + } + /** * Only the methods annotated with {@link Advice.OnMethodEnter} and {@link Advice.OnMethodExit} may contain references to * {@code javax.servlet}, as these are inlined into the matching methods. diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/servlet/ServletInstrumentation.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/servlet/ServletInstrumentation.java index 3bd3c14014..ec25605540 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/servlet/ServletInstrumentation.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/servlet/ServletInstrumentation.java @@ -57,6 +57,8 @@ */ public class ServletInstrumentation extends ElasticApmInstrumentation { + static final String SERVLET_API = "servlet-api"; + @Override public void init(ElasticApmTracer tracer) { ServletAdvice.init(tracer); @@ -84,6 +86,11 @@ public Class getAdviceClass() { return ServletAdvice.class; } + @Override + public String getInstrumentationGroupName() { + return SERVLET_API; + } + /** * Only the methods annotated with {@link Advice.OnMethodEnter} and {@link Advice.OnMethodExit} may contain references to * {@code javax.servlet}, as these are inlined into the matching methods. diff --git a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/servlet/ServletInstrumentationTest.java b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/servlet/ServletInstrumentationTest.java index 096365483f..b5b8852a40 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/servlet/ServletInstrumentationTest.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/servlet/ServletInstrumentationTest.java @@ -147,5 +147,10 @@ public ElementMatcher getTypeMatcher() { public ElementMatcher getMethodMatcher() { return none(); } + + @Override + public String getInstrumentationGroupName() { + return "noop"; + } } } diff --git a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/spring/webmvc/SpringTransactionNameInstrumentation.java b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/spring/webmvc/SpringTransactionNameInstrumentation.java index df28139e80..e8ddeecb17 100644 --- a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/spring/webmvc/SpringTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/spring/webmvc/SpringTransactionNameInstrumentation.java @@ -7,9 +7,9 @@ * Licensed 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. @@ -86,6 +86,11 @@ public Class getAdviceClass() { return HandlerAdapterAdvice.class; } + @Override + public String getInstrumentationGroupName() { + return "spring-mvc"; + } + @VisibleForAdvice public static class HandlerAdapterAdvice { @Nullable diff --git a/docs/configuration.asciidoc b/docs/configuration.asciidoc index d0ccfe515a..cd684be8df 100644 --- a/docs/configuration.asciidoc +++ b/docs/configuration.asciidoc @@ -221,6 +221,26 @@ you should add an additional entry to this list (make sure to also include the d | `elastic.apm.sanitize_field_names` | `ELASTIC_APM_SANITIZE_FIELD_NAMES` |============ +[float] +[[config-disabled-instrumentations]] +==== `disabled_instrumentations` + +A list of instrumentations which should be disabled. Valid options are `jdbc`, `servlet-api` and `spring-mvc`. + + +[options="header"] +|============ +| Default | Type | Dynamic +| `` | Collection | false +|============ + + +[options="header"] +|============ +| Java System Properties | Environment +| `elastic.apm.disabled_instrumentations` | `ELASTIC_APM_DISABLED_INSTRUMENTATIONS` +|============ + [[http]] === HTTP configuration options [float]