diff --git a/apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/WildcardMatcher.java b/apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/WildcardMatcher.java index 540627d8c6c..17d124d410f 100644 --- a/apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/WildcardMatcher.java +++ b/apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/WildcardMatcher.java @@ -83,7 +83,7 @@ public static WildcardMatcher matchAll() { return MATCH_ALL; } - public static List matchAllList() { + public static List matchAllList() { return MATCH_ALL_LIST; } @@ -138,7 +138,7 @@ public static WildcardMatcher valueOf(final String wildcardString) { * @param s the string to match against * @return {@code true}, if any of the matchers match the provided string */ - public static boolean isAnyMatch(List matchers, @Nullable CharSequence s) { + public static boolean isAnyMatch(List matchers, @Nullable CharSequence s) { return anyMatch(matchers, s) != null; } @@ -149,7 +149,7 @@ public static boolean isAnyMatch(List matchers, @Nullable CharS * @param s the string to match against * @return {@code true}, if none of the matchers match the provided string */ - public static boolean isNoneMatch(List matchers, @Nullable CharSequence s) { + public static boolean isNoneMatch(List matchers, @Nullable CharSequence s) { return !isAnyMatch(matchers, s); } @@ -161,7 +161,7 @@ public static boolean isNoneMatch(List matchers, @Nullable Char * @return the first matching {@link WildcardMatcher}, or {@code null} if none match. */ @Nullable - public static WildcardMatcher anyMatch(List matchers, @Nullable CharSequence s) { + public static WildcardMatcher anyMatch(List matchers, @Nullable CharSequence s) { if (s == null || matchers.isEmpty()) { return null; } @@ -178,7 +178,7 @@ public static WildcardMatcher anyMatch(List matchers, @Nullable * @see #matches(CharSequence, CharSequence) */ @Nullable - public static WildcardMatcher anyMatch(List matchers, CharSequence firstPart, @Nullable CharSequence secondPart) { + public static WildcardMatcher anyMatch(List matchers, CharSequence firstPart, @Nullable CharSequence secondPart) { for (int i = 0; i < matchers.size(); i++) { if (matchers.get(i).matches(firstPart, secondPart)) { return matchers.get(i); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/CustomElementMatchers.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/CustomElementMatchers.java index 5e95dd807dc..981784883af 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/CustomElementMatchers.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/CustomElementMatchers.java @@ -293,7 +293,7 @@ public String toString() { }; } - public static ElementMatcher.Junction anyMatch(final List matchers) { + public static ElementMatcher.Junction anyMatch(final List matchers) { return new ElementMatcher.Junction.AbstractBase() { @Override public boolean matches(NamedElement target) { 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 3a70bd1d3e6..246e88e3a36 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 @@ -19,15 +19,11 @@ package co.elastic.apm.agent.configuration; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.configuration.converter.ListValueConverter; -import co.elastic.apm.agent.configuration.converter.RoundedDoubleConverter; -import co.elastic.apm.agent.configuration.converter.TimeDuration; -import co.elastic.apm.agent.configuration.converter.TimeDurationValueConverter; +import co.elastic.apm.agent.configuration.converter.*; import co.elastic.apm.agent.configuration.validation.RegexValidator; import co.elastic.apm.agent.impl.transaction.Span; import co.elastic.apm.agent.matcher.MethodMatcher; import co.elastic.apm.agent.matcher.MethodMatcherValueConverter; -import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.matcher.WildcardMatcherValueConverter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -59,7 +55,7 @@ import static co.elastic.apm.agent.configuration.validation.RangeValidator.isInRange; import static co.elastic.apm.agent.logging.LoggingConfiguration.AGENT_HOME_PLACEHOLDER; -public class CoreConfiguration extends ConfigurationOptionProvider { +public class CoreConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.plugin.spi.CoreConfiguration { private final Logger logger = LoggerFactory.getLogger(getClass()); @@ -1077,6 +1073,11 @@ public TraceContinuationStrategy getTraceContinuationStrategy() { return traceContinuationStrategy.get(); } + @Override + public boolean isCaptureBody() { + return getCaptureBody() != EventType.OFF; + } + public enum EventType { /** * Request bodies will never be reported diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/MessagingConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/MessagingConfiguration.java index 49c0d7474e0..33d8656d62c 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/MessagingConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/MessagingConfiguration.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.configuration; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.agent.configuration.converter.WildcardMatcher; import co.elastic.apm.agent.matcher.WildcardMatcherValueConverter; import org.stagemonitor.configuration.ConfigurationOption; import org.stagemonitor.configuration.ConfigurationOptionProvider; @@ -28,7 +28,7 @@ import java.util.Collections; import java.util.List; -public class MessagingConfiguration extends ConfigurationOptionProvider { +public class MessagingConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.plugin.spi.MessagingConfiguration { private static final String MESSAGING_CATEGORY = "Messaging"; private static final String MESSAGE_POLLING_TRANSACTION_STRATEGY = "message_polling_transaction_strategy"; private static final String MESSAGE_BATCH_STRATEGY = "message_batch_strategy"; @@ -130,6 +130,21 @@ public Collection getJmsListenerPackages() { return jmsListenerPackages.get(); } + @Override + public boolean isMessageTransactionPolling() { + return getMessagePollingTransactionStrategy() != JmsStrategy.HANDLING; + } + + @Override + public boolean isMessageTransactionHandling() { + return getMessagePollingTransactionStrategy() != JmsStrategy.POLLING; + } + + @Override + public boolean isMessageBatchHandling() { + return getMessageBatchStrategy() == BatchStrategy.BATCH_HANDLING; + } + public enum JmsStrategy { /** * Create a transaction capturing JMS {@code receive} invocations diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/converter/WildcardMatcher.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/converter/WildcardMatcher.java new file mode 100644 index 00000000000..db6d3fb965c --- /dev/null +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/converter/WildcardMatcher.java @@ -0,0 +1,48 @@ +package co.elastic.apm.agent.configuration.converter; + +import javax.annotation.Nullable; +import java.util.Collections; +import java.util.List; + +public class WildcardMatcher extends co.elastic.apm.agent.common.util.WildcardMatcher implements co.elastic.apm.plugin.spi.WildcardMatcher { + + private static final WildcardMatcher MATCH_ALL = new WildcardMatcher(co.elastic.apm.agent.common.util.WildcardMatcher.matchAll()); + private static final List MATCH_ALL_LIST = Collections.singletonList(MATCH_ALL); + + private final co.elastic.apm.agent.common.util.WildcardMatcher matcher; + + public WildcardMatcher(co.elastic.apm.agent.common.util.WildcardMatcher matcher) { + this.matcher = matcher; + } + + public static WildcardMatcher valueOf(String wildcardString) { + return new WildcardMatcher(co.elastic.apm.agent.common.util.WildcardMatcher.valueOf(wildcardString)); + } + + public static WildcardMatcher caseSensitiveMatcher(String matcher) { + return new WildcardMatcher(co.elastic.apm.agent.common.util.WildcardMatcher.caseSensitiveMatcher(matcher)); + } + + public static WildcardMatcher matchAll() { + return MATCH_ALL; + } + + public static List matchAllList() { + return MATCH_ALL_LIST; + } + + @Override + public boolean matches(CharSequence s) { + return matcher.matches(s); + } + + @Override + public boolean matches(CharSequence firstPart, @Nullable CharSequence secondPart) { + return matcher.matches(firstPart, secondPart); + } + + @Override + public String getMatcher() { + return matcher.getMatcher(); + } +} diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/web/WebConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/web/WebConfiguration.java index 79993d9c7dd..0da44d0e2c1 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/web/WebConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/web/WebConfiguration.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.context.web; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.agent.configuration.converter.WildcardMatcher; import co.elastic.apm.agent.matcher.WildcardMatcherValueConverter; import org.stagemonitor.configuration.ConfigurationOption; import org.stagemonitor.configuration.ConfigurationOptionProvider; @@ -28,7 +28,7 @@ import java.util.Collections; import java.util.List; -public class WebConfiguration extends ConfigurationOptionProvider { +public class WebConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.plugin.spi.WebConfiguration { private static final String HTTP_CATEGORY = "HTTP"; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfiguration.java index ad68f1b93b0..adb962edb7a 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfiguration.java @@ -26,7 +26,7 @@ import java.util.Collection; import java.util.Collections; -public class StacktraceConfiguration extends ConfigurationOptionProvider { +public class StacktraceConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.plugin.spi.StacktraceConfiguration { private static final String STACKTRACE_CATEGORY = "Stacktrace"; public static final String APPLICATION_PACKAGES = "application_packages"; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/LoggingConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/LoggingConfiguration.java index f046adc3a4b..3282afa96e6 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/LoggingConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/LoggingConfiguration.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.common.util.SystemStandardOutputLogger; import co.elastic.apm.agent.configuration.converter.ByteValue; import co.elastic.apm.agent.configuration.converter.ByteValueConverter; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.agent.configuration.converter.WildcardMatcher; import co.elastic.apm.agent.matcher.WildcardMatcherValueConverter; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import org.apache.logging.log4j.Level; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/matcher/WildcardMatcherValueConverter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/matcher/WildcardMatcherValueConverter.java index 62ce9af2545..854d55a8ab3 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/matcher/WildcardMatcherValueConverter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/matcher/WildcardMatcherValueConverter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.matcher; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.agent.configuration.converter.WildcardMatcher; import org.stagemonitor.configuration.converter.ValueConverter; /** diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterConfiguration.java index 28655ff078b..40dcefd45b5 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterConfiguration.java @@ -18,11 +18,7 @@ */ package co.elastic.apm.agent.report; -import co.elastic.apm.agent.configuration.converter.ByteValue; -import co.elastic.apm.agent.configuration.converter.ByteValueConverter; -import co.elastic.apm.agent.configuration.converter.TimeDuration; -import co.elastic.apm.agent.configuration.converter.TimeDurationValueConverter; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.agent.configuration.converter.*; import co.elastic.apm.agent.matcher.WildcardMatcherValueConverter; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import org.stagemonitor.configuration.ConfigurationOption; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/tracemethods/TraceMethodInstrumentation.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/tracemethods/TraceMethodInstrumentation.java index 1cdf6a13211..962eae52f82 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/tracemethods/TraceMethodInstrumentation.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/tracemethods/TraceMethodInstrumentation.java @@ -74,7 +74,7 @@ public ElementMatcher getTypeMatcher() { public ElementMatcher getMethodMatcher() { ElementMatcher.Junction matcher = matches(methodMatcher.getMethodMatcher()); - final List methodsExcludedFromInstrumentation = config.getMethodsExcludedFromInstrumentation(); + final List methodsExcludedFromInstrumentation = config.getMethodsExcludedFromInstrumentation(); if (!methodsExcludedFromInstrumentation.isEmpty()) { matcher = matcher.and(not(new ElementMatcher() { @Override diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/TransactionNameUtils.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/TransactionNameUtils.java index 6005f0507c2..888fb6fb203 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/TransactionNameUtils.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/TransactionNameUtils.java @@ -18,7 +18,8 @@ */ package co.elastic.apm.agent.util; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.WildcardMatcher; +import co.elastic.apm.plugin.spi.WildcardMatcherUtil; import javax.annotation.Nullable; import java.util.List; @@ -75,15 +76,15 @@ public static void setNameFromClassAndMethod(String className, @Nullable String } - public static void setNameFromHttpRequestPath(String method, String path, @Nullable StringBuilder transactionName, List urlGroups) { + public static void setNameFromHttpRequestPath(String method, String path, @Nullable StringBuilder transactionName, List urlGroups) { setNameFromHttpRequestPath(method, path, null, transactionName, urlGroups); } - public static void setNameFromHttpRequestPath(String method, String pathFirstPart, @Nullable String pathSecondPart, @Nullable StringBuilder transactionName, List urlGroups) { + public static void setNameFromHttpRequestPath(String method, String pathFirstPart, @Nullable String pathSecondPart, @Nullable StringBuilder transactionName, List urlGroups) { if (transactionName == null) { return; } - WildcardMatcher groupMatcher = WildcardMatcher.anyMatch(urlGroups, pathFirstPart, pathSecondPart); + WildcardMatcher groupMatcher = WildcardMatcherUtil.anyMatch(urlGroups, pathFirstPart, pathSecondPart); if (groupMatcher != null) { transactionName.append(method).append(' ').append(groupMatcher); } else { diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/CoreConfigurationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/CoreConfigurationTest.java index a1ea6cab6cc..303c135785a 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/CoreConfigurationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/CoreConfigurationTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.configuration; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.agent.configuration.converter.WildcardMatcher; import org.junit.jupiter.api.Test; import org.stagemonitor.configuration.ConfigurationRegistry; import org.stagemonitor.configuration.source.SimpleSource; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/util/TransactionNameUtilsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/util/TransactionNameUtilsTest.java index 8225c78fe01..8f965db4348 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/util/TransactionNameUtilsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/util/TransactionNameUtilsTest.java @@ -20,7 +20,8 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.impl.context.web.WebConfiguration; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.WildcardMatcher; +import co.elastic.apm.plugin.spi.WildcardMatcherUtil; import org.jetbrains.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -97,9 +98,9 @@ void testClassAndMethodName() { @Test void setNameFromHttpRequestPath() { - List urlGroups = List.of( - WildcardMatcher.valueOf("/foo/bar/*/qux"), - WildcardMatcher.valueOf("/foo/bar/*") + List urlGroups = List.of( + WildcardMatcherUtil.valueOf("/foo/bar/*/qux"), + WildcardMatcherUtil.valueOf("/foo/bar/*") ); // shuold be a no-op diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/CoreConfiguration.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/CoreConfiguration.java new file mode 100644 index 00000000000..4a1f675bd95 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/CoreConfiguration.java @@ -0,0 +1,15 @@ +package co.elastic.apm.plugin.spi; + +import java.util.List; + +public interface CoreConfiguration { + boolean isEnablePublicApiAnnotationInheritance(); + + boolean isCaptureHeaders(); + + List getSanitizeFieldNames(); + + boolean isCaptureBody(); + + boolean isInstrumentationEnabled(String instrumentationGroupName); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/DisabledObjectPool.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/DisabledObjectPool.java new file mode 100644 index 00000000000..2d63f251e37 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/DisabledObjectPool.java @@ -0,0 +1,23 @@ +package co.elastic.apm.plugin.spi; + +public class DisabledObjectPool implements ObjectPool { + + private final Allocator allocator; + + public DisabledObjectPool(Allocator allocator) { + this.allocator = allocator; + } + + @Override + public T createInstance() { + return allocator.createInstance(); + } + + @Override + public void recycle(T obj) { + } + + @Override + public void clear() { + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/DisabledObjectPoolFactory.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/DisabledObjectPoolFactory.java new file mode 100644 index 00000000000..d0e442a2143 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/DisabledObjectPoolFactory.java @@ -0,0 +1,14 @@ +package co.elastic.apm.plugin.spi; + +public class DisabledObjectPoolFactory implements ObjectPoolFactory { + + public static final ObjectPoolFactory INSTANCE = new DisabledObjectPoolFactory(); + + private DisabledObjectPoolFactory() { + } + + @Override + public ObjectPool createRecyclableObjectPool(int maxCapacity, Allocator allocator) { + return new DisabledObjectPool(allocator); + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyCoreConfiguration.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyCoreConfiguration.java new file mode 100644 index 00000000000..6c67d6d424c --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyCoreConfiguration.java @@ -0,0 +1,37 @@ +package co.elastic.apm.plugin.spi; + +import java.util.Collections; +import java.util.List; + +public class EmptyCoreConfiguration implements CoreConfiguration { + + public static final CoreConfiguration INSTANCE = new EmptyCoreConfiguration(); + + private EmptyCoreConfiguration() { + } + + @Override + public boolean isEnablePublicApiAnnotationInheritance() { + return false; + } + + @Override + public boolean isCaptureHeaders() { + return false; + } + + @Override + public List getSanitizeFieldNames() { + return Collections.emptyList(); + } + + @Override + public boolean isCaptureBody() { + return false; + } + + @Override + public boolean isInstrumentationEnabled(String instrumentationGroupName) { + return false; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyMessagingConfiguration.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyMessagingConfiguration.java new file mode 100644 index 00000000000..a109322c230 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyMessagingConfiguration.java @@ -0,0 +1,48 @@ +package co.elastic.apm.plugin.spi; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +public class EmptyMessagingConfiguration implements MessagingConfiguration { + + public static final MessagingConfiguration INSTANCE = new EmptyMessagingConfiguration(); + + private EmptyMessagingConfiguration() { + } + + @Override + public List getIgnoreMessageQueues() { + return Collections.emptyList(); + } + + @Override + public Collection getJmsListenerPackages() { + return Collections.emptyList(); + } + + @Override + public boolean shouldEndMessagingTransactionOnPoll() { + return false; + } + + @Override + public boolean shouldCollectQueueAddress() { + return false; + } + + @Override + public boolean isMessageTransactionPolling() { + return true; + } + + @Override + public boolean isMessageTransactionHandling() { + return true; + } + + @Override + public boolean isMessageBatchHandling() { + return false; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyStacktraceConfiguration.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyStacktraceConfiguration.java new file mode 100644 index 00000000000..7bc5f0b972d --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyStacktraceConfiguration.java @@ -0,0 +1,17 @@ +package co.elastic.apm.plugin.spi; + +import java.util.Collection; +import java.util.Collections; + +public class EmptyStacktraceConfiguration implements StacktraceConfiguration { + + public static final StacktraceConfiguration INSTANCE = new EmptyStacktraceConfiguration(); + + private EmptyStacktraceConfiguration() { + } + + @Override + public Collection getApplicationPackages() { + return Collections.emptyList(); + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyWebConfiguration.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyWebConfiguration.java new file mode 100644 index 00000000000..be0455e242c --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyWebConfiguration.java @@ -0,0 +1,37 @@ +package co.elastic.apm.plugin.spi; + +import java.util.Collections; +import java.util.List; + +public class EmptyWebConfiguration implements WebConfiguration { + + public static final WebConfiguration INSTANCE = new EmptyWebConfiguration(); + + private EmptyWebConfiguration() { + } + + @Override + public boolean isUsePathAsName() { + return false; + } + + @Override + public List getIgnoreUrls() { + return Collections.emptyList(); + } + + @Override + public List getUrlGroups() { + return Collections.emptyList(); + } + + @Override + public List getCaptureContentTypes() { + return Collections.emptyList(); + } + + @Override + public List getIgnoreUserAgents() { + return Collections.emptyList(); + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/MessagingConfiguration.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/MessagingConfiguration.java new file mode 100644 index 00000000000..9354a52d76e --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/MessagingConfiguration.java @@ -0,0 +1,20 @@ +package co.elastic.apm.plugin.spi; + +import java.util.Collection; +import java.util.List; + +public interface MessagingConfiguration { + List getIgnoreMessageQueues(); + + Collection getJmsListenerPackages(); + + boolean shouldEndMessagingTransactionOnPoll(); + + boolean shouldCollectQueueAddress(); + + boolean isMessageTransactionPolling(); + + boolean isMessageTransactionHandling(); + + boolean isMessageBatchHandling(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/StacktraceConfiguration.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/StacktraceConfiguration.java new file mode 100644 index 00000000000..e8d1fa0a53b --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/StacktraceConfiguration.java @@ -0,0 +1,8 @@ +package co.elastic.apm.plugin.spi; + +import java.util.Collection; + +public interface StacktraceConfiguration { + + Collection getApplicationPackages(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/StringUtils.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/StringUtils.java new file mode 100644 index 00000000000..dde77f73e7d --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/StringUtils.java @@ -0,0 +1,53 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. 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 co.elastic.apm.plugin.spi; + +import java.util.ArrayList; +import java.util.List; + +public class StringUtils { + public static String[] split(final String str, final char separatorChar) { + if (str == null) { + return null; + } + final int len = str.length(); + if (len == 0) { + return new String[0]; + } + final List list = new ArrayList(); + int i = 0, start = 0; + boolean match = false; + while (i < len) { + if (str.charAt(i) == separatorChar) { + if (match) { + list.add(str.substring(start, i)); + match = false; + } + start = ++i; + continue; + } + match = true; + i++; + } + if (match) { + list.add(str.substring(start, i)); + } + return list.toArray(new String[list.size()]); + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/WebConfiguration.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/WebConfiguration.java new file mode 100644 index 00000000000..9a2e77d1ca9 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/WebConfiguration.java @@ -0,0 +1,16 @@ +package co.elastic.apm.plugin.spi; + +import java.util.List; + +public interface WebConfiguration { + + boolean isUsePathAsName(); + + List getIgnoreUrls(); + + List getUrlGroups(); + + List getCaptureContentTypes(); + + List getIgnoreUserAgents(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/WildcardMatcher.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/WildcardMatcher.java new file mode 100644 index 00000000000..16f424fba6c --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/WildcardMatcher.java @@ -0,0 +1,30 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. 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 co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface WildcardMatcher { + + boolean matches(CharSequence s); + + boolean matches(CharSequence firstPart, @Nullable CharSequence secondPart); + + String getMatcher(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/WildcardMatcherUtil.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/WildcardMatcherUtil.java new file mode 100644 index 00000000000..7ea3b6eb094 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/WildcardMatcherUtil.java @@ -0,0 +1,251 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. 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 co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +@SuppressWarnings("ForLoopReplaceableByForEach") +public abstract class WildcardMatcherUtil { + + private static final String CASE_INSENSITIVE_PREFIX = "(?i)"; + private static final String CASE_SENSITIVE_PREFIX = "(?-i)"; + private static final String WILDCARD = "*"; + + public static WildcardMatcher valueOf(final String wildcardString) { + String matcher = wildcardString; + boolean ignoreCase = true; + if (matcher.startsWith(CASE_SENSITIVE_PREFIX)) { + ignoreCase = false; + matcher = matcher.substring(CASE_SENSITIVE_PREFIX.length()); + } else if (matcher.startsWith(CASE_INSENSITIVE_PREFIX)) { + matcher = matcher.substring(CASE_INSENSITIVE_PREFIX.length()); + } + + String[] split = StringUtils.split(matcher, '*'); + if (split.length == 1) { + return new SimpleWildcardMatcher(split[0], matcher.startsWith(WILDCARD), matcher.endsWith(WILDCARD), ignoreCase); + } + + List matchers = new ArrayList<>(split.length); + for (int i = 0; i < split.length; i++) { + boolean isFirst = i == 0; + boolean isLast = i == split.length - 1; + matchers.add(new SimpleWildcardMatcher(split[i], + !isFirst || matcher.startsWith(WILDCARD), + !isLast || matcher.endsWith(WILDCARD), + ignoreCase)); + } + return new CompoundWildcardMatcher(wildcardString, matcher, matchers); + } + + public static boolean isAnyMatch(List matchers, @Nullable CharSequence s) { + return anyMatch(matchers, s) != null; + } + + public static boolean isNoneMatch(List matchers, @Nullable CharSequence s) { + return !isAnyMatch(matchers, s); + } + + @Nullable + public static WildcardMatcher anyMatch(List matchers, @Nullable CharSequence s) { + if (s == null || matchers.isEmpty()) { + return null; + } + return anyMatch(matchers, s, null); + } + + @Nullable + public static WildcardMatcher anyMatch(List matchers, CharSequence firstPart, @Nullable CharSequence secondPart) { + for (int i = 0; i < matchers.size(); i++) { + if (matchers.get(i).matches(firstPart, secondPart)) { + return matchers.get(i); + } + } + return null; + } + + public static int indexOfIgnoreCase(final CharSequence haystack1, final CharSequence haystack2, final String needle, final boolean ignoreCase, final int start, final int end) { + if (start < 0) { + return -1; + } + int totalHaystackLength = haystack1.length() + haystack2.length(); + if (needle.isEmpty() || totalHaystackLength == 0) { + // Fallback to legacy behavior. + return indexOf(haystack1, needle); + } + + final int haystack1Length = haystack1.length(); + final int needleLength = needle.length(); + for (int i = start; i < end; i++) { + // Early out, if possible. + if (i + needleLength > totalHaystackLength) { + return -1; + } + + // Attempt to match substring starting at position i of haystack. + int j = 0; + int ii = i; + while (ii < totalHaystackLength && j < needleLength) { + char c = ignoreCase ? Character.toLowerCase(charAt(ii, haystack1, haystack2, haystack1Length)) : charAt(ii, haystack1, haystack2, haystack1Length); + char c2 = ignoreCase ? Character.toLowerCase(needle.charAt(j)) : needle.charAt(j); + if (c != c2) { + break; + } + j++; + ii++; + } + // Walked all the way to the end of the needle, return the start + // position that this was found. + if (j == needleLength) { + return i; + } + } + return -1; + } + + private static int indexOf(CharSequence input, String s) { + if (input instanceof StringBuilder) { + return ((StringBuilder) input).indexOf(s); + } + return input.toString().indexOf(s); + } + + static char charAt(int i, CharSequence firstPart, CharSequence secondPart, int firstPartLength) { + return i < firstPartLength ? firstPart.charAt(i) : secondPart.charAt(i - firstPartLength); + } + + static class CompoundWildcardMatcher implements WildcardMatcher { + private final String wildcardString; + private final String matcher; + private final List wildcardMatchers; + + CompoundWildcardMatcher(String wildcardString, String matcher, List wildcardMatchers) { + this.wildcardString = wildcardString; + this.matcher = matcher; + this.wildcardMatchers = wildcardMatchers; + } + + @Override + public boolean matches(CharSequence s) { + int offset = 0; + for (int i = 0; i < wildcardMatchers.size(); i++) { + final SimpleWildcardMatcher matcher = wildcardMatchers.get(i); + offset = matcher.indexOf(s, offset); + if (offset == -1) { + return false; + } + offset += matcher.matcher.length(); + } + return true; + } + + @Override + public boolean matches(CharSequence firstPart, @Nullable CharSequence secondPart) { + int offset = 0; + for (int i = 0; i < wildcardMatchers.size(); i++) { + final SimpleWildcardMatcher matcher = wildcardMatchers.get(i); + offset = matcher.indexOf(firstPart, secondPart, offset); + if (offset == -1) { + return false; + } + offset += matcher.matcher.length(); + } + return true; + } + + @Override + public String toString() { + return wildcardString; + } + + @Override + public String getMatcher() { + return matcher; + } + } + + /** + * This {@link} does not support wildcards in the middle of a matcher. + */ + static class SimpleWildcardMatcher implements WildcardMatcher { + + private final String matcher; + private final String stringRepresentation; + private final boolean wildcardAtEnd; + private final boolean wildcardAtBeginning; + private final boolean ignoreCase; + + SimpleWildcardMatcher(String matcher, boolean wildcardAtBeginning, boolean wildcardAtEnd, boolean ignoreCase) { + this.matcher = matcher; + this.wildcardAtEnd = wildcardAtEnd; + this.wildcardAtBeginning = wildcardAtBeginning; + this.ignoreCase = ignoreCase; + this.stringRepresentation = new StringBuilder(matcher.length() + CASE_SENSITIVE_PREFIX.length() + WILDCARD.length() + WILDCARD.length()) + .append(ignoreCase ? "" : CASE_SENSITIVE_PREFIX) + .append(wildcardAtBeginning ? WILDCARD : "") + .append(matcher) + .append(wildcardAtEnd ? WILDCARD : "") + .toString(); + } + + @Override + public String toString() { + return stringRepresentation; + } + + @Override + public boolean matches(CharSequence s) { + return indexOf(s, 0) != -1; + } + + @Override + public boolean matches(CharSequence firstPart, @Nullable CharSequence secondPart) { + return indexOf(firstPart, secondPart, 0) != -1; + } + + int indexOf(final CharSequence s, final int offset) { + return indexOf(s, "", offset); + } + + int indexOf(CharSequence firstPart, @Nullable CharSequence secondPart, int offset) { + if (secondPart == null) { + secondPart = ""; + } + int totalLength = firstPart.length() + secondPart.length(); + if (wildcardAtEnd && wildcardAtBeginning) { + return indexOfIgnoreCase(firstPart, secondPart, matcher, ignoreCase, offset, totalLength); + } else if (wildcardAtEnd) { + return indexOfIgnoreCase(firstPart, secondPart, matcher, ignoreCase, 0, 1); + } else if (wildcardAtBeginning) { + return indexOfIgnoreCase(firstPart, secondPart, matcher, ignoreCase, totalLength - matcher.length(), totalLength); + } else if (totalLength == matcher.length()) { + return indexOfIgnoreCase(firstPart, secondPart, matcher, ignoreCase, 0, totalLength); + } else { + return -1; + } + } + + @Override + public String getMatcher() { + return matcher; + } + } +} diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureSpanInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureSpanInstrumentation.java index faa7ada6120..fc217622b26 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureSpanInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureSpanInstrumentation.java @@ -21,10 +21,10 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.bci.bytebuddy.AnnotationValueOffsetMappingFactory; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; -import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.CoreConfiguration; import co.elastic.apm.plugin.spi.DefaultOutcome; import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureTransactionInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureTransactionInstrumentation.java index cd84b9d23cb..bb993f4d622 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureTransactionInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureTransactionInstrumentation.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.bci.bytebuddy.AnnotationValueOffsetMappingFactory.AnnotationValueExtractor; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory.SimpleMethodSignature; -import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; +import co.elastic.apm.plugin.spi.CoreConfiguration; import co.elastic.apm.plugin.spi.DefaultOutcome; import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.PrivilegedActionUtils; diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TracedInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TracedInstrumentation.java index 5152ed05b08..a82517c88a4 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TracedInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TracedInstrumentation.java @@ -21,7 +21,6 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.bci.bytebuddy.AnnotationValueOffsetMappingFactory; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; -import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; import co.elastic.apm.agent.util.PrivilegedActionUtils; diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/SQSHelper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/SQSHelper.java index b11ac54bbcc..32362df4c7c 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/SQSHelper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/SQSHelper.java @@ -20,13 +20,7 @@ import co.elastic.apm.agent.awssdk.common.AbstractSQSInstrumentationHelper; import co.elastic.apm.agent.awssdk.v1.helper.sqs.wrapper.ReceiveMessageResultWrapper; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.plugin.spi.GlobalTracer; -import co.elastic.apm.plugin.spi.Tracer; -import co.elastic.apm.plugin.spi.Span; -import co.elastic.apm.plugin.spi.TextHeaderSetter; -import co.elastic.apm.plugin.spi.TraceContext; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.*; import com.amazonaws.AmazonWebServiceRequest; import com.amazonaws.Request; import com.amazonaws.http.ExecutionContext; @@ -144,13 +138,13 @@ protected void setMessageContext(@Nullable Message sqsMessage, @Nullable String if (!TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME.equals(key) && !TraceContext.TRACESTATE_HEADER_NAME.equals(key) && entry.getValue().getDataType().equals(ATTRIBUTE_DATA_TYPE_STRING) && - WildcardMatcher.anyMatch(coreConfiguration.getSanitizeFieldNames(), key) == null) { + WildcardMatcherUtil.anyMatch(coreConfiguration.getSanitizeFieldNames(), key) == null) { message.addHeader(key, entry.getValue().getStringValue()); } } } - if (coreConfiguration.getCaptureBody() != CoreConfiguration.EventType.OFF) { + if (coreConfiguration.isCaptureBody()) { message.appendToBody(sqsMessage.getBody()); } } diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/sqs/wrapper/MessageListWrapper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/sqs/wrapper/MessageListWrapper.java index cdc27247cc2..fe54ba9fa22 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/sqs/wrapper/MessageListWrapper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/sqs/wrapper/MessageListWrapper.java @@ -22,12 +22,12 @@ import co.elastic.apm.agent.awssdk.common.IAwsSdkDataSource; import co.elastic.apm.agent.awssdk.v2.helper.SQSHelper; import co.elastic.apm.agent.awssdk.v2.helper.SdkV2DataSource; -import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.MessagingConfiguration; import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.sdk.state.CallDepth; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; +import co.elastic.apm.plugin.spi.WildcardMatcherUtil; import software.amazon.awssdk.core.SdkRequest; import software.amazon.awssdk.core.SdkResponse; import software.amazon.awssdk.services.sqs.model.Message; @@ -50,7 +50,7 @@ public static void registerWrapperListForResponse(@Nullable SdkRequest sdkReques // Wrap result only if the messages are NOT received as part of JMS. if (!jmsReceiveMessageCallDepth.isNestedCallAndIncrement()) { if (tracer.isRunning() && queueName != null - && !WildcardMatcher.isAnyMatch(tracer.getConfig(MessagingConfiguration.class).getIgnoreMessageQueues(), queueName)) { + && !WildcardMatcherUtil.isAnyMatch(tracer.getConfig(MessagingConfiguration.class).getIgnoreMessageQueues(), queueName)) { sqsResponseToWrappedMessageListMap.put(receiveMessageResponse, new MessageListWrapper(receiveMessageResponse.messages(), tracer, queueName)); } } diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractSQSInstrumentationHelper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractSQSInstrumentationHelper.java index 7cfea9a01ca..d383933947b 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractSQSInstrumentationHelper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractSQSInstrumentationHelper.java @@ -18,9 +18,6 @@ */ package co.elastic.apm.agent.awssdk.common; -import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.MessagingConfiguration; import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.plugin.spi.Message; import co.elastic.apm.plugin.spi.*; @@ -81,7 +78,7 @@ protected AbstractSQSInstrumentationHelper(Tracer tracer, IAwsSdkDataSource createSpan(@Nullable String queueName) { - if (WildcardMatcher.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), queueName)) { + if (WildcardMatcherUtil.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), queueName)) { return null; } Span span = tracer.createExitChildSpan(); @@ -152,7 +149,7 @@ public Span startSpan(R request, URI httpURI, C context) { public void startTransactionOnMessage(MessageT sqsMessage, String queueName, TextHeaderGetter headerGetter) { try { - if (!WildcardMatcher.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), queueName)) { + if (!WildcardMatcherUtil.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), queueName)) { Transaction transaction = tracer.startChildTransaction(sqsMessage, headerGetter, PrivilegedActionUtils.getClassLoader(AbstractSQSInstrumentationHelper.class)); if (transaction != null) { transaction.withType(MESSAGING_TYPE).withName("SQS RECEIVE from " + queueName).activate(); @@ -193,13 +190,13 @@ protected void setMessageContext(@Nullable MessageT sqsMessage, @Nullable String if (!TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME.equals(key) && !TraceContext.TRACESTATE_HEADER_NAME.equals(key) && value != null && - WildcardMatcher.anyMatch(coreConfiguration.getSanitizeFieldNames(), key) == null) { + WildcardMatcherUtil.anyMatch(coreConfiguration.getSanitizeFieldNames(), key) == null) { message.addHeader(key, value); } } } - if (coreConfiguration.getCaptureBody() != CoreConfiguration.EventType.OFF) { + if (coreConfiguration.isCaptureBody()) { message.appendToBody(getMessageBody(sqsMessage)); } } diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelper.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelper.java index 2a5fc8f37d2..fd9dec0f9c4 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelper.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelper.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.esrestclient; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.WildcardMatcher; import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -43,11 +43,11 @@ public class ElasticsearchRestClientInstrumentationHelper { private static final ElasticsearchRestClientInstrumentationHelper INSTANCE = new ElasticsearchRestClientInstrumentationHelper(GlobalTracer.get()); public static final List QUERY_WILDCARD_MATCHERS = Arrays.asList( - WildcardMatcher.valueOf("*_search"), - WildcardMatcher.valueOf("*_msearch"), - WildcardMatcher.valueOf("*_msearch/template"), - WildcardMatcher.valueOf("*_search/template"), - WildcardMatcher.valueOf("*_count")); + WildcardMatcherUtil.valueOf("*_search"), + WildcardMatcherUtil.valueOf("*_msearch"), + WildcardMatcherUtil.valueOf("*_msearch/template"), + WildcardMatcherUtil.valueOf("*_search/template"), + WildcardMatcherUtil.valueOf("*_count")); public static final String SPAN_TYPE = "db"; public static final String ELASTICSEARCH = "elasticsearch"; public static final String SPAN_ACTION = "request"; @@ -96,7 +96,7 @@ public Span createClientSpan(String method, String endpoint, @Nullable HttpEn if (span.isSampled()) { span.getContext().getHttp().withMethod(method); - if (WildcardMatcher.isAnyMatch(QUERY_WILDCARD_MATCHERS, endpoint)) { + if (WildcardMatcherUtil.isAnyMatch(QUERY_WILDCARD_MATCHERS, endpoint)) { if (httpEntity != null && httpEntity.isRepeatable()) { try { IOUtils.readUtf8Stream(httpEntity.getContent(), span.getContext().getDb().withStatementBuffer()); diff --git a/apm-agent-plugins/apm-httpserver-core/src/main/java/co/elastic/apm/agent/httpserver/HttpServerHelper.java b/apm-agent-plugins/apm-httpserver-core/src/main/java/co/elastic/apm/agent/httpserver/HttpServerHelper.java index ff94f262a7c..ca3be2a9639 100644 --- a/apm-agent-plugins/apm-httpserver-core/src/main/java/co/elastic/apm/agent/httpserver/HttpServerHelper.java +++ b/apm-agent-plugins/apm-httpserver-core/src/main/java/co/elastic/apm/agent/httpserver/HttpServerHelper.java @@ -18,10 +18,11 @@ */ package co.elastic.apm.agent.httpserver; -import co.elastic.apm.agent.impl.context.web.WebConfiguration; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.WildcardMatcher; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.plugin.spi.WebConfiguration; +import co.elastic.apm.plugin.spi.WildcardMatcherUtil; import javax.annotation.Nullable; @@ -36,12 +37,12 @@ public HttpServerHelper(WebConfiguration configuration){ } public boolean isRequestExcluded(String path, @Nullable String userAgentHeader){ - final WildcardMatcher excludeUrlMatcher = WildcardMatcher.anyMatch(configuration.getIgnoreUrls(), path); + final WildcardMatcher excludeUrlMatcher = WildcardMatcherUtil.anyMatch(configuration.getIgnoreUrls(), path); if (excludeUrlMatcher != null && logger.isDebugEnabled()) { logger.debug("Not tracing this request as the path {} is ignored by the matcher {}", path, excludeUrlMatcher); } - final WildcardMatcher excludeAgentMatcher = userAgentHeader != null ? WildcardMatcher.anyMatch(configuration.getIgnoreUserAgents(), userAgentHeader) : null; + final WildcardMatcher excludeAgentMatcher = userAgentHeader != null ? WildcardMatcherUtil.anyMatch(configuration.getIgnoreUserAgents(), userAgentHeader) : null; if (excludeAgentMatcher != null) { logger.debug("Not tracing this request as the User-Agent {} is ignored by the matcher {}", userAgentHeader, excludeAgentMatcher); diff --git a/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/BaseServerEndpointInstrumentation.java b/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/BaseServerEndpointInstrumentation.java index 6aabc300d5b..e57f4d2f50b 100644 --- a/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/BaseServerEndpointInstrumentation.java +++ b/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/BaseServerEndpointInstrumentation.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.plugin.spi.DefaultOutcome; +import co.elastic.apm.plugin.spi.StacktraceConfiguration; import co.elastic.apm.plugin.spi.Tracer; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; import co.elastic.apm.plugin.spi.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; diff --git a/apm-agent-plugins/apm-javalin-plugin/src/main/java/co/elastic/apm/agent/javalin/JavalinInstrumentation.java b/apm-agent-plugins/apm-javalin-plugin/src/main/java/co/elastic/apm/agent/javalin/JavalinInstrumentation.java index 6b274018f9f..b6f007b8010 100644 --- a/apm-agent-plugins/apm-javalin-plugin/src/main/java/co/elastic/apm/agent/javalin/JavalinInstrumentation.java +++ b/apm-agent-plugins/apm-javalin-plugin/src/main/java/co/elastic/apm/agent/javalin/JavalinInstrumentation.java @@ -19,11 +19,7 @@ package co.elastic.apm.agent.javalin; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.plugin.spi.GlobalTracer; -import co.elastic.apm.agent.impl.context.web.WebConfiguration; -import co.elastic.apm.plugin.spi.AbstractSpan; -import co.elastic.apm.plugin.spi.Span; -import co.elastic.apm.plugin.spi.Transaction; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.util.TransactionNameUtils; import co.elastic.apm.agent.util.VersionUtils; import io.javalin.http.Context; diff --git a/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentation.java b/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentation.java index 254a27d0f17..dc56876d7dc 100644 --- a/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentation.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.StacktraceConfiguration; import co.elastic.apm.plugin.spi.Tracer; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; import co.elastic.apm.plugin.spi.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; diff --git a/apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/JaxWsTransactionNameInstrumentation.java b/apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/JaxWsTransactionNameInstrumentation.java index eed00caf083..113f81c2716 100644 --- a/apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/JaxWsTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/JaxWsTransactionNameInstrumentation.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory.SimpleMethodSignature; +import co.elastic.apm.plugin.spi.StacktraceConfiguration; import co.elastic.apm.plugin.spi.Tracer; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; import co.elastic.apm.plugin.spi.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; diff --git a/apm-agent-plugins/apm-jdk-httpserver-plugin/src/main/java/co/elastic/apm/agent/httpserver/HttpHandlerAdvice.java b/apm-agent-plugins/apm-jdk-httpserver-plugin/src/main/java/co/elastic/apm/agent/httpserver/HttpHandlerAdvice.java index 16fdd04eba1..a942a6f1744 100644 --- a/apm-agent-plugins/apm-jdk-httpserver-plugin/src/main/java/co/elastic/apm/agent/httpserver/HttpHandlerAdvice.java +++ b/apm-agent-plugins/apm-jdk-httpserver-plugin/src/main/java/co/elastic/apm/agent/httpserver/HttpHandlerAdvice.java @@ -18,9 +18,7 @@ */ package co.elastic.apm.agent.httpserver; -import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.plugin.spi.*; -import co.elastic.apm.agent.impl.context.web.WebConfiguration; import co.elastic.apm.agent.util.TransactionNameUtils; import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/BaseJmsInstrumentation.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/BaseJmsInstrumentation.java index 63d10be7d35..6e95cec217a 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/BaseJmsInstrumentation.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/BaseJmsInstrumentation.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.jms; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.MessagingConfiguration; +import co.elastic.apm.plugin.spi.CoreConfiguration; import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.MessagingConfiguration; import co.elastic.apm.plugin.spi.Tracer; import net.bytebuddy.matcher.ElementMatcher; diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java index ca25a4cae05..c3c894f3c4b 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java @@ -18,10 +18,8 @@ */ package co.elastic.apm.agent.jms; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.MessagingConfiguration; import co.elastic.apm.plugin.spi.*; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.WildcardMatcher; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.util.PrivilegedActionUtils; @@ -201,7 +199,7 @@ private boolean isTempDestination(Destination destination, @Nullable String extr } public boolean ignoreDestination(@Nullable String destinationName) { - return WildcardMatcher.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), destinationName); + return WildcardMatcherUtil.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), destinationName); } public void addDestinationDetails(Destination destination, @@ -244,7 +242,7 @@ public void addMessageDetails(@Nullable Message message, AbstractSpan span) { // Currently only capturing body of TextMessages. The javax.jms.Message#getBody() API is since 2.0, so, // if we are supporting JMS 1.1, it makes no sense to rely on isAssignableFrom. - if (coreConfiguration.getCaptureBody() != CoreConfiguration.EventType.OFF && message instanceof TextMessage) { + if (coreConfiguration.isCaptureBody() && message instanceof TextMessage) { messageContext.withBody(((TextMessage) message).getText()); } @@ -259,7 +257,7 @@ public void addMessageDetails(@Nullable Message message, AbstractSpan span) { while (properties.hasMoreElements()) { String propertyName = String.valueOf(properties.nextElement()); if (!propertyName.equals(JMS_DESTINATION_NAME_PROPERTY) && !propertyName.equals(JMS_TRACE_PARENT_PROPERTY) - && WildcardMatcher.anyMatch(coreConfiguration.getSanitizeFieldNames(), propertyName) == null) { + && WildcardMatcherUtil.anyMatch(coreConfiguration.getSanitizeFieldNames(), propertyName) == null) { messageContext.addHeader(propertyName, String.valueOf(message.getObjectProperty(propertyName))); } } diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageConsumerInstrumentation.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageConsumerInstrumentation.java index 3106c0bc6c1..7f998df01fd 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageConsumerInstrumentation.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageConsumerInstrumentation.java @@ -121,7 +121,7 @@ public static Object beforeReceive(@Advice.Origin Class clazz, } } - createPollingTransaction &= messagingConfiguration.getMessagePollingTransactionStrategy() != MessagingConfiguration.JmsStrategy.HANDLING; + createPollingTransaction &= !messagingConfiguration.isMessageTransactionHandling(); createPollingTransaction |= "receiveNoWait".equals(methodName); if (createPollingSpan) { @@ -207,7 +207,7 @@ public static void afterReceive(@Advice.Origin Class clazz, if (!discard && tracer.currentTransaction() == null && message != null - && messagingConfiguration.getMessagePollingTransactionStrategy() != MessagingConfiguration.JmsStrategy.POLLING + && !messagingConfiguration.isMessageTransactionPolling() && !"receiveNoWait".equals(methodName)) { Transaction messageHandlingTransaction = helper.startJmsTransaction(message, clazz); diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageListenerInstrumentation.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageListenerInstrumentation.java index ad78a9722df..09454262fa6 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageListenerInstrumentation.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageListenerInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.jms; -import co.elastic.apm.agent.configuration.MessagingConfiguration; +import co.elastic.apm.plugin.spi.MessagingConfiguration; import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaConsumerInstrumentation.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaConsumerInstrumentation.java index 5461451e6c8..aa49f4288f2 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaConsumerInstrumentation.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaConsumerInstrumentation.java @@ -18,11 +18,7 @@ */ package co.elastic.apm.agent.kafka; -import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.plugin.spi.GlobalTracer; -import co.elastic.apm.plugin.spi.AbstractSpan; -import co.elastic.apm.plugin.spi.Span; -import co.elastic.apm.plugin.spi.Transaction; +import co.elastic.apm.plugin.spi.*; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHelper.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHelper.java index 54cbd466ba2..7cb1bcca393 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHelper.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHelper.java @@ -18,9 +18,8 @@ */ package co.elastic.apm.agent.kafka.helper; -import co.elastic.apm.agent.configuration.MessagingConfiguration; import co.elastic.apm.plugin.spi.*; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.WildcardMatcher; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import org.apache.kafka.clients.producer.Callback; @@ -61,7 +60,7 @@ public CallbackWrapper createInstance() { } private boolean ignoreTopic(String topicName) { - return WildcardMatcher.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), topicName); + return WildcardMatcherUtil.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), topicName); } @Nullable diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsIteratorWrapper.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsIteratorWrapper.java index 9de2953c41d..fcf53aee3ab 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsIteratorWrapper.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsIteratorWrapper.java @@ -18,13 +18,7 @@ */ package co.elastic.apm.agent.kafka.helper; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.plugin.spi.Tracer; -import co.elastic.apm.plugin.spi.Message; -import co.elastic.apm.plugin.spi.TraceContext; -import co.elastic.apm.plugin.spi.Transaction; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.util.PrivilegedActionUtils; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.common.header.Header; @@ -74,7 +68,7 @@ public void endCurrentTransaction() { ConsumerRecord record = delegate.next(); try { String topic = record.topic(); - if (!WildcardMatcher.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), topic)) { + if (!WildcardMatcherUtil.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), topic)) { Transaction transaction = tracer.startChildTransaction(record, KafkaRecordHeaderAccessor.instance(), PrivilegedActionUtils.getClassLoader(ConsumerRecordsIteratorWrapper.class)); if (transaction != null) { transaction.withType("messaging").withName("Kafka record from " + topic).activate(); @@ -90,13 +84,13 @@ public void endCurrentTransaction() { for (Header header : record.headers()) { String key = header.key(); if (!TraceContext.TRACE_PARENT_BINARY_HEADER_NAME.equals(key) && - WildcardMatcher.anyMatch(coreConfiguration.getSanitizeFieldNames(), key) == null) { + WildcardMatcherUtil.anyMatch(coreConfiguration.getSanitizeFieldNames(), key) == null) { message.addHeader(key, header.value()); } } } - if (transaction.isSampled() && coreConfiguration.getCaptureBody() != CoreConfiguration.EventType.OFF) { + if (transaction.isSampled() && coreConfiguration.isCaptureBody()) { message.appendToBody("key=").appendToBody(String.valueOf(record.key())).appendToBody("; ") .appendToBody("value=").appendToBody(String.valueOf(record.value())); } diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/src/main/java/co/elastic/apm/agent/logback/reformatting/LogbackEcsReformattingHelper.java b/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/src/main/java/co/elastic/apm/agent/logback/reformatting/LogbackEcsReformattingHelper.java index 093e7ac480d..3712105a3fd 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/src/main/java/co/elastic/apm/agent/logback/reformatting/LogbackEcsReformattingHelper.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/src/main/java/co/elastic/apm/agent/logback/reformatting/LogbackEcsReformattingHelper.java @@ -31,10 +31,11 @@ import co.elastic.apm.agent.logback.sending.LogbackLogSenderAppender; import co.elastic.apm.agent.loginstr.reformatting.AbstractEcsReformattingHelper; import co.elastic.apm.agent.loginstr.reformatting.Utils; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.WildcardMatcher; import co.elastic.apm.agent.report.Reporter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.plugin.spi.WildcardMatcherUtil; import co.elastic.logging.AdditionalField; import co.elastic.logging.logback.EcsEncoder; @@ -66,9 +67,9 @@ protected void setFormatter(OutputStreamAppender appender, Encode } @Override - protected boolean isAllowedFormatter(Encoder formatter, List allowList) { + protected boolean isAllowedFormatter(Encoder formatter, List allowList) { if (formatter instanceof LayoutWrappingEncoder) { - return WildcardMatcher.anyMatch(allowList, ((LayoutWrappingEncoder) formatter).getLayout().getClass().getName()) != null; + return WildcardMatcherUtil.anyMatch(allowList, ((LayoutWrappingEncoder) formatter).getLayout().getClass().getName()) != null; } return super.isAllowedFormatter(formatter, allowList); } diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/reformatting/AbstractEcsReformattingHelper.java b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/reformatting/AbstractEcsReformattingHelper.java index 9725559c9ce..add0c4157f5 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/reformatting/AbstractEcsReformattingHelper.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/reformatting/AbstractEcsReformattingHelper.java @@ -27,7 +27,7 @@ import co.elastic.apm.agent.impl.metadata.ServiceFactory; import co.elastic.apm.agent.logging.LogEcsReformatting; import co.elastic.apm.agent.logging.LoggingConfiguration; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.WildcardMatcher; import co.elastic.apm.agent.report.Reporter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -35,6 +35,7 @@ import co.elastic.apm.agent.sdk.state.GlobalState; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; +import co.elastic.apm.plugin.spi.WildcardMatcherUtil; import javax.annotation.Nullable; import java.util.List; @@ -382,8 +383,8 @@ private boolean shouldApplyEcsReformatting(A originalAppender) { isAllowedFormatter(formatter, loggingConfiguration.getLogEcsFormatterAllowList()); } - protected boolean isAllowedFormatter(F formatter, List allowList) { - return WildcardMatcher.anyMatch(allowList, formatter.getClass().getName()) != null; + protected boolean isAllowedFormatter(F formatter, List allowList) { + return WildcardMatcherUtil.anyMatch(allowList, formatter.getClass().getName()) != null; } /** diff --git a/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMetricsReporter.java b/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMetricsReporter.java index f5063829dc4..0ce8e68a860 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMetricsReporter.java +++ b/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMetricsReporter.java @@ -227,13 +227,13 @@ private static class MeterMapConsumer implements Consumer { //Reuse an instance to reduce garbage churn static final MeterMapConsumer INSTANCE = new MeterMapConsumer(null); - private List disabledMetrics; + private List disabledMetrics; - public MeterMapConsumer(List disabledMetrics) { + public MeterMapConsumer(List disabledMetrics) { this.disabledMetrics = disabledMetrics; } - public MeterMapConsumer reset(List disabledMetrics2){ + public MeterMapConsumer reset(List disabledMetrics2){ disabledMetrics = disabledMetrics2; meters.clear(); return this; diff --git a/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/main/java/co/elastic/apm/agent/mongodb/MongoConfiguration.java b/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/main/java/co/elastic/apm/agent/mongodb/MongoConfiguration.java index dbeaa74fd37..c8bef5be528 100644 --- a/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/main/java/co/elastic/apm/agent/mongodb/MongoConfiguration.java +++ b/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/main/java/co/elastic/apm/agent/mongodb/MongoConfiguration.java @@ -18,12 +18,13 @@ */ package co.elastic.apm.agent.mongodb; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.agent.configuration.converter.WildcardMatcher; import co.elastic.apm.agent.matcher.WildcardMatcherValueConverter; import org.stagemonitor.configuration.ConfigurationOption; import org.stagemonitor.configuration.ConfigurationOptionProvider; import org.stagemonitor.configuration.converter.ListValueConverter; +import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; diff --git a/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/main/java/co/elastic/apm/agent/mongodb/MongoHelper.java b/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/main/java/co/elastic/apm/agent/mongodb/MongoHelper.java index 5288df61d83..650cd2637ae 100644 --- a/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/main/java/co/elastic/apm/agent/mongodb/MongoHelper.java +++ b/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/main/java/co/elastic/apm/agent/mongodb/MongoHelper.java @@ -18,11 +18,7 @@ */ package co.elastic.apm.agent.mongodb; -import co.elastic.apm.plugin.spi.GlobalTracer; -import co.elastic.apm.plugin.spi.Tracer; -import co.elastic.apm.plugin.spi.AbstractSpan; -import co.elastic.apm.plugin.spi.Span; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import org.bson.BsonDocument; @@ -62,7 +58,7 @@ public Span startSpan(@Nullable String database, @Nullable String collection, .withName(database); String statement = null; - if (command != null && commandDocument != null && WildcardMatcher.anyMatch(config.getCaptureStatementCommands(), command) != null) { + if (command != null && commandDocument != null && WildcardMatcherUtil.anyMatch(config.getCaptureStatementCommands(), command) != null) { statement = commandDocument.toJson(); } diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingConfiguration.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingConfiguration.java index d6101c0d045..284658eda85 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingConfiguration.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingConfiguration.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.configuration.converter.ListValueConverter; import co.elastic.apm.agent.configuration.converter.TimeDuration; import co.elastic.apm.agent.configuration.converter.TimeDurationValueConverter; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.agent.configuration.converter.WildcardMatcher; import co.elastic.apm.agent.matcher.WildcardMatcherValueConverter; import org.stagemonitor.configuration.ConfigurationOption; import org.stagemonitor.configuration.ConfigurationOptionProvider; diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java index b2e76786f72..aa0dff9a1ab 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java @@ -504,8 +504,8 @@ public void processTraces() throws IOException { return; } long start = System.nanoTime(); - List excludedClasses = config.getExcludedClasses(); - List includedClasses = config.getIncludedClasses(); + List excludedClasses = config.getExcludedClasses(); + List includedClasses = config.getIncludedClasses(); if (config.isBackupDiagnosticFiles()) { backupDiagnosticFiles(eof); } diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/JfrParser.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/JfrParser.java index 6239871f6eb..612e8263c56 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/JfrParser.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/JfrParser.java @@ -76,9 +76,9 @@ public class JfrParser implements Recyclable { @Nullable private boolean[] isJavaFrameType; @Nullable - private List excludedClasses; + private List excludedClasses; @Nullable - private List includedClasses; + private List includedClasses; public JfrParser() { this(ByteBuffer.allocateDirect(BIG_FILE_BUFFER_SIZE), ByteBuffer.allocateDirect(SMALL_FILE_BUFFER_SIZE)); @@ -96,7 +96,7 @@ public JfrParser() { * @param includedClasses Class names to include in stack traces (has an effect on {@link #resolveStackTrace(long, boolean, List, int)}) * @throws IOException if some I/O error occurs */ - public void parse(File file, List excludedClasses, List includedClasses) throws IOException { + public void parse(File file, List excludedClasses, List includedClasses) throws IOException { this.excludedClasses = excludedClasses; this.includedClasses = includedClasses; bufferedFile.setFile(file); diff --git a/apm-agent-plugins/apm-quartz-job-plugin/quartz-common/src/main/java/co/elastic/apm/agent/quartzjob/AbstractJobTransactionNameInstrumentation.java b/apm-agent-plugins/apm-quartz-job-plugin/quartz-common/src/main/java/co/elastic/apm/agent/quartzjob/AbstractJobTransactionNameInstrumentation.java index 9287d7572b5..0ddf7a826fe 100644 --- a/apm-agent-plugins/apm-quartz-job-plugin/quartz-common/src/main/java/co/elastic/apm/agent/quartzjob/AbstractJobTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-quartz-job-plugin/quartz-common/src/main/java/co/elastic/apm/agent/quartzjob/AbstractJobTransactionNameInstrumentation.java @@ -20,7 +20,6 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.plugin.spi.Tracer; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.util.PrivilegedActionUtils; import co.elastic.apm.agent.util.VersionUtils; diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/AbstractBaseInstrumentation.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/AbstractBaseInstrumentation.java index d289187975b..20af5b214e5 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/AbstractBaseInstrumentation.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/AbstractBaseInstrumentation.java @@ -19,12 +19,7 @@ package co.elastic.apm.agent.rabbitmq; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.plugin.spi.GlobalTracer; -import co.elastic.apm.plugin.spi.AbstractSpan; -import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.plugin.spi.Message; +import co.elastic.apm.plugin.spi.*; import javax.annotation.Nullable; import java.util.Date; @@ -40,7 +35,7 @@ public abstract class AbstractBaseInstrumentation extends TracerAwareInstrumenta * @return {@literal true} when exchange or queue is ignored, {@literal false otherwise} */ protected static boolean isIgnored(String name) { - return WildcardMatcher.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), name); + return WildcardMatcherUtil.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), name); } protected static boolean isCaptureHeaders() { @@ -48,7 +43,7 @@ protected static boolean isCaptureHeaders() { } protected static boolean captureHeaderKey(String key) { - return !WildcardMatcher.isAnyMatch(coreConfiguration.getSanitizeFieldNames(), key); + return !WildcardMatcherUtil.isAnyMatch(coreConfiguration.getSanitizeFieldNames(), key); } /** diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpBatchMessageListenerInstrumentation.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpBatchMessageListenerInstrumentation.java index bab80acca42..0e769dc3209 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpBatchMessageListenerInstrumentation.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpBatchMessageListenerInstrumentation.java @@ -19,7 +19,6 @@ package co.elastic.apm.agent.rabbitmq; -import co.elastic.apm.agent.configuration.MessagingConfiguration; import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.rabbitmq.header.SpringRabbitMQTextHeaderGetter; import co.elastic.apm.agent.sdk.logging.Logger; @@ -75,7 +74,7 @@ public static Object[] beforeOnBatch(@Advice.This Object thiz, if (tracer.isRunning() && messageBatch != null && !messageBatch.isEmpty()) { AbstractSpan active = tracer.getActive(); - if (active == null && messagingConfiguration.getMessageBatchStrategy() == MessagingConfiguration.BatchStrategy.BATCH_HANDLING) { + if (active == null && messagingConfiguration.isMessageBatchHandling()) { batchTransaction = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(thiz.getClass())); if (batchTransaction == null) { oneTimeTransactionCreationWarningLogger.warn("Failed to start Spring AMQP transaction for batch processing"); diff --git a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/ScheduledTransactionNameInstrumentation.java b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/ScheduledTransactionNameInstrumentation.java index 091661a46bb..0d4ea27086e 100644 --- a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/ScheduledTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/ScheduledTransactionNameInstrumentation.java @@ -21,7 +21,6 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory.SimpleMethodSignature; import co.elastic.apm.plugin.spi.*; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; import co.elastic.apm.agent.util.PrivilegedActionUtils; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; diff --git a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/TimerTaskInstrumentation.java b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/TimerTaskInstrumentation.java index 028b5574430..44f78b654bf 100644 --- a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/TimerTaskInstrumentation.java +++ b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/TimerTaskInstrumentation.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; +import co.elastic.apm.plugin.spi.StacktraceConfiguration; import co.elastic.apm.plugin.spi.Tracer; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; import co.elastic.apm.plugin.spi.AbstractSpan; import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.PrivilegedActionUtils; diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletApiAdvice.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletApiAdvice.java index 38b8c6d384d..5e29c9e0ed0 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletApiAdvice.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletApiAdvice.java @@ -18,7 +18,6 @@ */ package co.elastic.apm.agent.servlet; -import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.sdk.state.GlobalVariables; import co.elastic.apm.agent.sdk.weakconcurrent.DetachedThreadLocal; diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletTransactionHelper.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletTransactionHelper.java index d78e9927525..4c947e61371 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletTransactionHelper.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletTransactionHelper.java @@ -18,11 +18,9 @@ */ package co.elastic.apm.agent.servlet; -import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.httpserver.HttpServerHelper; import co.elastic.apm.plugin.spi.*; -import co.elastic.apm.agent.impl.context.web.WebConfiguration; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.WildcardMatcher; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.servlet.adapter.ServletContextAdapter; @@ -37,7 +35,6 @@ import java.util.Map; import java.util.Set; -import static co.elastic.apm.agent.configuration.CoreConfiguration.EventType.OFF; import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_DEFAULT; import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_LOW_LEVEL_FRAMEWORK; @@ -48,7 +45,7 @@ public class ServletTransactionHelper { public static final String ASYNC_ATTRIBUTE = ServletApiAdvice.class.getName() + ".async"; private static final String CONTENT_TYPE_FROM_URLENCODED = "application/x-www-form-urlencoded"; - private static final WildcardMatcher ENDS_WITH_JSP = WildcardMatcher.valueOf("*.jsp"); + private static final WildcardMatcher ENDS_WITH_JSP = WildcardMatcherUtil.valueOf("*.jsp"); private static final Logger logger = LoggerFactory.getLogger(ServletTransactionHelper.class); @@ -112,16 +109,16 @@ public void fillRequestContext(Transaction transaction, String protocol, Stri private void startCaptureBody(Transaction transaction, String method, @Nullable String contentTypeHeader) { Request request = transaction.getContext().getRequest(); if (hasBody(contentTypeHeader, method)) { - if (coreConfiguration.getCaptureBody() != OFF + if (coreConfiguration.isCaptureBody() && contentTypeHeader != null // form parameters are recorded via ServletRequest.getParameterMap // as the container might not call ServletRequest.getInputStream && !contentTypeHeader.startsWith(CONTENT_TYPE_FROM_URLENCODED) - && WildcardMatcher.isAnyMatch(webConfiguration.getCaptureContentTypes(), contentTypeHeader)) { + && WildcardMatcherUtil.isAnyMatch(webConfiguration.getCaptureContentTypes(), contentTypeHeader)) { request.withBodyBuffer(); } else { request.redactBody(); - if (coreConfiguration.getCaptureBody() == OFF) { + if (coreConfiguration.isCaptureBody()) { logger.debug("Not capturing Request body because the capture_body config option is OFF"); } if (contentTypeHeader == null) { @@ -274,7 +271,7 @@ void applyDefaultTransactionName(String method, String servletPath, @Nullable St private void fillRequestParameters(Transaction transaction, String method, @Nullable Map parameterMap, @Nullable String contentTypeHeader) { Request request = transaction.getContext().getRequest(); if (hasBody(contentTypeHeader, method)) { - if (coreConfiguration.getCaptureBody() != OFF && parameterMap != null) { + if (coreConfiguration.isCaptureBody() && parameterMap != null) { captureParameters(request, parameterMap, contentTypeHeader); } } @@ -284,8 +281,8 @@ public boolean captureParameters(String method, @Nullable String contentTypeHead return contentTypeHeader != null && contentTypeHeader.startsWith(CONTENT_TYPE_FROM_URLENCODED) && hasBody(contentTypeHeader, method) - && coreConfiguration.getCaptureBody() != OFF - && WildcardMatcher.isAnyMatch(webConfiguration.getCaptureContentTypes(), contentTypeHeader); + && coreConfiguration.isCaptureBody() + && WildcardMatcherUtil.isAnyMatch(webConfiguration.getCaptureContentTypes(), contentTypeHeader); } private void fillResponse(Response response, boolean committed, int status) { diff --git a/apm-agent-plugins/apm-sparkjava-plugin/src/main/java/co/elastic/apm/agent/sparkjava/RoutesAdvice.java b/apm-agent-plugins/apm-sparkjava-plugin/src/main/java/co/elastic/apm/agent/sparkjava/RoutesAdvice.java index 7343a1d8d9a..85e54615613 100644 --- a/apm-agent-plugins/apm-sparkjava-plugin/src/main/java/co/elastic/apm/agent/sparkjava/RoutesAdvice.java +++ b/apm-agent-plugins/apm-sparkjava-plugin/src/main/java/co/elastic/apm/agent/sparkjava/RoutesAdvice.java @@ -20,10 +20,10 @@ import co.elastic.apm.plugin.spi.GlobalTracer; import co.elastic.apm.plugin.spi.Tracer; -import co.elastic.apm.agent.impl.context.web.WebConfiguration; import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.TransactionNameUtils; import co.elastic.apm.agent.util.VersionUtils; +import co.elastic.apm.plugin.spi.WebConfiguration; import net.bytebuddy.asm.Advice; import spark.Route; import spark.routematch.RouteMatch; diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java index a0f98874eb8..cd58f63da9a 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java @@ -18,10 +18,8 @@ */ package co.elastic.apm.agent.springwebflux; -import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.httpserver.HttpServerHelper; import co.elastic.apm.plugin.spi.*; -import co.elastic.apm.agent.impl.context.web.WebConfiguration; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; diff --git a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringTransactionNameInstrumentation.java b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringTransactionNameInstrumentation.java index 876a9bced88..1a22f859b6f 100644 --- a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringTransactionNameInstrumentation.java @@ -20,10 +20,10 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.plugin.spi.GlobalTracer; -import co.elastic.apm.agent.impl.context.web.WebConfiguration; import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.TransactionNameUtils; import co.elastic.apm.agent.util.VersionUtils; +import co.elastic.apm.plugin.spi.WebConfiguration; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -102,7 +102,7 @@ public Collection getInstrumentationGroupNames() { public static class HandlerAdapterAdvice { - private static final WebConfiguration webConfig = GlobalTracer.get().getConfig(WebConfiguration.class);; + private static final WebConfiguration webConfig = GlobalTracer.get().getConfig(WebConfiguration.class); @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setTransactionName(@Advice.Argument(0) HttpServletRequest request, diff --git a/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ExecuteOperationsAdvice.java b/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ExecuteOperationsAdvice.java index 29cd3a0823c..bc5387bc2d1 100644 --- a/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ExecuteOperationsAdvice.java +++ b/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ExecuteOperationsAdvice.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.struts; import co.elastic.apm.plugin.spi.GlobalTracer; -import co.elastic.apm.agent.impl.context.web.WebConfiguration; import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.TransactionNameUtils; +import co.elastic.apm.plugin.spi.WebConfiguration; import net.bytebuddy.asm.Advice; import javax.servlet.http.HttpServletRequest; diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractHttpTransactionHelper.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractHttpTransactionHelper.java index 33d97d4d48f..39e3b4c6ca1 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractHttpTransactionHelper.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractHttpTransactionHelper.java @@ -18,14 +18,9 @@ */ package co.elastic.apm.agent.vertx; -import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.httpserver.HttpServerHelper; -import co.elastic.apm.plugin.spi.Request; -import co.elastic.apm.plugin.spi.Response; -import co.elastic.apm.plugin.spi.Tracer; -import co.elastic.apm.agent.impl.context.web.WebConfiguration; -import co.elastic.apm.plugin.spi.Transaction; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.*; +import co.elastic.apm.plugin.spi.WildcardMatcher; import co.elastic.apm.agent.util.TransactionNameUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -36,7 +31,6 @@ import java.util.Map; import java.util.Set; -import static co.elastic.apm.agent.configuration.CoreConfiguration.EventType.OFF; import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_DEFAULT; import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_LOW_LEVEL_FRAMEWORK; @@ -45,7 +39,7 @@ public abstract class AbstractHttpTransactionHelper { private static final String CONTENT_TYPE_FROM_URLENCODED = "application/x-www-form-urlencoded"; private static final Set METHODS_WITH_BODY = new HashSet<>(Arrays.asList("POST", "PUT", "PATCH", "DELETE")); - private static final WildcardMatcher ENDS_WITH_JSP = WildcardMatcher.valueOf("*.jsp"); + private static final WildcardMatcher ENDS_WITH_JSP = WildcardMatcherUtil.valueOf("*.jsp"); protected static final String CONTENT_TYPE_HEADER = "Content-Type"; @@ -67,16 +61,16 @@ protected AbstractHttpTransactionHelper(Tracer tracer) { protected void startCaptureBody(Transaction transaction, String method, @Nullable String contentTypeHeader) { Request request = transaction.getContext().getRequest(); if (hasBody(contentTypeHeader, method)) { - if (coreConfiguration.getCaptureBody() != OFF + if (coreConfiguration.isCaptureBody() && contentTypeHeader != null // form parameters are recorded via ServletRequest.getParameterMap // as the container might not call ServletRequest.getInputStream && !contentTypeHeader.startsWith(CONTENT_TYPE_FROM_URLENCODED) - && WildcardMatcher.isAnyMatch(webConfiguration.getCaptureContentTypes(), contentTypeHeader)) { + && WildcardMatcherUtil.isAnyMatch(webConfiguration.getCaptureContentTypes(), contentTypeHeader)) { request.withBodyBuffer(); } else { request.redactBody(); - if (coreConfiguration.getCaptureBody() == OFF) { + if (!coreConfiguration.isCaptureBody()) { logger.debug("Not capturing Request body because the capture_body config option is OFF"); } if (contentTypeHeader == null) { @@ -118,7 +112,7 @@ public void applyDefaultTransactionName(String method, String pathFirstPart, @Nu protected void fillRequestParameters(Transaction transaction, String method, @Nullable Map parameterMap, @Nullable String contentTypeHeader) { Request request = transaction.getContext().getRequest(); if (hasBody(contentTypeHeader, method)) { - if (coreConfiguration.getCaptureBody() != OFF && parameterMap != null) { + if (coreConfiguration.isCaptureBody() && parameterMap != null) { captureParameters(request, parameterMap, contentTypeHeader); } } @@ -136,8 +130,8 @@ public boolean captureParameters(String method, @Nullable String contentTypeHead return contentTypeHeader != null && contentTypeHeader.startsWith(CONTENT_TYPE_FROM_URLENCODED) && hasBody(contentTypeHeader, method) - && coreConfiguration.getCaptureBody() != OFF - && WildcardMatcher.isAnyMatch(webConfiguration.getCaptureContentTypes(), contentTypeHeader); + && coreConfiguration.isCaptureBody() + && WildcardMatcherUtil.isAnyMatch(webConfiguration.getCaptureContentTypes(), contentTypeHeader); } protected void fillResponse(Response response, @Nullable Boolean committed, int status) {