diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index da3537e08a..e9ec038fe1 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -32,6 +32,7 @@ endif::[] There will always be one history file `${log_file}.1`. * Add <> and <> with the options `PLAIN_TEXT` and `JSON`. The latter uses https://github.com/elastic/ecs-logging-java[ecs-logging-java] to format the logs. +* Exposing <> config - {pull}1187[#1187] [float] diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java index 9781445260..9928294d88 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java @@ -397,8 +397,6 @@ public static synchronized void reset() { } private static AgentBuilder getAgentBuilder(final ByteBuddy byteBuddy, final CoreConfiguration coreConfiguration, Logger logger, AgentBuilder.DescriptionStrategy descriptionStrategy, boolean premain) { - final List classesExcludedFromInstrumentation = coreConfiguration.getClassesExcludedFromInstrumentation(); - AgentBuilder.LocationStrategy locationStrategy = AgentBuilder.LocationStrategy.ForClassLoader.WEAK; if (agentJarFile != null) { try { @@ -472,7 +470,13 @@ private static AgentBuilder getAgentBuilder(final ByteBuddy byteBuddy, final Cor .or(new ElementMatcher.Junction.AbstractBase() { @Override public boolean matches(TypeDescription target) { - return WildcardMatcher.anyMatch(classesExcludedFromInstrumentation, target.getName()) != null; + return WildcardMatcher.anyMatch(coreConfiguration.getDefaultClassesExcludedFromInstrumentation(), target.getName()) != null; + } + }) + .or(new ElementMatcher.Junction.AbstractBase() { + @Override + public boolean matches(TypeDescription target) { + return WildcardMatcher.anyMatch(coreConfiguration.getClassesExcludedFromInstrumentation(), target.getName()) != null; } }) .disableClassFormatChanges(); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfiguration.java index eba26f9e0c..a09216b626 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfiguration.java @@ -334,11 +334,22 @@ public class CoreConfiguration extends ConfigurationOptionProvider { .builder(new ListValueConverter<>(new WildcardMatcherValueConverter()), List.class) .key("classes_excluded_from_instrumentation") .configurationCategory(CORE_CATEGORY) + .description("Use to exclude specific classes from being instrumented. In order to exclude entire packages, \n" + + "use wildcards, as in: `com.project.exclude.*`" + + "\n" + + WildcardMatcher.DOCUMENTATION) + .dynamic(false) + .buildWithDefault(Collections.emptyList()); + + private final ConfigurationOption> defaultClassesExcludedFromInstrumentation = ConfigurationOption + .builder(new ListValueConverter<>(new WildcardMatcherValueConverter()), List.class) + .key("classes_excluded_from_instrumentation_default") + .configurationCategory(CORE_CATEGORY) .tags("internal") .description("\n" + "\n" + WildcardMatcher.DOCUMENTATION) - .dynamic(true) + .dynamic(false) .buildWithDefault(Arrays.asList( WildcardMatcher.valueOf("(?-i)org.infinispan*"), WildcardMatcher.valueOf("(?-i)org.apache.xerces*"), @@ -638,6 +649,10 @@ public List getClassesExcludedFromInstrumentation() { return classesExcludedFromInstrumentation.get(); } + public List getDefaultClassesExcludedFromInstrumentation() { + return defaultClassesExcludedFromInstrumentation.get(); + } + public List getMethodsExcludedFromInstrumentation() { return methodsExcludedFromInstrumentation.get(); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/MockTracer.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/MockTracer.java index 0285c048c8..ccab63fb6f 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/MockTracer.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/MockTracer.java @@ -129,6 +129,15 @@ public static synchronized MockInstrumentationSetup getOrCreateInstrumentationTr ); } + public static synchronized void resetTracer() { + ElasticApmTracer tracer = ElasticApmInstrumentation.tracer; + if (tracer != null) { + ElasticApmAgent.reset(); + tracer.stop(); + ElasticApmInstrumentation.tracer = null; + } + } + /** * Like {@link #create(ConfigurationRegistry)} but with a {@link SpyConfiguration#createSpyConfig() mocked ConfigurationRegistry}. * diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/InstrumentationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/InstrumentationTest.java index 947256125f..cb7db0d505 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/InstrumentationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/InstrumentationTest.java @@ -29,6 +29,7 @@ import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.ElasticApmTracerBuilder; +import co.elastic.apm.agent.matcher.WildcardMatcher; import net.bytebuddy.agent.ByteBuddyAgent; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; @@ -37,6 +38,7 @@ import net.bytebuddy.matcher.ElementMatchers; import org.apache.commons.math.util.MathUtils; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.stagemonitor.configuration.ConfigurationRegistry; @@ -50,30 +52,39 @@ class InstrumentationTest { - private final ElasticApmTracer tracer = MockTracer.create(); + private ElasticApmTracer tracer; + private ConfigurationRegistry configurationRegistry; + private CoreConfiguration coreConfig; + + @BeforeEach + void setup() { + tracer = MockTracer.create(); + configurationRegistry = SpyConfiguration.createSpyConfig(); + coreConfig = configurationRegistry.getConfig(CoreConfiguration.class); + } @AfterEach - void afterAll() { - ElasticApmAgent.reset(); + void reset() { + MockTracer.resetTracer(); } @Test void testIntercept() { - init(SpyConfiguration.createSpyConfig(), List.of(new TestInstrumentation())); + init(configurationRegistry, List.of(new TestInstrumentation())); assertThat(interceptMe()).isEqualTo("intercepted"); } @Test void testDisabled() { - final ConfigurationRegistry config = SpyConfiguration.createSpyConfig(); - when(config.getConfig(CoreConfiguration.class).getDisabledInstrumentations()).thenReturn(Collections.singletonList("test")); - init(config, List.of(new TestInstrumentation())); + when(coreConfig.getDisabledInstrumentations()). + thenReturn(Collections.singletonList("test")); + init(configurationRegistry, List.of(new TestInstrumentation())); assertThat(interceptMe()).isEmpty(); } @Test void testEnsureInstrumented() { - init(SpyConfiguration.createSpyConfig(), List.of()); + init(configurationRegistry, List.of()); assertThat(interceptMe()).isEmpty(); ElasticApmAgent.ensureInstrumented(getClass(), List.of(TestInstrumentation.class)); assertThat(interceptMe()).isEqualTo("intercepted"); @@ -81,48 +92,79 @@ void testEnsureInstrumented() { @Test void testReInitEnableOneInstrumentation() { - final ConfigurationRegistry config = SpyConfiguration.createSpyConfig(); - CoreConfiguration configConfig = config.getConfig(CoreConfiguration.class); - when(configConfig.getDisabledInstrumentations()).thenReturn(Collections.singletonList("test")); - init(config, List.of(new TestInstrumentation())); + when(coreConfig.getDisabledInstrumentations()).thenReturn(Collections.singletonList("test")); + init(configurationRegistry, List.of(new TestInstrumentation())); assertThat(interceptMe()).isEmpty(); - when(configConfig.getDisabledInstrumentations()).thenReturn(List.of()); + when(coreConfig.getDisabledInstrumentations()).thenReturn(List.of()); ElasticApmAgent.doReInitInstrumentation(List.of(new TestInstrumentation())); assertThat(interceptMe()).isEqualTo("intercepted"); } @Test void testDefaultDisabledInstrumentation() { - final ConfigurationRegistry config = SpyConfiguration.createSpyConfig(); - - init(config, List.of(new TestInstrumentation())); + init(configurationRegistry, List.of(new TestInstrumentation())); assertThat(interceptMe()).isEqualTo("intercepted"); - when(config.getConfig(CoreConfiguration.class).getDisabledInstrumentations()).thenReturn(Collections.singletonList("experimental")); + when(coreConfig.getDisabledInstrumentations()) + .thenReturn(Collections.singletonList("experimental")); ElasticApmAgent.doReInitInstrumentation(List.of(new TestInstrumentation())); assertThat(interceptMe()).isEmpty(); } @Test - void testLegacyDefaultDisabledInstrumentation() { - final ConfigurationRegistry config = SpyConfiguration.createSpyConfig(); + void testExcludedClassesFromInstrumentation() { + when(coreConfig.getClassesExcludedFromInstrumentation()) + .thenReturn(List.of(WildcardMatcher.valueOf("co.elastic.apm.agent.bci.InstrumentationTest"))); + init(configurationRegistry, List.of(new TestInstrumentation())); + ElasticApmAgent.doReInitInstrumentation(List.of(new TestInstrumentation())); + assertThat(interceptMe()).isEmpty(); + } + + @Test + void testExcludedPackageFromInstrumentation() { + when(coreConfig.getClassesExcludedFromInstrumentation()) + .thenReturn(List.of(WildcardMatcher.valueOf("co.elastic.apm.agent.bci.*"))); + init(configurationRegistry, List.of(new TestInstrumentation())); + ElasticApmAgent.doReInitInstrumentation(List.of(new TestInstrumentation())); + assertThat(interceptMe()).isEmpty(); + } - init(config, List.of(new TestInstrumentation())); + @Test + void testExcludedDefaultClassesFromInstrumentation() { + when(coreConfig.getDefaultClassesExcludedFromInstrumentation()) + .thenReturn(List.of(WildcardMatcher.valueOf("co.elastic.apm.agent.bci.InstrumentationTest"))); + init(configurationRegistry, List.of(new TestInstrumentation())); + ElasticApmAgent.doReInitInstrumentation(List.of(new TestInstrumentation())); + assertThat(interceptMe()).isEmpty(); + } + + @Test + void testExcludedDefaultPackageFromInstrumentation() { + when(coreConfig.getDefaultClassesExcludedFromInstrumentation()) + .thenReturn(List.of(WildcardMatcher.valueOf("co.elastic.apm.agent.bci.*"))); + init(configurationRegistry, List.of(new TestInstrumentation())); + ElasticApmAgent.doReInitInstrumentation(List.of(new TestInstrumentation())); + assertThat(interceptMe()).isEmpty(); + } + + @Test + void testLegacyDefaultDisabledInstrumentation() { + init(configurationRegistry, List.of(new TestInstrumentation())); assertThat(interceptMe()).isEqualTo("intercepted"); - when(config.getConfig(CoreConfiguration.class).getDisabledInstrumentations()).thenReturn(Collections.singletonList("incubating")); + when(coreConfig.getDisabledInstrumentations()) + .thenReturn(Collections.singletonList("incubating")); ElasticApmAgent.doReInitInstrumentation(List.of(new TestInstrumentation())); assertThat(interceptMe()).isEmpty(); } @Test void testReInitDisableAllInstrumentations() { - final ConfigurationRegistry config = SpyConfiguration.createSpyConfig(); - init(config, List.of(new TestInstrumentation())); + init(configurationRegistry, List.of(new TestInstrumentation())); assertThat(interceptMe()).isEqualTo("intercepted"); - when(config.getConfig(CoreConfiguration.class).isInstrument()).thenReturn(false); + when(coreConfig.isInstrument()).thenReturn(false); ElasticApmAgent.doReInitInstrumentation(List.of(new TestInstrumentation())); assertThat(interceptMe()).isEmpty(); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyProcessorTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyProcessorTest.java index b9a0a53809..e4999c2366 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyProcessorTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyProcessorTest.java @@ -11,9 +11,9 @@ * 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 @@ -36,7 +36,7 @@ import static co.elastic.apm.agent.impl.context.AbstractContext.REDACTED_CONTEXT_STRING; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.doReturn; class BodyProcessorTest { @@ -54,7 +54,7 @@ void setUp() { @Test void processBeforeReport_Transaction_EventTypeAll() { - when(config.getCaptureBody()).thenReturn(CoreConfiguration.EventType.ALL); + doReturn(CoreConfiguration.EventType.ALL).when(config).getCaptureBody(); final Transaction transaction = processTransaction(); @@ -64,7 +64,7 @@ void processBeforeReport_Transaction_EventTypeAll() { @Test void processBeforeReport_Transaction_EventTypeTransaction() { - when(config.getCaptureBody()).thenReturn(CoreConfiguration.EventType.TRANSACTIONS); + doReturn(CoreConfiguration.EventType.TRANSACTIONS).when(config).getCaptureBody(); final Transaction transaction = processTransaction(); @@ -74,7 +74,7 @@ void processBeforeReport_Transaction_EventTypeTransaction() { @Test void processBeforeReport_Transaction_EventTypeError() { - when(config.getCaptureBody()).thenReturn(CoreConfiguration.EventType.ERRORS); + doReturn(CoreConfiguration.EventType.ERRORS).when(config).getCaptureBody(); final Transaction transaction = processTransaction(); @@ -84,7 +84,7 @@ void processBeforeReport_Transaction_EventTypeError() { @Test void processBeforeReport_Transaction_EventTypeOff() { - when(config.getCaptureBody()).thenReturn(CoreConfiguration.EventType.OFF); + doReturn(CoreConfiguration.EventType.OFF).when(config).getCaptureBody(); final Transaction transaction = processTransaction(); @@ -94,7 +94,7 @@ void processBeforeReport_Transaction_EventTypeOff() { @Test void processBeforeReport_Error_EventTypeAll() { - when(config.getCaptureBody()).thenReturn(CoreConfiguration.EventType.ALL); + doReturn(CoreConfiguration.EventType.ALL).when(config).getCaptureBody(); final ErrorCapture error = processError(); @@ -104,7 +104,7 @@ void processBeforeReport_Error_EventTypeAll() { @Test void processBeforeReport_Error_EventTypeTransaction() { - when(config.getCaptureBody()).thenReturn(CoreConfiguration.EventType.TRANSACTIONS); + doReturn(CoreConfiguration.EventType.TRANSACTIONS).when(config).getCaptureBody(); final ErrorCapture error = processError(); @@ -114,7 +114,7 @@ void processBeforeReport_Error_EventTypeTransaction() { @Test void processBeforeReport_Error_EventTypeError() { - when(config.getCaptureBody()).thenReturn(CoreConfiguration.EventType.ERRORS); + doReturn(CoreConfiguration.EventType.ERRORS).when(config).getCaptureBody(); final ErrorCapture error = processError(); @@ -124,7 +124,7 @@ void processBeforeReport_Error_EventTypeError() { @Test void processBeforeReport_Error_EventTypeOff() { - when(config.getCaptureBody()).thenReturn(CoreConfiguration.EventType.OFF); + doReturn(CoreConfiguration.EventType.OFF).when(config).getCaptureBody(); final ErrorCapture error = processError(); diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcContextHeadersTest.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcContextHeadersTest.java index 60e4f3d91d..cbb48d53c4 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcContextHeadersTest.java +++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcContextHeadersTest.java @@ -92,7 +92,7 @@ void simpleClientContextPropagation() { Transaction transaction2 = transactions.stream() .filter((t) -> !t.equals(transaction1)) .findFirst() - .orElseThrow(); + .orElseThrow(() -> null); Span span = reporter.getFirstSpan(); diff --git a/apm-agent-plugins/apm-jms-plugin/src/test/java/co/elastic/apm/agent/jms/JmsInstrumentationIT.java b/apm-agent-plugins/apm-jms-plugin/src/test/java/co/elastic/apm/agent/jms/JmsInstrumentationIT.java index 321964b589..8c6e19a431 100644 --- a/apm-agent-plugins/apm-jms-plugin/src/test/java/co/elastic/apm/agent/jms/JmsInstrumentationIT.java +++ b/apm-agent-plugins/apm-jms-plugin/src/test/java/co/elastic/apm/agent/jms/JmsInstrumentationIT.java @@ -79,6 +79,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; @RunWith(Parameterized.class) @@ -125,7 +126,7 @@ public void startTransaction() throws Exception { startAndActivateTransaction(null); brokerFacade.beforeTest(); noopQ = brokerFacade.createQueue("NOOP"); - when(coreConfiguration.getCaptureBody()).thenReturn(CoreConfiguration.EventType.ALL); + doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); } private void startAndActivateTransaction(@Nullable Sampler sampler) { diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyClientIT.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyClientIT.java index 0a4ec49207..66620b4fbd 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyClientIT.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyClientIT.java @@ -60,11 +60,12 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; /** * This test is disabled because may fail on CI, maybe because of running in parallel to the current client test. - * It is still useful to be ran locally to test the legacy client. + * It is still useful to run locally to test the legacy client. *

