From 73ee8a8ff3601739bba1489daf154596c11bbb35 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Wed, 22 Feb 2023 13:48:08 +0100 Subject: [PATCH] #3030: Introduce configuration API within SPI package that acts as a binary compatible mirror of the current configuration. --- .../agent/common/util/WildcardMatcher.java | 10 +- .../bci/bytebuddy/CustomElementMatchers.java | 2 +- .../configuration/CoreConfiguration.java | 13 +- .../configuration/MessagingConfiguration.java | 19 +- .../converter/WildcardMatcher.java | 48 ++++ .../elastic/apm/agent/impl/BasicTracer.java | 23 +- .../apm/agent/impl/ElasticApmTracer.java | 23 +- .../apm/agent/impl/context/Request.java | 6 +- .../apm/agent/impl/context/Response.java | 2 +- .../impl/context/web/WebConfiguration.java | 4 +- .../stacktrace/StacktraceConfiguration.java | 2 +- .../agent/logging/LoggingConfiguration.java | 2 +- .../WildcardMatcherValueConverter.java | 2 +- .../agent/report/ReporterConfiguration.java | 6 +- .../TraceMethodInstrumentation.java | 2 +- .../apm/agent/util/TransactionNameUtils.java | 9 +- .../configuration/CoreConfigurationTest.java | 2 +- .../agent/util/TransactionNameUtilsTest.java | 9 +- .../apm/plugin/spi/CoreConfiguration.java | 15 ++ .../java/co/elastic/apm/plugin/spi/Db.java | 4 + .../apm/plugin/spi/DisabledObjectPool.java | 23 ++ .../plugin/spi/DisabledObjectPoolFactory.java | 14 + .../co/elastic/apm/plugin/spi/EmptyCloud.java | 16 ++ .../apm/plugin/spi/EmptyCloudOrigin.java | 31 +++ .../plugin/spi/EmptyCoreConfiguration.java | 37 +++ .../co/elastic/apm/plugin/spi/EmptyDb.java | 49 ++++ .../apm/plugin/spi/EmptyDestination.java | 49 ++++ .../co/elastic/apm/plugin/spi/EmptyFaas.java | 36 +++ .../co/elastic/apm/plugin/spi/EmptyHttp.java | 38 +++ .../elastic/apm/plugin/spi/EmptyMessage.java | 46 ++++ .../spi/EmptyMessagingConfiguration.java | 48 ++++ .../spi/EmptyPotentiallyMultiValuedMap.java | 37 +++ .../elastic/apm/plugin/spi/EmptyRequest.java | 86 ++++++ .../elastic/apm/plugin/spi/EmptyResponse.java | 37 +++ .../elastic/apm/plugin/spi/EmptySocket.java | 16 ++ .../spi/EmptyStacktraceConfiguration.java | 17 ++ .../co/elastic/apm/plugin/spi/EmptyUrl.java | 45 ++++ .../co/elastic/apm/plugin/spi/EmptyUser.java | 22 ++ .../apm/plugin/spi/EmptyWebConfiguration.java | 37 +++ .../java/co/elastic/apm/plugin/spi/Http.java | 1 + .../plugin/spi/MessagingConfiguration.java | 20 ++ .../plugin/spi/PotentiallyMultiValuedMap.java | 16 +- .../co/elastic/apm/plugin/spi/Request.java | 2 + .../plugin/spi/StacktraceConfiguration.java | 8 + .../elastic/apm/plugin/spi/StringUtils.java | 53 ++++ .../java/co/elastic/apm/plugin/spi/User.java | 4 + .../apm/plugin/spi/WebConfiguration.java | 16 ++ .../apm/plugin/spi/WildcardMatcher.java | 30 +++ .../apm/plugin/spi/WildcardMatcherUtil.java | 251 ++++++++++++++++++ .../pluginapi/CaptureSpanInstrumentation.java | 2 +- .../CaptureTransactionInstrumentation.java | 2 +- .../pluginapi/TracedInstrumentation.java | 1 - .../apm/agent/awssdk/v1/helper/SQSHelper.java | 12 +- .../sqs/wrapper/MessageListWrapper.java | 6 +- .../AbstractSQSInstrumentationHelper.java | 11 +- ...searchRestClientInstrumentationHelper.java | 20 +- .../agent/httpserver/HttpServerHelper.java | 9 +- .../BaseServerEndpointInstrumentation.java | 2 +- .../agent/javalin/JavalinInstrumentation.java | 6 +- .../JaxRsTransactionNameInstrumentation.java | 2 +- .../JaxWsTransactionNameInstrumentation.java | 2 +- .../agent/httpserver/HttpHandlerAdvice.java | 2 - .../apm/agent/jms/BaseJmsInstrumentation.java | 4 +- .../agent/jms/JmsInstrumentationHelper.java | 10 +- .../JmsMessageConsumerInstrumentation.java | 4 +- .../JmsMessageListenerInstrumentation.java | 2 +- .../kafka/KafkaConsumerInstrumentation.java | 6 +- .../helper/KafkaInstrumentationHelper.java | 5 +- .../ConsumerRecordsIteratorWrapper.java | 14 +- .../LogbackEcsReformattingHelper.java | 7 +- .../AbstractEcsReformattingHelper.java | 7 +- .../micrometer/MicrometerMetricsReporter.java | 6 +- .../apm/agent/mongodb/MongoConfiguration.java | 3 +- .../apm/agent/mongodb/MongoHelper.java | 8 +- .../profiler/ProfilingConfiguration.java | 2 +- .../apm/agent/profiler/SamplingProfiler.java | 4 +- .../profiler/asyncprofiler/JfrParser.java | 6 +- ...ractJobTransactionNameInstrumentation.java | 1 - .../rabbitmq/AbstractBaseInstrumentation.java | 11 +- ...qpBatchMessageListenerInstrumentation.java | 3 +- ...heduledTransactionNameInstrumentation.java | 1 - .../scheduled/TimerTaskInstrumentation.java | 2 +- .../apm/agent/servlet/ServletApiAdvice.java | 1 - .../servlet/ServletTransactionHelper.java | 19 +- .../apm/agent/sparkjava/RoutesAdvice.java | 2 +- .../agent/springwebflux/WebfluxHelper.java | 2 - .../SpringTransactionNameInstrumentation.java | 4 +- .../agent/struts/ExecuteOperationsAdvice.java | 2 +- .../vertx/AbstractHttpTransactionHelper.java | 24 +- 89 files changed, 1321 insertions(+), 204 deletions(-) create mode 100644 apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/converter/WildcardMatcher.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/CoreConfiguration.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/DisabledObjectPool.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/DisabledObjectPoolFactory.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyCloud.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyCloudOrigin.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyCoreConfiguration.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyDb.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyDestination.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyFaas.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyHttp.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyMessage.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyMessagingConfiguration.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyPotentiallyMultiValuedMap.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyRequest.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyResponse.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptySocket.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyStacktraceConfiguration.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyUrl.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyUser.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyWebConfiguration.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/MessagingConfiguration.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/StacktraceConfiguration.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/StringUtils.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/WebConfiguration.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/WildcardMatcher.java create mode 100644 apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/WildcardMatcherUtil.java 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 540627d8c6..17d124d410 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 5e95dd807d..981784883a 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 3a70bd1d3e..246e88e3a3 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 49c0d7474e..33d8656d62 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 0000000000..db6d3fb965 --- /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/BasicTracer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/BasicTracer.java index 2b539e3221..7fe6ef034f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/BasicTracer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/BasicTracer.java @@ -21,6 +21,13 @@ import co.elastic.apm.agent.configuration.ServiceInfo; import co.elastic.apm.agent.impl.error.ErrorCapture; import co.elastic.apm.agent.impl.sampling.Sampler; +import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.transaction.BinaryHeaderGetter; +import co.elastic.apm.agent.impl.transaction.ElasticContext; +import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.impl.transaction.*; import co.elastic.apm.agent.objectpool.ObjectPool; import co.elastic.apm.agent.objectpool.ObjectPoolFactory; @@ -28,6 +35,7 @@ import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; +import co.elastic.apm.plugin.spi.*; import javax.annotation.Nullable; import java.util.Collections; @@ -440,11 +448,18 @@ public TracerState getState() { } @Override + @SuppressWarnings("unchecked") public T getConfig(Class configProvider) { - try { - return configProvider.getConstructor().newInstance(); - } catch (Exception e) { - throw new IllegalStateException("Failed to create empty configuration for " + configProvider.getName(), e); + if (configProvider == CoreConfiguration.class) { + return (T) EmptyCoreConfiguration.INSTANCE; + } else if (configProvider == StacktraceConfiguration.class) { + return (T) EmptyStacktraceConfiguration.INSTANCE; + } else if (configProvider == MessagingConfiguration.class) { + return (T) EmptyMessagingConfiguration.INSTANCE; + } else if (configProvider == WebConfiguration.class) { + return (T) EmptyWebConfiguration.INSTANCE; + } else { + throw new IllegalArgumentException("Unknown configuration: " + configProvider.getName()); } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java index 2043aabda7..a8b8c2c036 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java @@ -21,10 +21,12 @@ import co.elastic.apm.agent.common.JvmRuntimeInfo; 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.agent.configuration.ServiceInfo; import co.elastic.apm.agent.configuration.SpanConfiguration; import co.elastic.apm.agent.context.ClosableLifecycleListenerAdapter; import co.elastic.apm.agent.context.LifecycleListener; +import co.elastic.apm.agent.impl.context.web.WebConfiguration; import co.elastic.apm.agent.impl.error.ErrorCapture; import co.elastic.apm.agent.impl.metadata.MetaDataFuture; import co.elastic.apm.agent.impl.sampling.ProbabilitySampler; @@ -42,8 +44,6 @@ import co.elastic.apm.agent.report.ReporterConfiguration; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; -import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; -import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import co.elastic.apm.agent.util.DependencyInjectingServiceLoader; import co.elastic.apm.agent.util.ExecutorUtils; import org.stagemonitor.configuration.ConfigurationOption; @@ -207,13 +207,24 @@ public ConfigurationRegistry getConfigurationRegistry() { } @Override - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings("unchecked") public T getConfig(Class configProvider) { - if (ConfigurationOptionProvider.class.isAssignableFrom(configProvider)) { - return (T) configurationRegistry.getConfig((Class) configProvider); + Class actualConfigProvider; + if (configProvider == co.elastic.apm.plugin.spi.CoreConfiguration.class) { + actualConfigProvider = CoreConfiguration.class; + } else if (configProvider == co.elastic.apm.plugin.spi.StacktraceConfiguration.class) { + actualConfigProvider = StacktraceConfiguration.class; + } else if (configProvider == co.elastic.apm.plugin.spi.MessagingConfiguration.class) { + actualConfigProvider = MessagingConfiguration.class; + } else if (configProvider == co.elastic.apm.plugin.spi.WebConfiguration.class) { + actualConfigProvider = WebConfiguration.class; + } else if (ConfigurationOptionProvider.class.isAssignableFrom(configProvider)) { + actualConfigProvider = (Class) configProvider; } else { - throw new IllegalArgumentException("Configuration types must subclass " + ConfigurationOptionProvider.class.getName()); + throw new IllegalArgumentException("Configuration types must subclass " + ConfigurationOptionProvider.class.getName() + + " and this does not apply to " + configProvider.getName() + " which was provided"); } + return (T) configurationRegistry.getConfig(actualConfigProvider); } @Override diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Request.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Request.java index 9628ed9c8b..d9b3a18012 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Request.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Request.java @@ -344,10 +344,10 @@ public void copyFrom(Request other) { public boolean hasContent() { return method != null || - headers.size() > 0 || + !headers.isEmpty() || httpVersion != null || - cookies.size() > 0 || - postParams.size() > 0 || + !cookies.isEmpty() || + !postParams.isEmpty() || socket.hasContent() || url.hasContent(); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Response.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Response.java index 459747845f..2eb7f8ee3a 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Response.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Response.java @@ -124,6 +124,6 @@ public void copyFrom(Response other) { } public boolean hasContent() { - return statusCode > 0 || headers.size() > 0; + return statusCode > 0 || !headers.isEmpty(); } } 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 79993d9c7d..0da44d0e2c 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 ad68f1b93b..adb962edb7 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 f046adc3a4..3282afa96e 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 62ce9af254..854d55a8ab 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 28655ff078..40dcefd45b 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 1cdf6a1321..962eae52f8 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 6005f0507c..888fb6fb20 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 a1ea6cab6c..303c135785 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 8225c78fe0..8f965db434 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 0000000000..4a1f675bd9 --- /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/Db.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Db.java index fc4abe3323..7d4aa26739 100644 --- a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Db.java +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Db.java @@ -15,5 +15,9 @@ public interface Db { Db withAffectedRowsCount(long returnValue); + @Nullable + CharBuffer getStatementBuffer(); + + @Nullable CharBuffer withStatementBuffer(); } 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 0000000000..2d63f251e3 --- /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 0000000000..d0e442a214 --- /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/EmptyCloud.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyCloud.java new file mode 100644 index 0000000000..5851341cff --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyCloud.java @@ -0,0 +1,16 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public class EmptyCloud implements Cloud { + + public static final Cloud INSTANCE = new EmptyCloud(); + + private EmptyCloud() { + } + + @Override + public Cloud withRegion(@Nullable String region) { + return this; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyCloudOrigin.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyCloudOrigin.java new file mode 100644 index 0000000000..f49070fdd4 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyCloudOrigin.java @@ -0,0 +1,31 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public class EmptyCloudOrigin implements CloudOrigin { + + public static final CloudOrigin INSTANCE = new EmptyCloudOrigin(); + + private EmptyCloudOrigin() { + } + + @Override + public CloudOrigin withAccountId(@Nullable String accountId) { + return this; + } + + @Override + public CloudOrigin withProvider(@Nullable String provider) { + return this; + } + + @Override + public CloudOrigin withRegion(@Nullable String region) { + return this; + } + + @Override + public CloudOrigin withServiceName(@Nullable String serviceName) { + return this; + } +} 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 0000000000..6c67d6d424 --- /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/EmptyDb.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyDb.java new file mode 100644 index 0000000000..3c052e932f --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyDb.java @@ -0,0 +1,49 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.nio.CharBuffer; + +public class EmptyDb implements Db { + + public static final Db INSTANCE = new EmptyDb(); + + private EmptyDb() { + } + + @Override + public Db withInstance(@Nullable String instance) { + return this; + } + + @Override + public Db withType(@Nullable String type) { + return this; + } + + @Override + public Db withStatement(@Nullable String statement) { + return this; + } + + @Override + public Db withUser(@Nullable String user) { + return this; + } + + @Override + public Db withAffectedRowsCount(long returnValue) { + return this; + } + + @Nullable + @Override + public CharBuffer getStatementBuffer() { + return null; + } + + @Override + @Nullable + public CharBuffer withStatementBuffer() { + return null; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyDestination.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyDestination.java new file mode 100644 index 0000000000..853e881b1b --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyDestination.java @@ -0,0 +1,49 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketAddress; + +public class EmptyDestination implements Destination { + + public static final Destination INSTANCE = new EmptyDestination(); + + private EmptyDestination() { + } + + @Override + public Destination withAddress(@Nullable CharSequence address) { + return this; + } + + @Override + public Destination withInetAddress(InetAddress address) { + return this; + } + + @Override + public Destination withPort(int port) { + return this; + } + + @Override + public Destination withAddressPort(@Nullable String addressPort) { + return this; + } + + @Override + public Destination withInetSocketAddress(InetSocketAddress remoteAddress) { + return this; + } + + @Override + public Destination withSocketAddress(SocketAddress socketAddress) { + return this; + } + + @Override + public Cloud getCloud() { + return EmptyCloud.INSTANCE; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyFaas.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyFaas.java new file mode 100644 index 0000000000..980a2a1f5a --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyFaas.java @@ -0,0 +1,36 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public class EmptyFaas implements Faas { + + public static final Faas INSTANCE = new EmptyFaas(); + + private EmptyFaas() { + } + + @Override + public Faas withColdStart(boolean coldStart) { + return this; + } + + @Override + public Faas withId(@Nullable String id) { + return this; + } + + @Override + public Faas withName(@Nullable String name) { + return this; + } + + @Override + public Faas withVersion(@Nullable String version) { + return this; + } + + @Override + public Faas withExecution(@Nullable String execution) { + return this; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyHttp.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyHttp.java new file mode 100644 index 0000000000..6c268b29e6 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyHttp.java @@ -0,0 +1,38 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public class EmptyHttp implements Http { + + public static final Http INSTANCE = new EmptyHttp(); + + private EmptyHttp() { + } + + @Override + public Http withUrl(@Nullable String url) { + return this; + } + + @Override + public Http withMethod(String method) { + return this; + } + + @Override + public Http withStatusCode(int statusCode) { + return this; + } + + @Nullable + @Override + public CharSequence getUrl() { + return null; + } + + @Nullable + @Override + public String getMethod() { + return null; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyMessage.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyMessage.java new file mode 100644 index 0000000000..29b1e4ed21 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyMessage.java @@ -0,0 +1,46 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public class EmptyMessage implements Message { + + public static final Message INSTANCE = new EmptyMessage(); + + private EmptyMessage() { + } + + @Override + public Message withAge(long age) { + return this; + } + + @Override + public Message withBody(@Nullable String body) { + return this; + } + + @Override + public Message withRoutingKey(String routingKey) { + return this; + } + + @Override + public Message withQueue(@Nullable String queueName) { + return this; + } + + @Override + public Message addHeader(@Nullable String key, @Nullable String value) { + return this; + } + + @Override + public Message addHeader(@Nullable String key, @Nullable byte[] value) { + return this; + } + + @Override + public Message appendToBody(CharSequence bodyContent) { + return this; + } +} 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 0000000000..a109322c23 --- /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/EmptyPotentiallyMultiValuedMap.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyPotentiallyMultiValuedMap.java new file mode 100644 index 0000000000..ed512e5e0a --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyPotentiallyMultiValuedMap.java @@ -0,0 +1,37 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public class EmptyPotentiallyMultiValuedMap implements PotentiallyMultiValuedMap { + + public static final PotentiallyMultiValuedMap INSTANCE = new EmptyPotentiallyMultiValuedMap(); + + private EmptyPotentiallyMultiValuedMap() { + } + + @Override + public void add(String key, String value) { + } + + @Nullable + @Override + public String getFirst(String key) { + return null; + } + + @Nullable + @Override + public Object get(String key) { + return null; + } + + @Override + public boolean isEmpty() { + return true; + } + + @Override + public boolean containsIgnoreCase(String key) { + return false; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyRequest.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyRequest.java new file mode 100644 index 0000000000..a40917dd36 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyRequest.java @@ -0,0 +1,86 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.nio.CharBuffer; +import java.util.Enumeration; + +public class EmptyRequest implements Request { + + public static final Request INSTANCE = new EmptyRequest(); + + private EmptyRequest() { + } + + @Override + public boolean hasContent() { + return false; + } + + @Override + public Request withMethod(@Nullable String method) { + return this; + } + + @Override + public Socket getSocket() { + return EmptySocket.INSTANCE; + } + + @Override + public Url getUrl() { + return EmptyUrl.INSTANCE; + } + + @Override + public PotentiallyMultiValuedMap getHeaders() { + return EmptyPotentiallyMultiValuedMap.INSTANCE; + } + + @Override + public PotentiallyMultiValuedMap getCookies() { + return EmptyPotentiallyMultiValuedMap.INSTANCE; + } + + @Override + public Request withHttpVersion(@Nullable String httpVersion) { + return this; + } + + @Override + public CharBuffer withBodyBuffer() { + return null; + } + + @Override + public void redactBody() { + } + + @Override + public Request addFormUrlEncodedParameters(String key, String[] values) { + return this; + } + + @Override + public Request addHeader(String headerName, @Nullable Enumeration headerValues) { + return this; + } + + @Override + public Request addCookie(String cookieName, String cookieValue) { + return this; + } + + @Nullable + @Override + public CharBuffer getBodyBuffer() { + return null; + } + + @Override + public void endOfBufferInput() { + } + + @Override + public void setRawBody(String rawBody) { + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyResponse.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyResponse.java new file mode 100644 index 0000000000..9aaf2d6cbd --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyResponse.java @@ -0,0 +1,37 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.util.Collection; + +public class EmptyResponse implements Response { + + public static final Response INSTANCE = new EmptyResponse(); + + private EmptyResponse() { + } + + @Override + public PotentiallyMultiValuedMap getHeaders() { + return EmptyPotentiallyMultiValuedMap.INSTANCE; + } + + @Override + public Response withFinished(boolean finished) { + return this; + } + + @Override + public Response withStatusCode(int statusCode) { + return this; + } + + @Override + public Response withHeadersSent(boolean headersSent) { + return this; + } + + @Override + public Response addHeader(String headerName, @Nullable Collection headerValues) { + return this; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptySocket.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptySocket.java new file mode 100644 index 0000000000..142d845b19 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptySocket.java @@ -0,0 +1,16 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public class EmptySocket implements Socket { + + public static final Socket INSTANCE = new EmptySocket(); + + private EmptySocket() { + } + + @Override + public Socket withRemoteAddress(@Nullable String remoteAddress) { + return this; + } +} 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 0000000000..7bc5f0b972 --- /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/EmptyUrl.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyUrl.java new file mode 100644 index 0000000000..c64e60d471 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyUrl.java @@ -0,0 +1,45 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.net.URI; + +public class EmptyUrl implements Url { + + public static final Url INSTANCE = new EmptyUrl(); + + private EmptyUrl() { + } + + @Override + public void fillFrom(URI uri) { + } + + @Override + public void fillFrom(@Nullable String scheme, @Nullable String serverName, int serverPort, @Nullable String requestURI, @Nullable String queryString) { + } + + @Override + public Url withProtocol(@Nullable String protocol) { + return this; + } + + @Override + public Url withHostname(@Nullable String hostname) { + return this; + } + + @Override + public Url withPort(int port) { + return this; + } + + @Override + public Url withPathname(@Nullable String pathname) { + return this; + } + + @Override + public Url withSearch(@Nullable String search) { + return this; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyUser.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyUser.java new file mode 100644 index 0000000000..f8e5ba7207 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/EmptyUser.java @@ -0,0 +1,22 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public class EmptyUser implements User { + + public static final User INSTANCE = new EmptyUser(); + + private EmptyUser() { + } + + @Nullable + @Override + public String getUsername() { + return null; + } + + @Override + public User withUsername(String userName) { + return this; + } +} 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 0000000000..be0455e242 --- /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/Http.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Http.java index 943a183fb4..7e18fd580e 100644 --- a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Http.java +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Http.java @@ -10,6 +10,7 @@ public interface Http { Http withStatusCode(int statusCode); + @Nullable CharSequence getUrl(); @Nullable 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 0000000000..9354a52d76 --- /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/PotentiallyMultiValuedMap.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/PotentiallyMultiValuedMap.java index e63e9c7e84..b0a2d08c1f 100644 --- a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/PotentiallyMultiValuedMap.java +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/PotentiallyMultiValuedMap.java @@ -21,30 +21,16 @@ import javax.annotation.Nullable; import java.util.List; -public interface PotentiallyMultiValuedMap extends Recyclable { +public interface PotentiallyMultiValuedMap { void add(String key, String value); - void set(String key, String... values); - @Nullable String getFirst(String key); @Nullable Object get(String key); - List getAll(String key); - boolean isEmpty(); - String getKey(int i); - - Object getValue(int i); - - int size(); - - void removeIgnoreCase(String key); - - void set(int index, String value); - boolean containsIgnoreCase(String key); } diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Request.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Request.java index 51e6cab00c..cf07dc3ec3 100644 --- a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Request.java +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Request.java @@ -19,6 +19,7 @@ public interface Request { Request withHttpVersion(@Nullable String httpVersion); + @Nullable CharBuffer withBodyBuffer(); void redactBody(); @@ -29,6 +30,7 @@ public interface Request { Request addCookie(String cookieName, String cookieValue); + @Nullable CharBuffer getBodyBuffer(); void endOfBufferInput(); 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 0000000000..e8d1fa0a53 --- /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 0000000000..dde77f73e7 --- /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/User.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/User.java index 9d2dd7e6ec..47517f538a 100644 --- a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/User.java +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/User.java @@ -1,6 +1,10 @@ package co.elastic.apm.plugin.spi; +import javax.annotation.Nullable; + public interface User { + + @Nullable String getUsername(); User withUsername(String userName); 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 0000000000..9a2e77d1ca --- /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 0000000000..16f424fba6 --- /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 0000000000..7ea3b6eb09 --- /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 faa7ada612..fc217622b2 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 cd84b9d23c..bb993f4d62 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 5152ed05b0..a82517c88a 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 b11ac54bbc..32362df4c7 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 cdc27247cc..fe54ba9fa2 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 7cfea9a01c..d383933947 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 2a5fc8f37d..9f916a3cea 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; @@ -31,6 +31,7 @@ import org.elasticsearch.client.ResponseListener; import javax.annotation.Nullable; +import java.nio.CharBuffer; import java.util.Arrays; import java.util.List; import java.util.concurrent.CancellationException; @@ -43,11 +44,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,10 +97,13 @@ 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()); + CharBuffer buffer = span.getContext().getDb().withStatementBuffer(); + if (buffer != null) { + IOUtils.readUtf8Stream(httpEntity.getContent(), buffer); + } } catch (UnsupportedOperationException e) { // special case for hibernatesearch versions pre 6.0: // those don't support httpEntity.getContent() and throw an UnsupportedException when called. 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 ff94f262a7..ca3be2a963 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 6aabc300d5..e57f4d2f50 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 6b274018f9..b6f007b801 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 254a27d0f1..dc56876d7d 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 eed00caf08..113f81c271 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 16fdd04eba..a942a6f174 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 63d10be7d3..6e95cec217 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 ca25a4cae0..c3c894f3c4 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 3106c0bc6c..7f998df01f 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 ad78a9722d..09454262fa 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 5461451e6c..aa49f4288f 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 54cbd466ba..7cb1bcca39 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 9de2953c41..fcf53aee3a 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 093e7ac480..3712105a3f 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 9725559c9c..add0c4157f 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 f5063829dc..0ce8e68a86 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 dbeaa74fd3..c8bef5be52 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 5288df61d8..650cd2637a 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 d6101c0d04..284658eda8 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 b2e76786f7..aa0dff9a1a 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 6239871f6e..612e8263c5 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 9287d7572b..0ddf7a826f 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 d289187975..20af5b214e 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 bab80acca4..0e769dc320 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 091661a46b..0d4ea27086 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 028b557443..44f78b654b 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 38b8c6d384..5e29c9e0ed 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 d78e992752..4c947e6137 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 7343a1d8d9..85e5461561 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 a0f98874eb..cd58f63da9 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 876a9bced8..1a22f859b6 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 29cd3a0823..bc5387bc2d 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 33d97d4d48..39e3b4c6ca 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) {