* Each test sends a message to a request topic and waits on a reply message. This serves two purposes: * 1. reduce waits to a minimum within tests @@ -210,7 +211,7 @@ public void testSendTwoRecords_PartiallyIterate() { @Test public void testBodyCaptureEnabled() { - when(coreConfiguration.getCaptureBody()).thenReturn(CoreConfiguration.EventType.ALL); + doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); testScenario = TestScenario.BODY_CAPTURE_ENABLED; consumerThread.setIterationMode(RecordIterationMode.ITERABLE_FOR); sendTwoRecordsAndConsumeReplies(); diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaIT.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaIT.java index c77268f66d..120c3914a0 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaIT.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaIT.java @@ -68,6 +68,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; /** @@ -230,7 +231,7 @@ public void testSendTwoRecords_PartiallyIterate() { @Test public void testBodyCaptureEnabled() { - when(coreConfiguration.getCaptureBody()).thenReturn(CoreConfiguration.EventType.ALL); + doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); testScenario = TestScenario.BODY_CAPTURE_ENABLED; consumerThread.setIterationMode(RecordIterationMode.ITERABLE_FOR); sendTwoRecordsAndConsumeReplies(); diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyBrokerIT.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyBrokerIT.java index 2cb93024bc..4d337dfe74 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyBrokerIT.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyBrokerIT.java @@ -63,12 +63,13 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; /** * Tests newer client with a 0.10.2.2 version. * This test is disabled because may fail on CI, maybe because of running in parallel to the current broker test. - * It is still useful to be ran locally to test the legacy broker. + * It is still useful to run locally to test the legacy broker. *

* Each test sends a message to a request topic and waits on a reply message. This serves two purposes: * 1. reduce waits to a minimum within tests @@ -214,7 +215,7 @@ public void testSendTwoRecords_PartiallyIterate() { @Test public void testBodyCaptureEnabled() { - when(coreConfiguration.getCaptureBody()).thenReturn(CoreConfiguration.EventType.ALL); + doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); testScenario = TestScenario.BODY_CAPTURE_ENABLED; consumerThread.setIterationMode(RecordIterationMode.ITERABLE_FOR); sendTwoRecordsAndConsumeReplies(); diff --git a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/TestRequestBodyCapturing.java b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/TestRequestBodyCapturing.java index 9e742cfe32..179ea52fc7 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/TestRequestBodyCapturing.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/TestRequestBodyCapturing.java @@ -61,6 +61,7 @@ import static co.elastic.apm.agent.impl.context.AbstractContext.REDACTED_CONTEXT_STRING; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; class TestRequestBodyCapturing extends AbstractInstrumentationTest { @@ -94,7 +95,7 @@ static Stream streamConsumers() { void setUp() { webConfiguration = tracer.getConfig(WebConfiguration.class); coreConfiguration = tracer.getConfig(CoreConfiguration.class); - when(coreConfiguration.getCaptureBody()).thenReturn(CoreConfiguration.EventType.ALL); + doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); filterChain = new MockFilterChain(new HttpServlet() { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { @@ -133,7 +134,7 @@ void testReadTextPlain(InputStreamConsumer consumer) throws Exception { @Test void testCaptureBodyOff() throws Exception { - when(coreConfiguration.getCaptureBody()).thenReturn(CoreConfiguration.EventType.OFF); + doReturn(CoreConfiguration.EventType.OFF).when(coreConfiguration).getCaptureBody(); executeRequest(filterChain, "foo".getBytes(StandardCharsets.UTF_8), "text/plain"); final Object body = reporter.getFirstTransaction().getContext().getRequest().getBody(); @@ -146,7 +147,7 @@ void testCaptureBodyOff() throws Exception { void testCaptureBodyNotOff(CoreConfiguration.EventType eventType) throws Exception { streamCloser = is -> { throw new RuntimeException(); }; - when(coreConfiguration.getCaptureBody()).thenReturn(eventType); + doReturn(eventType).when(coreConfiguration).getCaptureBody(); executeRequest(filterChain, "foo".getBytes(StandardCharsets.UTF_8), "text/plain"); final Transaction transaction = reporter.getFirstTransaction(); @@ -231,7 +232,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I @Test void testTrackPostParams() throws IOException, ServletException { - when(coreConfiguration.getCaptureBody()).thenReturn(CoreConfiguration.EventType.ALL); + doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/foo/bar"); request.addParameter("foo", "bar"); request.addParameter("baz", "qux", "quux"); @@ -246,7 +247,7 @@ void testTrackPostParams() throws IOException, ServletException { @Test void testTrackPostParamsDisabled() throws IOException, ServletException { - when(coreConfiguration.getCaptureBody()).thenReturn(CoreConfiguration.EventType.ALL); + doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); when(webConfiguration.getCaptureContentTypes()).thenReturn(Collections.emptyList()); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/foo/bar"); request.addParameter("foo", "bar"); diff --git a/docs/configuration.asciidoc b/docs/configuration.asciidoc index bc8a70dc07..74c04752aa 100644 --- a/docs/configuration.asciidoc +++ b/docs/configuration.asciidoc @@ -114,6 +114,7 @@ Click on a key to get more information. ** <> ** <> ** <> +** <> ** <> ** <> ** <> @@ -848,6 +849,34 @@ NOTE: This feature requires APM Server 7.2+ | `elastic.apm.global_labels` | `global_labels` | `ELASTIC_APM_GLOBAL_LABELS` |============ +// This file is auto generated. Please make your changes in *Configuration.java (for example CoreConfiguration.java) and execute ConfigurationExporter +[float] +[[config-classes-excluded-from-instrumentation]] +==== `classes_excluded_from_instrumentation` + +Use to exclude specific classes from being instrumented. In order to exclude entire packages, +use wildcards, as in: `com.project.exclude.*` +This option supports the wildcard `*`, which matches zero or more characters. +Examples: `/foo/*/bar/*/baz*`, `*foo*`. +Matching is case insensitive by default. +Prepending an element with `(?-i)` makes the matching case sensitive. + + + + +[options="header"] +|============ +| Default | Type | Dynamic +| `` | List | false +|============ + + +[options="header"] +|============ +| Java System Properties | Property file | Environment +| `elastic.apm.classes_excluded_from_instrumentation` | `classes_excluded_from_instrumentation` | `ELASTIC_APM_CLASSES_EXCLUDED_FROM_INSTRUMENTATION` +|============ + // This file is auto generated. Please make your changes in *Configuration.java (for example CoreConfiguration.java) and execute ConfigurationExporter [float] [[config-trace-methods]] @@ -2593,6 +2622,19 @@ The default unit for this option is `ms`. # # global_labels= +# Use to exclude specific classes from being instrumented. In order to exclude entire packages, +# use wildcards, as in: `com.project.exclude.*` +# This option supports the wildcard `*`, which matches zero or more characters. +# Examples: `/foo/*/bar/*/baz*`, `*foo*`. +# Matching is case insensitive by default. +# Prepending an element with `(?-i)` makes the matching case sensitive. +# +# This setting can not be changed at runtime. Changes require a restart of the application. +# Type: comma separated list +# Default value: +# +# classes_excluded_from_instrumentation= + # A list of methods for which to create a transaction or span. # # If you want to monitor a large number of methods,