diff --git a/apm-agent-core/pom.xml b/apm-agent-core/pom.xml
index 077a22be2d..f39b9cec66 100644
--- a/apm-agent-core/pom.xml
+++ b/apm-agent-core/pom.xml
@@ -10,6 +10,12 @@
apm-agent-core
${project.groupId}:${project.artifactId}
+
+
+ The Apache Software License, Version 2.0
+ http://www.apache.org/licenses/LICENSE-2.0.txt
+
+
true
@@ -18,6 +24,11 @@
+
+ ${project.groupId}
+ apm-agent-plugin-sdk
+ ${project.version}
+
com.lmax
disruptor
@@ -29,11 +40,6 @@
2.1.2
-
- org.slf4j
- slf4j-api
- ${version.slf4j}
-
org.apache.logging.log4j
log4j-core
@@ -49,22 +55,12 @@
log4j2-ecs-layout
0.3.0
-
- com.blogspot.mydailyjava
- weak-lock-free
- 0.15
-
org.stagemonitor
stagemonitor-configuration
0.87.3
-
- net.bytebuddy
- byte-buddy-dep
- ${version.byte-buddy}
-
org.ow2.asm
asm-tree
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/annotation/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/annotation/package-info.java
index 7e271b670d..e08a5e3ecb 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/annotation/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/annotation/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -24,3 +24,5 @@
*/
@NonnullApi
package co.elastic.apm.agent.annotation;
+
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/DynamicTransformerImpl.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/DynamicTransformerImpl.java
new file mode 100644
index 0000000000..f73175328a
--- /dev/null
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/DynamicTransformerImpl.java
@@ -0,0 +1,38 @@
+/*-
+ * #%L
+ * Elastic APM Java agent
+ * %%
+ * Copyright (C) 2018 - 2020 Elastic and contributors
+ * %%
+ * 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.
+ * #L%
+ */
+package co.elastic.apm.agent.bci;
+
+import co.elastic.apm.agent.sdk.DynamicTransformer;
+import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
+
+import java.util.Collection;
+
+public class DynamicTransformerImpl implements DynamicTransformer {
+
+ @Override
+ public void ensureInstrumented(Class> classToInstrument, Collection> instrumentationClasses) {
+ ElasticApmAgent.ensureInstrumented(classToInstrument, instrumentationClasses);
+ }
+}
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java
index 67f7f1537c..6f44750478 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java
@@ -34,15 +34,18 @@
import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory;
import co.elastic.apm.agent.bci.bytebuddy.SoftlyReferencingTypePoolCache;
import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignToPostProcessorFactory;
+import co.elastic.apm.agent.bci.classloading.ExternalPluginClassLoader;
import co.elastic.apm.agent.bci.methodmatching.MethodMatcher;
import co.elastic.apm.agent.bci.methodmatching.TraceMethodInstrumentation;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.configuration.CoreConfiguration;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.ElasticApmTracerBuilder;
import co.elastic.apm.agent.impl.GlobalTracer;
+import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import co.elastic.apm.agent.util.DependencyInjectingServiceLoader;
import co.elastic.apm.agent.util.ExecutorUtils;
+import co.elastic.apm.agent.util.ObjectUtils;
import co.elastic.apm.agent.util.ThreadUtils;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import net.bytebuddy.ByteBuddy;
@@ -69,6 +72,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.File;
+import java.io.FilenameFilter;
import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.lang.reflect.Constructor;
@@ -78,6 +82,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -115,6 +120,7 @@ public class ElasticApmAgent {
private static final WeakConcurrentMap, Set>>> dynamicallyInstrumentedClasses = WeakMapSupplier.createMap();
@Nullable
private static File agentJarFile;
+ private static final Map pluginClassLoaderByAdviceClass = new ConcurrentHashMap<>();
/**
* Called reflectively by {@link AgentMain} to initialize the agent
@@ -144,14 +150,51 @@ private static void initInstrumentation(ElasticApmTracer tracer, Instrumentation
@Nonnull
private static Iterable loadInstrumentations(ElasticApmTracer tracer) {
- final List instrumentations = DependencyInjectingServiceLoader.load(ElasticApmInstrumentation.class, tracer);
+ List pluginClassLoaders = new ArrayList<>();
+ pluginClassLoaders.add(ElasticApmAgent.class.getClassLoader());
+ pluginClassLoaders.addAll(createExternalPluginClassLoaders(tracer.getConfig(CoreConfiguration.class).getPluginsDir()));
+ final List instrumentations = DependencyInjectingServiceLoader.load(ElasticApmInstrumentation.class, pluginClassLoaders, tracer);
for (MethodMatcher traceMethod : tracer.getConfig(CoreConfiguration.class).getTraceMethods()) {
instrumentations.add(new TraceMethodInstrumentation(tracer, traceMethod));
}
-
return instrumentations;
}
+ private static Collection extends ClassLoader> createExternalPluginClassLoaders(@Nullable String pluginsDirString) {
+ final Logger logger = LoggerFactory.getLogger(ElasticApmAgent.class);
+ if (pluginsDirString == null) {
+ logger.debug("No plugins dir");
+ return Collections.emptyList();
+ }
+ File pluginsDir = new File(pluginsDirString);
+ if (!pluginsDir.exists()) {
+ logger.debug("Plugins dir does not exist: {}", pluginsDirString);
+ return Collections.emptyList();
+ }
+ File[] pluginJars = pluginsDir.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".jar");
+ }
+ });
+ if (pluginJars == null) {
+ logger.info("Invalid plugins dir {}", pluginsDirString);
+ return Collections.emptyList();
+ }
+ List result = new ArrayList<>(pluginJars.length);
+ for (File pluginJar : pluginJars) {
+ try {
+ result.add(new ExternalPluginClassLoader(pluginJar, ElasticApmAgent.class.getClassLoader()));
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ logger.info("Loading plugin {}", pluginJar.getName());
+ }
+ return result;
+ }
+
+
+
public static synchronized void initInstrumentation(final ElasticApmTracer tracer, Instrumentation instrumentation,
Iterable instrumentations) {
initInstrumentation(tracer, instrumentation, instrumentations, false);
@@ -163,6 +206,11 @@ private static synchronized void initInstrumentation(final ElasticApmTracer trac
return;
}
GlobalTracer.set(tracer);
+ for (ElasticApmInstrumentation apmInstrumentation : instrumentations) {
+ pluginClassLoaderByAdviceClass.put(
+ apmInstrumentation.getAdviceClass().getName(),
+ ObjectUtils.systemClassLoaderIfNull(apmInstrumentation.getClass().getClassLoader()));
+ }
Runtime.getRuntime().addShutdownHook(new Thread(ThreadUtils.addElasticApmThreadPrefix("init-instrumentation-shutdown-hook")) {
@Override
public void run() {
@@ -266,7 +314,7 @@ private static AgentBuilder applyAdvice(final ElasticApmTracer tracer, final Age
final boolean typeMatchingWithNamePreFilter = tracer.getConfig(CoreConfiguration.class).isTypeMatchingWithNamePreFilter();
final ElementMatcher.Junction classLoaderMatcher = instrumentation.getClassLoaderMatcher();
final ElementMatcher super NamedElement> typeMatcherPreFilter = instrumentation.getTypeMatcherPreFilter();
- final ElementMatcher.Junction versionPostFilter = instrumentation.getImplementationVersionPostFilter();
+ final ElementMatcher.Junction versionPostFilter = instrumentation.getProtectionDomainPostFilter();
final ElementMatcher super MethodDescription> methodMatcher = new ElementMatcher.Junction.Conjunction<>(instrumentation.getMethodMatcher(), not(isAbstract()));
return agentBuilder
.type(new AgentBuilder.RawMatcher() {
@@ -339,8 +387,10 @@ private static AgentBuilder.Transformer.ForAdvice getTransformer(final ElasticAp
if (offsetMapping != null) {
withCustomMapping = withCustomMapping.bind(offsetMapping);
}
- if (instrumentation.indyPlugin()) {
- validateAdvice(instrumentation.getAdviceClass().getName());
+ // external plugins are always indy plugins
+ if (!(instrumentation instanceof TracerAwareInstrumentation)
+ || ((TracerAwareInstrumentation) instrumentation).indyPlugin()) {
+ validateAdvice(instrumentation.getAdviceClass());
withCustomMapping = withCustomMapping.bootstrap(IndyBootstrap.getIndyBootstrapMethod());
}
return new AgentBuilder.Transformer.ForAdvice(withCustomMapping)
@@ -366,17 +416,22 @@ public boolean matches(MethodDescription target) {
}
}
}, instrumentation.getAdviceClass().getName())
- .include(ClassLoader.getSystemClassLoader())
+ .include(ClassLoader.getSystemClassLoader(), instrumentation.getClass().getClassLoader())
.withExceptionHandler(PRINTING);
}
/**
- * Validates invariants explained in {@link ElasticApmInstrumentation#indyPlugin()}
+ * Validates invariants explained in {@link TracerAwareInstrumentation#indyPlugin()}
*
- * @param adviceClassName the name of the advice class
+ * @param adviceClass the advice class
*/
- private static void validateAdvice(String adviceClassName) {
- TypePool pool = new TypePool.Default.WithLazyResolution(TypePool.CacheProvider.NoOp.INSTANCE, ClassFileLocator.ForClassLoader.ofSystemLoader(), TypePool.Default.ReaderMode.FAST);
+ private static void validateAdvice(Class> adviceClass) {
+ String adviceClassName = adviceClass.getName();
+ ClassLoader classLoader = adviceClass.getClassLoader();
+ if (classLoader == null) {
+ classLoader = ClassLoader.getSystemClassLoader();
+ }
+ TypePool pool = new TypePool.Default.WithLazyResolution(TypePool.CacheProvider.NoOp.INSTANCE, ClassFileLocator.ForClassLoader.of(classLoader), TypePool.Default.ReaderMode.FAST);
TypeDescription typeDescription = pool.describe(adviceClassName).resolve();
for (MethodDescription.InDefinedShape enterAdvice : typeDescription.getDeclaredMethods().filter(isStatic().and(isAnnotatedWith(Advice.OnMethodEnter.class)))) {
validateAdviceReturnAndParameterTypes(enterAdvice);
@@ -398,7 +453,7 @@ private static void validateAdvice(String adviceClassName) {
}
}
}
- if (adviceClassName.startsWith("co.elastic.apm.agent.") && adviceClassName.split("\\.").length > 6) {
+ if (!(classLoader instanceof ExternalPluginClassLoader) && adviceClassName.startsWith("co.elastic.apm.agent.") && adviceClassName.split("\\.").length > 6) {
throw new IllegalStateException("Indy-dispatched advice class must be at the root of the instrumentation plugin.");
}
}
@@ -607,6 +662,9 @@ public static void ensureInstrumented(Class> classToInstrument, Collection instrumentationClass : instrumentationClasses) {
+ pluginClassLoaderByAdviceClass.put(
+ instrumentationClass.getName(),
+ ObjectUtils.systemClassLoaderIfNull(instrumentationClass.getClassLoader()));
ElasticApmInstrumentation apmInstrumentation = instantiate(instrumentationClass);
ElementMatcher.Junction super TypeDescription> typeMatcher = getTypeMatcher(classToInstrument, apmInstrumentation.getMethodMatcher(), none());
if (typeMatcher != null && isIncluded(apmInstrumentation, config)) {
@@ -693,15 +751,19 @@ private static ElasticApmInstrumentation tryInstantiate(Class extends ElasticA
}
public static ClassLoader getAgentClassLoader() {
- ClassLoader agentClassLoader = ElasticApmAgent.class.getClassLoader();
- if (agentClassLoader == null) {
- // currently, the agent CL is the bootstrap CL in production
- // but resources are not loadable from the bootstrap CL, only from the system CL
- // also, we want to return a no-null CL from here
- return ClassLoader.getSystemClassLoader();
- }
+ // currently, the agent CL is the bootstrap CL in production
+ // but resources are not loadable from the bootstrap CL, only from the system CL
+ // also, we want to return a no-null CL from here
// in tests, the agent CL is the system CL
// in the future, the agent will be loaded from an isolated CL in production
- return agentClassLoader;
+ return ObjectUtils.systemClassLoaderIfNull(ElasticApmAgent.class.getClassLoader());
+ }
+
+ public static ClassLoader getClassLoader(String adviceClass) {
+ ClassLoader classLoader = pluginClassLoaderByAdviceClass.get(adviceClass);
+ if (classLoader == null) {
+ throw new IllegalStateException("There's no mapping for key " + adviceClass);
+ }
+ return classLoader;
}
}
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/HelperClassManager.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/HelperClassManager.java
index 35e3848199..50f67e81f0 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/HelperClassManager.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/HelperClassManager.java
@@ -24,14 +24,13 @@
*/
package co.elastic.apm.agent.bci;
-import co.elastic.apm.agent.impl.Tracer;
+import co.elastic.apm.agent.bci.classloading.IndyPluginClassLoader;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.ClassFileLocator;
import net.bytebuddy.dynamic.loading.ByteArrayClassLoader;
import net.bytebuddy.dynamic.loading.ClassInjector;
-import net.bytebuddy.dynamic.loading.MultipleParentClassLoader;
import net.bytebuddy.dynamic.loading.PackageDefinitionStrategy;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.pool.TypePool;
@@ -286,7 +285,7 @@ public static class ForIndyPlugin {
* Creates an isolated CL that has two parents: the target class loader and the agent CL.
* The agent class loader is currently the bootstrap CL but in the future it will be an isolated CL that is a child of the bootstrap CL.
*/
- public synchronized static ClassLoader getOrCreatePluginClassLoader(@Nullable ClassLoader targetClassLoader, List classesToInject, ElementMatcher super TypeDescription> exclusionMatcher) throws Exception {
+ public synchronized static ClassLoader getOrCreatePluginClassLoader(@Nullable ClassLoader targetClassLoader, List classesToInject, ClassLoader parent, ElementMatcher super TypeDescription> exclusionMatcher) throws Exception {
classesToInject = new ArrayList<>(classesToInject);
Map, WeakReference> injectedClasses = getOrCreateInjectedClasses(targetClassLoader);
@@ -300,7 +299,7 @@ public synchronized static ClassLoader getOrCreatePluginClassLoader(@Nullable Cl
}
List classesToInjectCopy = new ArrayList<>(classesToInject.size());
- TypePool pool = new TypePool.Default.WithLazyResolution(TypePool.CacheProvider.NoOp.INSTANCE, ClassFileLocator.ForClassLoader.ofSystemLoader(), TypePool.Default.ReaderMode.FAST);
+ TypePool pool = new TypePool.Default.WithLazyResolution(TypePool.CacheProvider.NoOp.INSTANCE, ClassFileLocator.ForClassLoader.of(parent), TypePool.Default.ReaderMode.FAST);
for (Iterator iterator = classesToInject.iterator(); iterator.hasNext(); ) {
String className = iterator.next();
if (!exclusionMatcher.matches(pool.describe(className).resolve())) {
@@ -309,18 +308,9 @@ public synchronized static ClassLoader getOrCreatePluginClassLoader(@Nullable Cl
}
logger.debug("Creating plugin class loader for {} containing {}", targetClassLoader, classesToInjectCopy);
- ClassLoader parent = getPluginClassLoaderParent(targetClassLoader);
- Map typeDefinitions = getTypeDefinitions(classesToInjectCopy);
+ Map typeDefinitions = getTypeDefinitions(classesToInjectCopy, parent);
// child first semantics are important here as the plugin CL contains classes that are also present in the agent CL
- ClassLoader pluginClassLoader = new ByteArrayClassLoader.ChildFirst(parent, true, typeDefinitions, ByteArrayClassLoader.PersistenceHandler.MANIFEST) {
- @Override
- protected Class> loadClass(String name, boolean resolve) throws ClassNotFoundException {
- if (name.equals("java.lang.ThreadLocal")) {
- throw new ClassNotFoundException("The usage of ThreadLocals is not allowed in instrumentation plugins. Use GlobalThreadLocal instead.");
- }
- return super.loadClass(name, resolve);
- }
- };
+ ClassLoader pluginClassLoader = new IndyPluginClassLoader(targetClassLoader, parent, typeDefinitions);
injectedClasses.put(classesToInject, new WeakReference<>(pluginClassLoader));
return pluginClassLoader;
@@ -335,17 +325,10 @@ private static Map, WeakReference> getOrCreateIn
return injectedClasses;
}
- private static ClassLoader getPluginClassLoaderParent(@Nullable ClassLoader targetClassLoader) {
- ClassLoader agentClassLoader = ElasticApmAgent.getAgentClassLoader();
- // the plugin class loader has both, the agent class loader and the target class loader as the parent
- // this is important so that the plugin class loader has direct access to the agent class loader
- // otherwise, filtering class loaders (like OSGi) have a chance to interfere
- return new MultipleParentClassLoader(Arrays.asList(agentClassLoader, targetClassLoader));
- }
-
public synchronized static void clear() {
alreadyInjected.clear();
}
+
}
static Class injectClass(@Nullable ClassLoader targetClassLoader, @Nullable ProtectionDomain pd, String className, boolean isBootstrapClass) throws IOException, ClassNotFoundException {
@@ -364,7 +347,7 @@ static Class injectClass(@Nullable ClassLoader targetClassLoader, @Nullable Prot
classInjector = new ClassInjector.UsingReflection(targetClassLoader, pd, PackageDefinitionStrategy.NoOp.INSTANCE,
true);
}
- final byte[] classBytes = getAgentClassBytes(className);
+ final byte[] classBytes = ClassFileLocator.ForClassLoader.of(ElasticApmAgent.getAgentClassLoader()).locate(className).resolve();
final TypeDescription typeDesc =
new TypeDescription.Latent(className, 0, null, Collections.emptyList());
Map typeMap = new HashMap<>();
@@ -375,7 +358,7 @@ static Class injectClass(@Nullable ClassLoader targetClassLoader, @Nullable Prot
private static T createHelper(@Nullable ClassLoader targetClassLoader, ElasticApmTracer tracer, String implementation,
String... additionalHelpers) {
try {
- final Map typeDefinitions = getTypeDefinitions(asList(implementation, additionalHelpers));
+ final Map typeDefinitions = getTypeDefinitions(asList(implementation, additionalHelpers), ElasticApmAgent.getAgentClassLoader());
Class extends T> helperClass;
try {
helperClass = loadHelperClass(targetClassLoader, implementation, typeDefinitions);
@@ -410,17 +393,13 @@ private static Class loadHelperClass(@Nullable ClassLoader targetClassLoa
return (Class) helperCL.loadClass(implementation);
}
- private static Map getTypeDefinitions(List helperClassNames) throws IOException {
+ private static Map getTypeDefinitions(List helperClassNames, ClassLoader classLoader) throws IOException {
Map typeDefinitions = new HashMap<>();
for (final String helperName : helperClassNames) {
- final byte[] classBytes = getAgentClassBytes(helperName);
+ final byte[] classBytes = ClassFileLocator.ForClassLoader.of(classLoader).locate(helperName).resolve();
typeDefinitions.put(helperName, classBytes);
}
return typeDefinitions;
}
- private static byte[] getAgentClassBytes(String className) throws IOException {
- final ClassFileLocator locator = ClassFileLocator.ForClassLoader.of(ElasticApmAgent.getAgentClassLoader());
- return locator.locate(className).resolve();
- }
}
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/IndyBootstrap.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/IndyBootstrap.java
index 0e97c10d5c..b52d470e63 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/IndyBootstrap.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/IndyBootstrap.java
@@ -24,6 +24,9 @@
*/
package co.elastic.apm.agent.bci;
+import co.elastic.apm.agent.bci.classloading.ExternalPluginClassLoader;
+import co.elastic.apm.agent.bci.classloading.IndyPluginClassLoader;
+import co.elastic.apm.agent.sdk.state.GlobalState;
import co.elastic.apm.agent.util.PackageScanner;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.dynamic.loading.ClassInjector;
@@ -31,12 +34,14 @@
import org.stagemonitor.util.IOUtils;
import javax.annotation.Nullable;
+import java.io.IOException;
import java.lang.invoke.CallSite;
import java.lang.invoke.ConstantCallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
+import java.net.URISyntaxException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@@ -47,7 +52,7 @@
import static net.bytebuddy.matcher.ElementMatchers.named;
/**
- * When {@link ElasticApmInstrumentation#indyPlugin()} returns {@code true},
+ * When {@link TracerAwareInstrumentation#indyPlugin()} returns {@code true},
* we instruct Byte Buddy (via {@link Advice.WithCustomMapping#bootstrap(java.lang.reflect.Method)})
* to dispatch {@linkplain Advice.OnMethodEnter#inline() non-inlined advices} via an invokedynamic (indy) instruction.
* The target method is linked to a dynamically created plugin class loader that is specific to an instrumentation plugin
@@ -60,17 +65,17 @@
*
* Bootstrap CL ←──────────────────────────── Agent CL
* ↑ └java.lang.IndyBootstrapDispatcher ─ ↑ ─→ └ {@link IndyBootstrap#bootstrap}
- * Ext/Platform CL ↑ │ ╷
- * ↑ ╷ │ ↓
- * System CL ╷ │ {@link HelperClassManager.ForIndyPlugin#getOrCreatePluginClassLoader}
- * ↑ ╷ │ ╷
- * Common linking of CallSite │ ╷
- * ↑ ↑ (on first invocation) │ creates
- * WebApp1 WebApp2 ╷ │ ╷
- * ↑ - InstrumentedClass ╷ │ ╷
- * │ ╷ ╷ │ ╷
- * │ INVOKEDYNAMIC │ ↓
- * └────────────────┼──────────────────Plugin CL
+ * Ext/Platform CL ↑ │ ╷
+ * ↑ ╷ │ ↓
+ * System CL ╷ │ {@link HelperClassManager.ForIndyPlugin#getOrCreatePluginClassLoader}
+ * ↑ ╷ │ ╷
+ * Common linking of CallSite {@link ExternalPluginClassLoader}
+ * ↑ ↑ (on first invocation) ↑ ├ AdviceClass ╷
+ * WebApp1 WebApp2 ╷ │ ├ AdviceHelper creates
+ * ↑ - InstrumentedClass ╷ │ └ GlobalState ╷
+ * │ ╷ ╷ │ ╷
+ * │ INVOKEDYNAMIC │ ↓
+ * └────────────────┼──────────────────{@link IndyPluginClassLoader}
* └╶╶╶╶╶╶╶╶╶╶╶╶╶╶╶╶→ ├ AdviceClass
* └ AdviceHelper
* Legend:
@@ -147,10 +152,10 @@
*
*
* There are some things to watch out for when writing plugins,
- * as explained in {@link ElasticApmInstrumentation#indyPlugin()}
+ * as explained in {@link TracerAwareInstrumentation#indyPlugin()}
*
*
- * @see ElasticApmInstrumentation#indyPlugin()
+ * @see TracerAwareInstrumentation#indyPlugin()
*/
public class IndyBootstrap {
@@ -264,15 +269,18 @@ public static ConstantCallSite bootstrap(MethodHandles.Lookup lookup,
Class> instrumentedType = (Class>) args[2];
String instrumentedMethodName = (String) args[3];
MethodHandle instrumentedMethod = args.length >= 5 ? (MethodHandle) args[4] : null;
- String packageName = adviceClassName.substring(0, adviceClassName.lastIndexOf('.'));
- List pluginClasses = classesByPackage.get(packageName);
- if (pluginClasses == null) {
- classesByPackage.putIfAbsent(packageName, PackageScanner.getClassNames(packageName));
- pluginClasses = classesByPackage.get(packageName);
+
+ ClassLoader adviceClassLoader = ElasticApmAgent.getClassLoader(adviceClassName);
+ List pluginClasses;
+ if (adviceClassLoader instanceof ExternalPluginClassLoader) {
+ pluginClasses = ((ExternalPluginClassLoader) adviceClassLoader).getClassNames();
+ } else {
+ pluginClasses = getClassNamesFromBundledPlugin(adviceClassName, adviceClassLoader);
}
ClassLoader pluginClassLoader = HelperClassManager.ForIndyPlugin.getOrCreatePluginClassLoader(
lookup.lookupClass().getClassLoader(),
pluginClasses,
+ adviceClassLoader,
isAnnotatedWith(named(GlobalState.class.getName()))
// no plugin CL necessary as all types are available form bootstrap CL
// also, this plugin is used as a dependency in other plugins
@@ -286,4 +294,16 @@ public static ConstantCallSite bootstrap(MethodHandles.Lookup lookup,
return null;
}
}
+
+ private static List getClassNamesFromBundledPlugin(String adviceClassName, ClassLoader adviceClassLoader) throws IOException, URISyntaxException {
+ List pluginClasses;
+ String packageName = adviceClassName.substring(0, adviceClassName.lastIndexOf('.'));
+ pluginClasses = classesByPackage.get(packageName);
+ if (pluginClasses == null) {
+ classesByPackage.putIfAbsent(packageName, PackageScanner.getClassNames(packageName, adviceClassLoader));
+ pluginClasses = classesByPackage.get(packageName);
+ }
+ return pluginClasses;
+ }
+
}
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/TracerAwareInstrumentation.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/TracerAwareInstrumentation.java
index 77edfa30a2..eab28989ac 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/TracerAwareInstrumentation.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/TracerAwareInstrumentation.java
@@ -27,6 +27,10 @@
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.GlobalTracer;
import co.elastic.apm.agent.impl.Tracer;
+import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
+import co.elastic.apm.agent.sdk.state.GlobalThreadLocal;
+import net.bytebuddy.asm.Advice;
/**
* The constructor can optionally have a {@link ElasticApmTracer} parameter.
@@ -36,4 +40,57 @@ public abstract class TracerAwareInstrumentation extends ElasticApmInstrumentati
@VisibleForAdvice
public static final Tracer tracer = GlobalTracer.get();
+ /**
+ * When this method returns {@code true} the whole package (starting at the {@linkplain #getAdviceClass() advice's} package)
+ * will be loaded from a plugin class loader that has both the agent class loader and the class loader of the class this instruments as
+ * parents.
+ *
+ * This instructs Byte Buddy to dispatch to the advice methods via an {@code INVOKEDYNAMIC} instruction.
+ * Upon first invocation of an instrumented method,
+ * this will call {@code IndyBootstrap#bootstrap} to determine the target {@link java.lang.invoke.ConstantCallSite}.
+ *
+ *
+ * Things to watch out for when using indy plugins:
+ *
+ *
+ * -
+ * Set {@link Advice.OnMethodEnter#inline()} and {@link Advice.OnMethodExit#inline()} to {@code false} on all advices.
+ * As the {@code readOnly} flag in Byte Buddy annotations such as {@link Advice.Return#readOnly()} cannot be used with non
+ * {@linkplain Advice.OnMethodEnter#inline() inlined advices},
+ * use {@link AssignTo} and friends.
+ *
+ * -
+ * Both the return type and the arguments of advice methods must not contain types from the agent.
+ * If you'd like to return a span from an advice, for example, return an {@link Object} instead.
+ * When using an {@link Advice.Enter} argument on the {@linkplain Advice.OnMethodExit exit advice},
+ * that argument also has to be of type {@link Object} and you have to cast it within the method body.
+ * The reason is that the return value will become a local variable in the instrumented method.
+ * Due to OSGi, those methods may not have access to agent types.
+ * Another case is when the instrumented class is inside the bootstrap classloader.
+ *
+ * -
+ * When an advice instruments classes in multiple class loaders, the plugin classes will be loaded form multiple class loaders.
+ * In order to still share state across those plugin class loaders,
+ * use {@link co.elastic.apm.agent.sdk.state.GlobalVariables} or {@link co.elastic.apm.agent.sdk.state.GlobalState}.
+ * That's necessary as static variables are scoped to the class loader they are defined in.
+ *
+ * -
+ * Don't use {@link ThreadLocal}s as it can lead to class loader leaks.
+ * Use {@link GlobalThreadLocal} instead.
+ *
+ * -
+ * Due to the automatic plugin classloader creation that is based on package scanning,
+ * plugins need be in their own uniquely named package.
+ * As the package of the {@link #getAdviceClass()} is used as the root,
+ * all advices have to be at the top level of the plugin.
+ *
+ *
+ *
+ * @return whether to load the classes of this plugin in dedicated plugin class loaders (one for each unique class loader)
+ * and dispatch to the {@linkplain #getAdviceClass() advice} via an {@code INVOKEDYNAMIC} instruction.
+ */
+ public boolean indyPlugin() {
+ return false;
+ }
+
}
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 f074ef1b07..d3b691ead1 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
@@ -24,9 +24,9 @@
*/
package co.elastic.apm.agent.bci.bytebuddy;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.matcher.AnnotationMatcher;
import co.elastic.apm.agent.matcher.WildcardMatcher;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import co.elastic.apm.agent.util.Version;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import net.bytebuddy.description.NamedElement;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/PatchBytecodeVersionTo51Transformer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/PatchBytecodeVersionTo51Transformer.java
index 54b67b5870..d9824aa9a3 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/PatchBytecodeVersionTo51Transformer.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/PatchBytecodeVersionTo51Transformer.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -24,7 +24,7 @@
*/
package co.elastic.apm.agent.bci.bytebuddy;
-import co.elastic.apm.agent.bci.ElasticApmInstrumentation;
+import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.AsmVisitorWrapper;
@@ -45,7 +45,7 @@
/**
* Patches the class file version to 51 (Java 7) in order to support injecting {@code INVOKEDYNAMIC} instructions via
- * {@link Advice.WithCustomMapping#bootstrap} which is important for {@linkplain ElasticApmInstrumentation#indyPlugin() indy plugins}.
+ * {@link Advice.WithCustomMapping#bootstrap} which is important for {@linkplain TracerAwareInstrumentation#indyPlugin() indy plugins}.
*/
public class PatchBytecodeVersionTo51Transformer implements AgentBuilder.Transformer {
@Override
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/package-info.java
index 73a4e379eb..05a2c0c447 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.bci.bytebuddy;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/postprocessor/AssignToPostProcessorFactory.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/postprocessor/AssignToPostProcessorFactory.java
index e59b4d4ed1..9aa8826d20 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/postprocessor/AssignToPostProcessorFactory.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/postprocessor/AssignToPostProcessorFactory.java
@@ -24,6 +24,7 @@
*/
package co.elastic.apm.agent.bci.bytebuddy.postprocessor;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.annotation.AnnotationList;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/postprocessor/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/postprocessor/package-info.java
index b39221de0a..f766d96f5b 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/postprocessor/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/postprocessor/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.bci.bytebuddy.postprocessor;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/ExternalPluginClassLoader.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/ExternalPluginClassLoader.java
new file mode 100644
index 0000000000..b104b9d6e3
--- /dev/null
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/ExternalPluginClassLoader.java
@@ -0,0 +1,75 @@
+/*-
+ * #%L
+ * Elastic APM Java agent
+ * %%
+ * Copyright (C) 2018 - 2020 Elastic and contributors
+ * %%
+ * 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.
+ * #L%
+ */
+package co.elastic.apm.agent.bci.classloading;
+
+import co.elastic.apm.agent.configuration.CoreConfiguration;
+import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * Loads plugins from {@link CoreConfiguration#getPluginsDir() plugins_dir}
+ *
+ * @see co.elastic.apm.agent.bci.IndyBootstrap
+ */
+public class ExternalPluginClassLoader extends URLClassLoader {
+ private final List classNames;
+
+ public ExternalPluginClassLoader(File pluginJar, ClassLoader agentClassLoader) throws IOException {
+ super(new URL[]{pluginJar.toURI().toURL()}, agentClassLoader);
+ classNames = Collections.unmodifiableList(scanForClasses(pluginJar));
+ if (classNames.contains(ElasticApmInstrumentation.class.getName())) {
+ throw new IllegalStateException("The plugin %s contains the plugin SDK. Please make sure the scope for the dependency apm-agent-plugin-sdk is set to provided.");
+ }
+ }
+
+ private List scanForClasses(File pluginJar) throws IOException {
+ List tempClassNames = new ArrayList<>();
+ try (JarFile jarFile = new JarFile(pluginJar)) {
+ Enumeration entries = jarFile.entries();
+ while (entries.hasMoreElements()) {
+ JarEntry jarEntry = entries.nextElement();
+ if (jarEntry.getName().endsWith(".class")) {
+ tempClassNames.add(jarEntry.getName().replace('/', '.').substring(0, jarEntry.getName().length() - 6));
+ }
+ }
+ }
+ return tempClassNames;
+ }
+
+ public List getClassNames() {
+ return classNames;
+ }
+
+}
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/IndyPluginClassLoader.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/IndyPluginClassLoader.java
new file mode 100644
index 0000000000..69a96db612
--- /dev/null
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/IndyPluginClassLoader.java
@@ -0,0 +1,53 @@
+/*-
+ * #%L
+ * Elastic APM Java agent
+ * %%
+ * Copyright (C) 2018 - 2020 Elastic and contributors
+ * %%
+ * 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.
+ * #L%
+ */
+package co.elastic.apm.agent.bci.classloading;
+
+import net.bytebuddy.dynamic.loading.ByteArrayClassLoader;
+import net.bytebuddy.dynamic.loading.MultipleParentClassLoader;
+
+import javax.annotation.Nullable;
+import java.util.Arrays;
+import java.util.Map;
+
+/**
+ * The plugin class loader has both the agent class loader and the target class loader as the parent.
+ * This is important so that the plugin class loader has direct access to the agent class loader
+ * otherwise, filtering class loaders (like OSGi) have a chance to interfere
+ *
+ * @see co.elastic.apm.agent.bci.IndyBootstrap
+ */
+public class IndyPluginClassLoader extends ByteArrayClassLoader.ChildFirst {
+ public IndyPluginClassLoader(@Nullable ClassLoader targetClassLoader, ClassLoader agentClassLoader, Map typeDefinitions) {
+ super(new MultipleParentClassLoader(Arrays.asList(agentClassLoader, targetClassLoader)), true, typeDefinitions, PersistenceHandler.MANIFEST);
+ }
+
+ @Override
+ protected Class> loadClass(String name, boolean resolve) throws ClassNotFoundException {
+ if (name.equals("java.lang.ThreadLocal")) {
+ throw new ClassNotFoundException("The usage of ThreadLocals is not allowed in instrumentation plugins. Use GlobalThreadLocal instead.");
+ }
+ return super.loadClass(name, resolve);
+ }
+}
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/threadlocal/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/package-info.java
similarity index 90%
rename from apm-agent-core/src/main/java/co/elastic/apm/agent/threadlocal/package-info.java
rename to apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/package-info.java
index 831582f7c1..29e6079b8a 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/threadlocal/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/package-info.java
@@ -23,6 +23,6 @@
* #L%
*/
@NonnullApi
-package co.elastic.apm.agent.threadlocal;
+package co.elastic.apm.agent.bci.classloading;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/methodmatching/configuration/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/methodmatching/configuration/package-info.java
index 0e60cd7c9d..b5ec048c51 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/methodmatching/configuration/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/methodmatching/configuration/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.bci.methodmatching.configuration;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/methodmatching/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/methodmatching/package-info.java
index 990b810b45..3251036781 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/methodmatching/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/methodmatching/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.bci.methodmatching;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/package-info.java
index 81f73e06cf..1c6cddbe50 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.bci;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/cache/WeakKeySoftValueLoadingCache.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/cache/WeakKeySoftValueLoadingCache.java
index dcca43444b..206a02c201 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/cache/WeakKeySoftValueLoadingCache.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/cache/WeakKeySoftValueLoadingCache.java
@@ -24,7 +24,7 @@
*/
package co.elastic.apm.agent.cache;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/cache/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/cache/package-info.java
index a4e47e1db9..bbaaf8b6ea 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/cache/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/cache/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.cache;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapCleaner.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapCleaner.java
index 20a5bdf80e..7363c3bb16 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapCleaner.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapCleaner.java
@@ -26,6 +26,7 @@
import co.elastic.apm.agent.context.AbstractLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import co.elastic.apm.agent.util.ExecutorUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 5942b2756e..8853bffa6a 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
@@ -509,6 +509,19 @@ public class CoreConfiguration extends ConfigurationOptionProvider {
"NOTE: this option can only be set via system properties, environment variables or the attacher options.")
.buildWithDefault(DEFAULT_CONFIG_FILE);
+ private final ConfigurationOption pluginsDirLocation = ConfigurationOption.stringOption()
+ .key("plugins_dir")
+ .tags("added[1.18.0]")
+ .configurationCategory(CORE_CATEGORY)
+ .tags("internal", "experimental")
+ .description("A folder that contains external agent plugins.\n" +
+ "\n" +
+ "Use the `apm-agent-plugin-sdk` and the `apm-agent-api` artifacts to create a jar and place it into the plugins folder.\n" +
+ "The agent will load all instrumentations that are declared in the\n" +
+ "`META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation` service descriptor.\n" +
+ "See `integration-tests/external-plugin-test` for an example plugin.")
+ .build();
+
private final ConfigurationOption useElasticTraceparentHeader = ConfigurationOption.booleanOption()
.key("use_elastic_traceparent_header")
.tags("added[1.14.0]")
@@ -711,6 +724,22 @@ public static String getConfigFileLocation(List configurati
}
}
+ @Nullable
+ public String getPluginsDir() {
+ @Nullable
+ String configFileLocation = pluginsDirLocation.get();
+ if (configFileLocation != null && configFileLocation.contains(AGENT_HOME_PLACEHOLDER)) {
+ String agentHome = ElasticApmAgent.getAgentHome();
+ if (agentHome != null) {
+ return configFileLocation.replace(AGENT_HOME_PLACEHOLDER, agentHome);
+ } else {
+ return null;
+ }
+ } else {
+ return configFileLocation;
+ }
+ }
+
public enum EventType {
/**
* Request bodies will never be reported
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/converter/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/converter/package-info.java
index b1350f4817..0177b52111 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/converter/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/converter/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.configuration.converter;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/package-info.java
index 7a86339837..5971b49ca5 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.configuration;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/validation/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/validation/package-info.java
index b0f01189fb..ba70639a6c 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/validation/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/validation/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.configuration.validation;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/context/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/context/package-info.java
index 42066aa5da..46fff4a728 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/context/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/context/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.context;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
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 e6c97c90f6..8b7d8b51ed 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
@@ -24,7 +24,6 @@
*/
package co.elastic.apm.agent.impl;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.configuration.CoreConfiguration;
import co.elastic.apm.agent.configuration.ServiceNameUtil;
import co.elastic.apm.agent.context.LifecycleListener;
@@ -45,6 +44,7 @@
import co.elastic.apm.agent.report.ApmServerClient;
import co.elastic.apm.agent.report.Reporter;
import co.elastic.apm.agent.report.ReporterConfiguration;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import co.elastic.apm.agent.util.DependencyInjectingServiceLoader;
import co.elastic.apm.agent.util.ExecutorUtils;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/package-info.java
index be5eb9e761..678768ba0a 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.impl.circuitbreaker;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/package-info.java
index e9eead7c46..a3170ef917 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.impl.context;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/package-info.java
index 2f7adae7f6..67aea841c4 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.impl.error;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/package-info.java
index 183047994a..7ca483567c 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.impl;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/payload/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/payload/package-info.java
index 336fdcf515..d5666a44a5 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/payload/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/payload/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.impl.payload;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/package-info.java
index 4401b73db7..e9d36ceafb 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.impl.sampling;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/package-info.java
index af30237ce1..36784b6cbd 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.impl.stacktrace;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java
index 997e8a8fc3..dcd6e3f357 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java
@@ -24,12 +24,12 @@
*/
package co.elastic.apm.agent.impl.transaction;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.configuration.CoreConfiguration;
-import co.elastic.apm.agent.impl.Tracer;
import co.elastic.apm.agent.impl.ElasticApmTracer;
+import co.elastic.apm.agent.impl.Tracer;
import co.elastic.apm.agent.impl.sampling.Sampler;
import co.elastic.apm.agent.objectpool.Recyclable;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import co.elastic.apm.agent.util.ByteUtils;
import co.elastic.apm.agent.util.HexUtils;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/package-info.java
index 92d6a6be58..ac4eb84cef 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.impl.transaction;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/package-info.java
index e2ad4b896f..b20cc136ec 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.logging;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/matcher/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/matcher/package-info.java
index a0e609c441..3174e1df74 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/matcher/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/matcher/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.matcher;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/package-info.java
index c8fb093a4b..c860ce990f 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -30,4 +30,4 @@
@NonnullApi
package co.elastic.apm.agent.metrics.builtin;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/package-info.java
index 6b4bc23251..c2e0abc815 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.metrics;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/package-info.java
index e36010f8aa..d1dfd121f7 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.objectpool.impl;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/package-info.java
index 2244a95818..74d70b6aa4 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.objectpool;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/package-info.java
index 63223eafbd..bf53f7df76 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ApmServerHealthChecker.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ApmServerHealthChecker.java
index cff2e2942f..c756329bf2 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ApmServerHealthChecker.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ApmServerHealthChecker.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/package-info.java
index 84d9976bc1..ec14e21f75 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.report;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/processor/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/processor/package-info.java
index eda523a7ac..01d11a75c6 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/processor/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/processor/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.report.processor;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/package-info.java
index 2215f21be7..3a7f6cabea 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.report.serialize;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ssl/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ssl/package-info.java
index 1b61256334..eaf366ce49 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ssl/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ssl/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.report.ssl;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/DependencyInjectingServiceLoader.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/DependencyInjectingServiceLoader.java
index 292761c375..94c16e1c18 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/DependencyInjectingServiceLoader.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/DependencyInjectingServiceLoader.java
@@ -34,6 +34,7 @@
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashSet;
import java.util.List;
@@ -46,28 +47,30 @@ public class DependencyInjectingServiceLoader {
private final Object[] constructorArguments;
private final Class>[] constructorTypes;
private final List instances = new ArrayList<>();
- @Nullable
- private final ClassLoader classLoader;
private DependencyInjectingServiceLoader(Class clazz, Object... constructorArguments) {
+ this(clazz, Collections.singletonList(clazz.getClassLoader()), constructorArguments);
+ }
+
+ private DependencyInjectingServiceLoader(Class clazz, List classLoaders, Object... constructorArguments) {
this.clazz = clazz;
this.constructorArguments = constructorArguments;
- this.classLoader = clazz.getClassLoader();
List> types = new ArrayList<>(constructorArguments.length);
for (Object constructorArgument : constructorArguments) {
types.add(constructorArgument.getClass());
}
constructorTypes = types.toArray(new Class[]{});
try {
- final Enumeration resources = getServiceDescriptors(clazz);
- Set implementations = getImplementations(resources);
- instantiate(implementations);
+ for (ClassLoader classLoader : classLoaders) {
+ final Enumeration resources = getServiceDescriptors(classLoader, clazz);
+ instantiate(classLoader, getImplementations(resources));
+ }
} catch (IOException e) {
throw new ServiceConfigurationError(e.getMessage(), e);
}
}
- private Enumeration getServiceDescriptors(Class clazz) throws IOException {
+ private Enumeration getServiceDescriptors(@Nullable ClassLoader classLoader, Class clazz) throws IOException {
if (classLoader != null) {
return classLoader.getResources("META-INF/services/" + clazz.getName());
} else {
@@ -79,6 +82,10 @@ public static List load(Class clazz, Object... constructorArguments) {
return new DependencyInjectingServiceLoader<>(clazz, constructorArguments).instances;
}
+ public static List load(Class clazz, List classLoaders, Object... constructorArguments) {
+ return new DependencyInjectingServiceLoader<>(clazz, classLoaders, constructorArguments).instances;
+ }
+
private static boolean isComment(String serviceImplementationClassName) {
return serviceImplementationClassName.startsWith("#");
}
@@ -100,13 +107,13 @@ private Set getImplementations(Enumeration resources) throws IOExce
return implementations;
}
- private void instantiate(Set implementations) {
+ private void instantiate(ClassLoader classLoader, Set implementations) {
for (String implementation : implementations) {
- instances.add(instantiate(implementation));
+ instances.add(instantiate(classLoader, implementation));
}
}
- private T instantiate(String implementation) {
+ private T instantiate(ClassLoader classLoader, String implementation) {
try {
final Class> implementationClass = Class.forName(implementation, true, classLoader);
checkClassModifiers(implementationClass);
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/ObjectUtils.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/ObjectUtils.java
new file mode 100644
index 0000000000..e89c332a13
--- /dev/null
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/ObjectUtils.java
@@ -0,0 +1,38 @@
+/*-
+ * #%L
+ * Elastic APM Java agent
+ * %%
+ * Copyright (C) 2018 - 2020 Elastic and contributors
+ * %%
+ * 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.
+ * #L%
+ */
+package co.elastic.apm.agent.util;
+
+import javax.annotation.Nullable;
+
+public class ObjectUtils {
+
+ public static ClassLoader systemClassLoaderIfNull(@Nullable ClassLoader classLoader) {
+ return classLoader != null ? classLoader : ClassLoader.getSystemClassLoader();
+ }
+
+ public static T defaultIfNull(@Nullable T obj, T defaultIfNull) {
+ return obj != null ? obj : defaultIfNull;
+ }
+}
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/PackageScanner.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/PackageScanner.java
index 384cd6e77b..4f05ac0658 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/PackageScanner.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/PackageScanner.java
@@ -24,8 +24,6 @@
*/
package co.elastic.apm.agent.util;
-import co.elastic.apm.agent.bci.ElasticApmAgent;
-
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -49,28 +47,31 @@ public class PackageScanner {
* Returns all class names within a package and sub-packages
*
* @param basePackage the package to scan
+ * @param classLoader
* @return all class names within a package and sub-packages
* @throws IOException
* @throws URISyntaxException
*/
- public static List getClassNames(final String basePackage) throws IOException, URISyntaxException {
+ public static List getClassNames(final String basePackage, ClassLoader classLoader) throws IOException, URISyntaxException {
String baseFolderResource = basePackage.replace('.', '/');
final List classNames = new ArrayList<>();
- Enumeration resources = ElasticApmAgent.getAgentClassLoader().getResources(baseFolderResource);
+ Enumeration resources = classLoader.getResources(baseFolderResource);
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
URI uri = resource.toURI();
+ List result;
if (uri.getScheme().equals("jar")) {
// avoids FileSystemAlreadyExistsException
synchronized (PackageScanner.class) {
try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap())) {
final Path basePath = fileSystem.getPath(baseFolderResource).toAbsolutePath();
- classNames.addAll(listClassNames(basePackage, basePath));
+ result = listClassNames(basePackage, basePath);
}
}
} else {
- classNames.addAll(listClassNames(basePackage, Paths.get(uri)));
+ result = listClassNames(basePackage, Paths.get(uri));
}
+ classNames.addAll(result);
}
return classNames;
}
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/Version.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/Version.java
index bb63719549..712747bc48 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/Version.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/Version.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/package-info.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/package-info.java
index 3cda3214f4..38c0b0f7bc 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/package-info.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.util;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.DynamicTransformer b/apm-agent-core/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.DynamicTransformer
new file mode 100644
index 0000000000..6a1f1942f6
--- /dev/null
+++ b/apm-agent-core/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.DynamicTransformer
@@ -0,0 +1 @@
+co.elastic.apm.agent.bci.DynamicTransformerImpl
diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/InstrumentationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/InstrumentationTest.java
index 46934abf53..cfda9cb946 100644
--- a/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/InstrumentationTest.java
+++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/InstrumentationTest.java
@@ -25,7 +25,6 @@
package co.elastic.apm.agent.bci;
import co.elastic.apm.agent.MockTracer;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.bci.subpackage.AdviceInSubpackageInstrumentation;
import co.elastic.apm.agent.configuration.CoreConfiguration;
import co.elastic.apm.agent.configuration.SpyConfiguration;
@@ -33,7 +32,10 @@
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.matcher.WildcardMatcher;
-import co.elastic.apm.agent.util.GlobalVariables;
+import co.elastic.apm.agent.sdk.DynamicTransformer;
+import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
+import co.elastic.apm.agent.sdk.state.GlobalVariables;
import net.bytebuddy.agent.ByteBuddyAgent;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@@ -50,17 +52,24 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import org.slf4j.event.SubstituteLoggingEvent;
import org.stagemonitor.configuration.ConfigurationRegistry;
+import org.stagemonitor.util.IOUtils;
import javax.annotation.Nullable;
+import java.io.File;
+import java.io.FileOutputStream;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static net.bytebuddy.matcher.ElementMatchers.any;
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -70,6 +79,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.awaitility.Awaitility.await;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
class InstrumentationTest {
@@ -96,6 +106,20 @@ void testIntercept() {
assertThat(interceptMe()).isEqualTo("intercepted");
}
+ @Test
+ void testExternalPlugin(@TempDir File pluginsDir) throws Exception {
+ File pluginJar = new File(pluginsDir, "plugin.jar");
+ try (JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(pluginJar))) {
+ jarOutputStream.putNextEntry(new JarEntry("co/elastic/apm/agent/plugin/external/TestInstrumentation.class"));
+ jarOutputStream.write(IOUtils.readToBytes(IOUtils.getResourceAsStream("TestInstrumentation.clazz")));
+ jarOutputStream.putNextEntry(new JarEntry("META-INF/services/" + ElasticApmInstrumentation.class.getName()));
+ jarOutputStream.write("co.elastic.apm.agent.plugin.external.TestInstrumentation".getBytes(UTF_8));
+ }
+ when(coreConfig.getPluginsDir()).thenReturn(pluginsDir.getAbsolutePath());
+ ElasticApmAgent.initInstrumentation(tracer, ByteBuddyAgent.install());
+ assertThat(interceptMe()).isEqualTo("intercepted");
+ }
+
@Test
void testFieldAccess() {
init(List.of(new FieldAccessInstrumentation()));
@@ -155,7 +179,7 @@ void testDisabled() {
void testEnsureInstrumented() {
init(List.of());
assertThat(interceptMe()).isEmpty();
- ElasticApmAgent.ensureInstrumented(getClass(), List.of(TestInstrumentation.class));
+ DynamicTransformer.Accessor.get().ensureInstrumented(getClass(), List.of(TestInstrumentation.class));
assertThat(interceptMe()).isEqualTo("intercepted");
}
@@ -463,7 +487,7 @@ private String interceptMe() {
return "";
}
- public static class TestInstrumentation extends ElasticApmInstrumentation {
+ public static class TestInstrumentation extends TracerAwareInstrumentation {
@AssignTo.Return
@Advice.OnMethodExit
public static String onMethodExit() {
@@ -486,7 +510,7 @@ public Collection getInstrumentationGroupNames() {
}
}
- public static class MathInstrumentation extends ElasticApmInstrumentation {
+ public static class MathInstrumentation extends TracerAwareInstrumentation {
@AssignTo.Return
@Advice.OnMethodExit(inline = false)
public static int onMethodExit() {
@@ -509,7 +533,7 @@ public Collection getInstrumentationGroupNames() {
}
}
- public static class ExceptionInstrumentation extends ElasticApmInstrumentation {
+ public static class ExceptionInstrumentation extends TracerAwareInstrumentation {
@Advice.OnMethodExit
public static void onMethodExit() {
throw new RuntimeException("This exception should not be suppressed");
@@ -531,7 +555,7 @@ public Collection getInstrumentationGroupNames() {
}
}
- public static class SuppressExceptionInstrumentation extends ElasticApmInstrumentation {
+ public static class SuppressExceptionInstrumentation extends TracerAwareInstrumentation {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static String onMethodEnter() {
throw new RuntimeException("This exception should be suppressed");
@@ -559,7 +583,7 @@ public Collection getInstrumentationGroupNames() {
}
}
- public static class FieldAccessInstrumentation extends ElasticApmInstrumentation {
+ public static class FieldAccessInstrumentation extends TracerAwareInstrumentation {
@AssignTo.Field("privateString")
@Advice.OnMethodEnter
@@ -583,7 +607,7 @@ public Collection getInstrumentationGroupNames() {
}
}
- public static class FieldAccessArrayInstrumentation extends ElasticApmInstrumentation {
+ public static class FieldAccessArrayInstrumentation extends TracerAwareInstrumentation {
@AssignTo(fields = @AssignTo.Field(index = 0, value = "privateString"))
@Advice.OnMethodEnter
@@ -607,7 +631,7 @@ public Collection getInstrumentationGroupNames() {
}
}
- public static class AssignToArgumentInstrumentation extends ElasticApmInstrumentation {
+ public static class AssignToArgumentInstrumentation extends TracerAwareInstrumentation {
@AssignTo.Argument(0)
@Advice.OnMethodEnter
@@ -631,7 +655,7 @@ public Collection getInstrumentationGroupNames() {
}
}
- public static class AssignToArgumentsInstrumentation extends ElasticApmInstrumentation {
+ public static class AssignToArgumentsInstrumentation extends TracerAwareInstrumentation {
@AssignTo(arguments = {
@AssignTo.Argument(index = 0, value = 1),
@@ -658,7 +682,7 @@ public Collection getInstrumentationGroupNames() {
}
}
- public static class AssignToReturnArrayInstrumentation extends ElasticApmInstrumentation {
+ public static class AssignToReturnArrayInstrumentation extends TracerAwareInstrumentation {
@AssignTo(returns = @AssignTo.Return(index = 0))
@Advice.OnMethodExit(inline = false)
@@ -712,10 +736,6 @@ public Collection getInstrumentationGroupNames() {
return Collections.singletonList("test");
}
- @Override
- public boolean indyPlugin() {
- return true;
- }
}
public static class LoggerFactoryInstrumentation extends ElasticApmInstrumentation {
@@ -748,10 +768,6 @@ public Collection getInstrumentationGroupNames() {
return Collections.singletonList("test");
}
- @Override
- public boolean indyPlugin() {
- return true;
- }
}
public static class StatUtilsInstrumentation extends ElasticApmInstrumentation {
@@ -784,10 +800,6 @@ public Collection getInstrumentationGroupNames() {
return Collections.singletonList("test");
}
- @Override
- public boolean indyPlugin() {
- return true;
- }
}
public static class CallStackUtilsInstrumentation extends ElasticApmInstrumentation {
@@ -820,10 +832,6 @@ public Collection getInstrumentationGroupNames() {
return Collections.singletonList("test");
}
- @Override
- public boolean indyPlugin() {
- return true;
- }
}
public static class ClassLoadingTestInstrumentation extends ElasticApmInstrumentation {
@@ -849,10 +857,6 @@ public Collection getInstrumentationGroupNames() {
return Collections.singletonList("test");
}
- @Override
- public boolean indyPlugin() {
- return true;
- }
}
public static class InlinedIndyAdviceInstrumentation extends ElasticApmInstrumentation {
@@ -876,10 +880,6 @@ public Collection getInstrumentationGroupNames() {
return Collections.singletonList("test");
}
- @Override
- public boolean indyPlugin() {
- return true;
- }
}
public static class AgentTypeReturnInstrumentation extends ElasticApmInstrumentation {
@@ -904,10 +904,6 @@ public Collection getInstrumentationGroupNames() {
return Collections.singletonList("test");
}
- @Override
- public boolean indyPlugin() {
- return true;
- }
}
public static class AgentTypeParameterInstrumentation extends ElasticApmInstrumentation {
@@ -936,10 +932,6 @@ public Collection getInstrumentationGroupNames() {
return Collections.singletonList("test");
}
- @Override
- public boolean indyPlugin() {
- return true;
- }
}
public static class UsingThreadLocal extends TracerAwareInstrumentation {
@@ -1001,9 +993,5 @@ public Collection getInstrumentationGroupNames() {
return Collections.singletonList("test");
}
- @Override
- public boolean indyPlugin() {
- return true;
- }
}
}
diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/subpackage/AdviceInSubpackageInstrumentation.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/subpackage/AdviceInSubpackageInstrumentation.java
index 1915668a0a..5bef052270 100644
--- a/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/subpackage/AdviceInSubpackageInstrumentation.java
+++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/subpackage/AdviceInSubpackageInstrumentation.java
@@ -24,7 +24,7 @@
*/
package co.elastic.apm.agent.bci.subpackage;
-import co.elastic.apm.agent.bci.ElasticApmInstrumentation;
+import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
@@ -35,7 +35,7 @@
import static net.bytebuddy.matcher.ElementMatchers.none;
-public class AdviceInSubpackageInstrumentation extends ElasticApmInstrumentation {
+public class AdviceInSubpackageInstrumentation extends TracerAwareInstrumentation {
@Advice.OnMethodEnter(inline = false)
private static void onEnter() {
diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/collections/package-info.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/collections/package-info.java
index 26a883e3ee..b12e5c52fa 100644
--- a/apm-agent-core/src/test/java/co/elastic/apm/agent/collections/package-info.java
+++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/collections/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.collections;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/util/PackageScannerTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/util/PackageScannerTest.java
index 8cddb76b3a..6d45a397b4 100644
--- a/apm-agent-core/src/test/java/co/elastic/apm/agent/util/PackageScannerTest.java
+++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/util/PackageScannerTest.java
@@ -24,6 +24,7 @@
*/
package co.elastic.apm.agent.util;
+import co.elastic.apm.agent.bci.ElasticApmAgent;
import net.bytebuddy.ByteBuddy;
import org.junit.jupiter.api.Test;
@@ -33,21 +34,21 @@ class PackageScannerTest {
@Test
void getClassNames() throws Exception {
- assertThat(PackageScanner.getClassNames(getClass().getPackageName()))
+ assertThat(PackageScanner.getClassNames(getClass().getPackageName(), ElasticApmAgent.getAgentClassLoader()))
.contains(PackageScanner.class.getName());
}
@Test
void testScanJar() throws Exception {
- assertThat(PackageScanner.getClassNames(ByteBuddy.class.getPackageName()))
+ assertThat(PackageScanner.getClassNames(ByteBuddy.class.getPackageName(), ElasticApmAgent.getAgentClassLoader()))
.contains(ByteBuddy.class.getName());
// scan again to see verify there's no FileSystemAlreadyExistsException
- assertThat(PackageScanner.getClassNames(ByteBuddy.class.getPackageName()))
+ assertThat(PackageScanner.getClassNames(ByteBuddy.class.getPackageName(), ElasticApmAgent.getAgentClassLoader()))
.contains(ByteBuddy.class.getName());
}
@Test
void getClassNamesOfNonExistentPackage() throws Exception {
- assertThat(PackageScanner.getClassNames("foo.bar")).isEmpty();
+ assertThat(PackageScanner.getClassNames("foo.bar", ElasticApmAgent.getAgentClassLoader())).isEmpty();
}
}
diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/util/ThreadUtilsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/util/ThreadUtilsTest.java
index b68b44bdda..9e773f4408 100644
--- a/apm-agent-core/src/test/java/co/elastic/apm/agent/util/ThreadUtilsTest.java
+++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/util/ThreadUtilsTest.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/util/VersionTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/util/VersionTest.java
index 6bae8257de..4ec1d9e155 100644
--- a/apm-agent-core/src/test/java/co/elastic/apm/agent/util/VersionTest.java
+++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/util/VersionTest.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
diff --git a/apm-agent-core/src/test/resources/TestInstrumentation.clazz b/apm-agent-core/src/test/resources/TestInstrumentation.clazz
new file mode 100644
index 0000000000..7358a8c4be
Binary files /dev/null and b/apm-agent-core/src/test/resources/TestInstrumentation.clazz differ
diff --git a/apm-agent-plugin-sdk/pom.xml b/apm-agent-plugin-sdk/pom.xml
new file mode 100644
index 0000000000..26581ae1e1
--- /dev/null
+++ b/apm-agent-plugin-sdk/pom.xml
@@ -0,0 +1,43 @@
+
+
+
+ apm-agent-parent
+ co.elastic.apm
+ 1.17.1-SNAPSHOT
+
+ 4.0.0
+
+ apm-agent-plugin-sdk
+ ${project.groupId}:${project.artifactId}
+
+
+ The Apache Software License, Version 2.0
+ http://www.apache.org/licenses/LICENSE-2.0.txt
+
+
+
+
+ ${project.basedir}/..
+
+
+
+
+ org.slf4j
+ slf4j-api
+ ${version.slf4j}
+
+
+ com.blogspot.mydailyjava
+ weak-lock-free
+ 0.15
+
+
+ net.bytebuddy
+ byte-buddy-dep
+ ${version.byte-buddy}
+
+
+
+
diff --git a/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/DynamicTransformer.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/DynamicTransformer.java
new file mode 100644
index 0000000000..fd8cfe48a5
--- /dev/null
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/DynamicTransformer.java
@@ -0,0 +1,66 @@
+/*-
+ * #%L
+ * Elastic APM Java agent
+ * %%
+ * Copyright (C) 2018 - 2020 Elastic and contributors
+ * %%
+ * 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.
+ * #L%
+ */
+package co.elastic.apm.agent.sdk;
+
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+
+import java.util.Collection;
+import java.util.ServiceLoader;
+
+public interface DynamicTransformer {
+
+ /**
+ * Instruments a specific class at runtime with one or multiple instrumentation classes.
+ *
+ * Note that {@link ElasticApmInstrumentation#getTypeMatcher()} will be
+ * {@linkplain net.bytebuddy.matcher.ElementMatcher.Junction#and(ElementMatcher) conjoined} with a
+ * computed {@link ElementMatcher}{@code <}{@link TypeDescription}{@code >}
+ * that is specific to the provided class to instrument.
+ *
+ *
+ * @param classToInstrument the class which should be instrumented.
+ * @param instrumentationClasses the instrumentation which should be applied to the class to instrument.
+ */
+ void ensureInstrumented(Class> classToInstrument, Collection> instrumentationClasses);
+
+ class Accessor {
+ private static final DynamicTransformer transformer;
+
+ static {
+ ClassLoader classLoader = Accessor.class.getClassLoader();
+ if (classLoader == null) {
+ classLoader = ClassLoader.getSystemClassLoader();
+ }
+ // loads the implementation provided by the core module without depending on the class or class name
+ transformer = ServiceLoader.load(DynamicTransformer.class, classLoader).iterator().next();
+ }
+
+ public static DynamicTransformer get() {
+ return transformer;
+ }
+ }
+
+}
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmInstrumentation.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/ElasticApmInstrumentation.java
similarity index 53%
rename from apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmInstrumentation.java
rename to apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/ElasticApmInstrumentation.java
index 529e29bdc9..67ae4bb15f 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmInstrumentation.java
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/ElasticApmInstrumentation.java
@@ -22,10 +22,8 @@
* under the License.
* #L%
*/
-package co.elastic.apm.agent.bci;
+package co.elastic.apm.agent.sdk;
-import co.elastic.apm.agent.impl.transaction.Span;
-import co.elastic.apm.agent.threadlocal.GlobalThreadLocal;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.method.MethodDescription;
@@ -65,9 +63,9 @@ public ElementMatcher super NamedElement> getTypeMatcherPreFilter() {
}
/**
- * Post filters classes that pass the {@link #getTypeMatcher()} by version.
+ * Post filters classes that pass the {@link #getTypeMatcher()} by {@link ProtectionDomain}.
*/
- public ElementMatcher.Junction getImplementationVersionPostFilter() {
+ public ElementMatcher.Junction getProtectionDomainPostFilter() {
return any();
}
@@ -103,7 +101,7 @@ public Class> getAdviceClass() {
/**
* Return {@code true},
* if this instrumentation should even be applied when
- * {@link co.elastic.apm.agent.configuration.CoreConfiguration#instrument} is set to {@code false}.
+ * {@code instrument} is set to {@code false}.
*/
public boolean includeWhenInstrumentationIsDisabled() {
return false;
@@ -112,7 +110,7 @@ public boolean includeWhenInstrumentationIsDisabled() {
/**
* Returns a name which groups several instrumentations into a logical group.
*
- * This name is used in {@link co.elastic.apm.agent.configuration.CoreConfiguration#disabledInstrumentations} to exclude a logical group
+ * This name is used in {@code disabled_instrumentations} to exclude a logical group
* of instrumentations.
*
*
@@ -128,56 +126,4 @@ public Advice.OffsetMapping.Factory> getOffsetMapping() {
public void onTypeMatch(TypeDescription typeDescription, ClassLoader classLoader, ProtectionDomain protectionDomain, @Nullable Class> classBeingRedefined) {
}
- /**
- * When this method returns {@code true} the whole package (starting at the {@linkplain #getAdviceClass() advice's} package)
- * will be loaded from a plugin class loader that has both the agent class loader and the class loader of the class this instruments as
- * parents.
- *
- * This instructs Byte Buddy to dispatch to the advice methods via an {@code INVOKEDYNAMIC} instruction.
- * Upon first invocation of an instrumented method,
- * this will call {@link IndyBootstrap#bootstrap} to determine the target {@link java.lang.invoke.ConstantCallSite}.
- *
- *
- * Things to watch out for when using indy plugins:
- *
- *
- * -
- * Set {@link Advice.OnMethodEnter#inline()} and {@link Advice.OnMethodExit#inline()} to {@code false} on all advices.
- * As the {@code readOnly} flag in Byte Buddy annotations such as {@link Advice.Return#readOnly()} cannot be used with non
- * {@linkplain Advice.OnMethodEnter#inline() inlined advices},
- * use {@link co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo} and friends.
- *
- * -
- * Both the return type and the arguments of advice methods must not contain types from the agent.
- * If you'd like to return a {@link Span} from an advice, for example, return an {@link Object} instead.
- * When using an {@link Advice.Enter} argument on the {@linkplain Advice.OnMethodExit exit advice},
- * that argument also has to be of type {@link Object} and you have to cast it within the method body.
- * The reason is that the return value will become a local variable in the instrumented method.
- * Due to OSGi, those methods may not have access to agent types.
- * Another case is when the instrumented class is inside the bootstrap classloader.
- *
- * -
- * When an advice instruments classes in multiple class loaders, the plugin classes will be loaded form multiple class loaders.
- * In order to still share state across those plugin class loaders, use {@link co.elastic.apm.agent.util.GlobalVariables} or {@link GlobalState}.
- * That's necessary as static variables are scoped to the class loader they are defined in.
- *
- * -
- * Don't use {@link ThreadLocal}s as it can lead to class loader leaks.
- * Use {@link GlobalThreadLocal} instead.
- *
- * -
- * Due to the automatic plugin classloader creation that is based on package scanning,
- * plugins need be in their own uniquely named package.
- * As the package of the {@link #getAdviceClass()} is used as the root,
- * all advices have to be at the top level of the plugin.
- *
- *
- *
- * @return whether to load the classes of this plugin in dedicated plugin class loaders (one for each unique class loader)
- * and dispatch to the {@linkplain #getAdviceClass() advice} via an {@code INVOKEDYNAMIC} instruction.
- * @see IndyBootstrap
- */
- public boolean indyPlugin() {
- return false;
- }
}
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/annotation/NonnullApi.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/NonnullApi.java
similarity index 96%
rename from apm-agent-core/src/main/java/co/elastic/apm/agent/annotation/NonnullApi.java
rename to apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/NonnullApi.java
index 7fa900c775..166dbcbf03 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/annotation/NonnullApi.java
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/NonnullApi.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -22,7 +22,7 @@
* under the License.
* #L%
*/
-package co.elastic.apm.agent.annotation;
+package co.elastic.apm.agent.sdk;
import javax.annotation.Nonnull;
import javax.annotation.meta.TypeQualifierDefault;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/postprocessor/AssignTo.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/advice/AssignTo.java
similarity index 91%
rename from apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/postprocessor/AssignTo.java
rename to apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/advice/AssignTo.java
index e31b70584b..d38e3b0e3e 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/postprocessor/AssignTo.java
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/advice/AssignTo.java
@@ -22,7 +22,7 @@
* under the License.
* #L%
*/
-package co.elastic.apm.agent.bci.bytebuddy.postprocessor;
+package co.elastic.apm.agent.sdk.advice;
import net.bytebuddy.dynamic.TargetType;
import net.bytebuddy.implementation.bytecode.assign.Assigner;
@@ -36,25 +36,24 @@
* A limitation of non-{@linkplain net.bytebuddy.asm.Advice.OnMethodEnter#inline() inlined advices} is that the {@code readOnly} property
* of annotations that bind values to advice method parameters cannot be used.
*
- * Because we make heavy use of non-inlined advices for
- * {@linkplain co.elastic.apm.agent.bci.ElasticApmInstrumentation#indyPlugin() indy plugins},
- * this package provides alternative means to bind values:
+ * Because we make heavy use of non-inlined advices for indy plugins,
+ * this class and it's subclasses provide alternative means to bind values:
*
*
* -
- * {@link co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo.Argument}:
+ * {@link AssignTo.Argument}:
* Substitute of {@link net.bytebuddy.asm.Advice.Argument#readOnly()}.
*
* -
- * {@link co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo.Field}:
+ * {@link AssignTo.Field}:
* Substitute of {@link net.bytebuddy.asm.Advice.FieldValue#readOnly()}.
*
* -
- * {@link co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo.Return}:
+ * {@link AssignTo.Return}:
* Substitute of {@link net.bytebuddy.asm.Advice.Return#readOnly()}.
*
* -
- * {@link co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo}:
+ * {@link AssignTo}:
* Substitute of binding multiple values in a single method.
* Works by returning an {@code Object[]} from the advice method.
*
diff --git a/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/advice/package-info.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/advice/package-info.java
new file mode 100644
index 0000000000..2af52b9c4a
--- /dev/null
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/advice/package-info.java
@@ -0,0 +1,28 @@
+/*-
+ * #%L
+ * Elastic APM Java agent
+ * %%
+ * Copyright (C) 2018 - 2020 Elastic and contributors
+ * %%
+ * 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.
+ * #L%
+ */
+@NonnullApi
+package co.elastic.apm.agent.sdk.advice;
+
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/package-info.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/package-info.java
new file mode 100644
index 0000000000..e48fab94ea
--- /dev/null
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/package-info.java
@@ -0,0 +1,26 @@
+/*-
+ * #%L
+ * Elastic APM Java agent
+ * %%
+ * Copyright (C) 2018 - 2020 Elastic and contributors
+ * %%
+ * 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.
+ * #L%
+ */
+@NonnullApi
+package co.elastic.apm.agent.sdk;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/CallDepth.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/CallDepth.java
similarity index 99%
rename from apm-agent-core/src/main/java/co/elastic/apm/agent/util/CallDepth.java
rename to apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/CallDepth.java
index 2aa4e625d9..1af56879e8 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/CallDepth.java
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/CallDepth.java
@@ -22,7 +22,7 @@
* under the License.
* #L%
*/
-package co.elastic.apm.agent.util;
+package co.elastic.apm.agent.sdk.state;
import net.bytebuddy.asm.Advice;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/GlobalState.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/GlobalState.java
similarity index 92%
rename from apm-agent-core/src/main/java/co/elastic/apm/agent/bci/GlobalState.java
rename to apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/GlobalState.java
index 0b83f22c4f..ef1195193c 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/GlobalState.java
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/GlobalState.java
@@ -22,7 +22,7 @@
* under the License.
* #L%
*/
-package co.elastic.apm.agent.bci;
+package co.elastic.apm.agent.sdk.state;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -41,7 +41,7 @@
* The effect of that is that state added to static variables in one class loader does not affect the static variable in other class loaders.
*
*
- * An alternative to this is {@link co.elastic.apm.agent.util.GlobalVariables} which can be used to make individual variables scoped globally.
+ * An alternative to this is {@link GlobalVariables} which can be used to make individual variables scoped globally.
*
*/
@Retention(RetentionPolicy.RUNTIME)
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/threadlocal/GlobalThreadLocal.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/GlobalThreadLocal.java
similarity index 94%
rename from apm-agent-core/src/main/java/co/elastic/apm/agent/threadlocal/GlobalThreadLocal.java
rename to apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/GlobalThreadLocal.java
index 7770368ed6..2ac3960e03 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/threadlocal/GlobalThreadLocal.java
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/GlobalThreadLocal.java
@@ -22,7 +22,7 @@
* under the License.
* #L%
*/
-package co.elastic.apm.agent.threadlocal;
+package co.elastic.apm.agent.sdk.state;
import com.blogspot.mydailyjava.weaklockfree.DetachedThreadLocal;
@@ -32,7 +32,7 @@
/**
* Allows registering a globally shared instance of a {@link DetachedThreadLocal} that optionally allows for removal on get.
- * Similar to {@link co.elastic.apm.agent.util.GlobalVariables} and {@link co.elastic.apm.agent.bci.GlobalState},
+ * Similar to {@link GlobalVariables} and {@link GlobalState},
* this allows to get thread locals whose state is shared across plugin class loaders.
*
* @param
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/GlobalVariables.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/GlobalVariables.java
similarity index 88%
rename from apm-agent-core/src/main/java/co/elastic/apm/agent/util/GlobalVariables.java
rename to apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/GlobalVariables.java
index 77d8791641..42e73885af 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/GlobalVariables.java
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/GlobalVariables.java
@@ -22,11 +22,9 @@
* under the License.
* #L%
*/
-package co.elastic.apm.agent.util;
+package co.elastic.apm.agent.sdk.state;
-import co.elastic.apm.agent.impl.ElasticApmTracer;
-
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -34,7 +32,7 @@
* As the classes of an instrumentation plugins may be loaded from multiple plugin class loaders,
* there's a need to share global state between those class loaders.
*
- * An alternative to this is {@link co.elastic.apm.agent.bci.GlobalState} which can be used to make a whole class scoped globally.
+ * An alternative to this is {@link GlobalState} which can be used to make a whole class scoped globally.
*
*/
public class GlobalVariables {
@@ -51,7 +49,7 @@ public class GlobalVariables {
*/
public static T get(Class> adviceClass, String key, T defaultValue) {
key = adviceClass.getName() + "." + key;
- if (defaultValue.getClass().getClassLoader() != null && !defaultValue.getClass().getName().startsWith(ElasticApmTracer.class.getPackage().getName())) {
+ if (defaultValue.getClass().getClassLoader() != null && !defaultValue.getClass().getName().startsWith("co.elastic.apm.agent")) {
throw new IllegalArgumentException("Registering types specific to an instrumentation plugin would lead to class loader leaks: " + defaultValue);
}
T value = (T) registry.get(key);
diff --git a/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/package-info.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/package-info.java
new file mode 100644
index 0000000000..8336f65699
--- /dev/null
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/state/package-info.java
@@ -0,0 +1,28 @@
+/*-
+ * #%L
+ * Elastic APM Java agent
+ * %%
+ * Copyright (C) 2018 - 2020 Elastic and contributors
+ * %%
+ * 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.
+ * #L%
+ */
+@NonnullApi
+package co.elastic.apm.agent.sdk.state;
+
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapSupplier.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/weakmap/WeakMapSupplier.java
similarity index 95%
rename from apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapSupplier.java
rename to apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/weakmap/WeakMapSupplier.java
index f8b2e53de5..3dc6e61f77 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapSupplier.java
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/weakmap/WeakMapSupplier.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -22,7 +22,7 @@
* under the License.
* #L%
*/
-package co.elastic.apm.agent.collections;
+package co.elastic.apm.agent.sdk.weakmap;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentSet;
@@ -46,7 +46,7 @@ public static WeakConcurrentMap createMap() {
* Avoids that the maps take unnecessary space for the {@link java.util.Map.Entry}, the {@link java.lang.ref.WeakReference} and the value.
* Failing to call this does not mean the keys cannot be collected.
*/
- static void expungeStaleEntries() {
+ public static void expungeStaleEntries() {
for (WeakConcurrentMap, ?> weakMap : registeredMaps) {
weakMap.expungeStaleEntries();
}
diff --git a/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/weakmap/package-info.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/weakmap/package-info.java
new file mode 100644
index 0000000000..b489ddd72b
--- /dev/null
+++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/weakmap/package-info.java
@@ -0,0 +1,28 @@
+/*-
+ * #%L
+ * Elastic APM Java agent
+ * %%
+ * Copyright (C) 2018 - 2020 Elastic and contributors
+ * %%
+ * 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.
+ * #L%
+ */
+@NonnullApi
+package co.elastic.apm.agent.sdk.weakmap;
+
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/util/CallDepthTest.java b/apm-agent-plugin-sdk/src/test/java/co/elastic/apm/agent/sdk/state/CallDepthTest.java
similarity index 97%
rename from apm-agent-core/src/test/java/co/elastic/apm/agent/util/CallDepthTest.java
rename to apm-agent-plugin-sdk/src/test/java/co/elastic/apm/agent/sdk/state/CallDepthTest.java
index f26eb99317..2a91cc4f81 100644
--- a/apm-agent-core/src/test/java/co/elastic/apm/agent/util/CallDepthTest.java
+++ b/apm-agent-plugin-sdk/src/test/java/co/elastic/apm/agent/sdk/state/CallDepthTest.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -22,7 +22,7 @@
* under the License.
* #L%
*/
-package co.elastic.apm.agent.util;
+package co.elastic.apm.agent.sdk.state;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
diff --git a/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/ApacheHttpAsyncClientInstrumentation.java b/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/ApacheHttpAsyncClientInstrumentation.java
index dfb3b207c5..3aa4fb0549 100644
--- a/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/ApacheHttpAsyncClientInstrumentation.java
+++ b/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/ApacheHttpAsyncClientInstrumentation.java
@@ -26,13 +26,13 @@
import co.elastic.apm.agent.bci.HelperClassManager;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.http.client.HttpClientHelper;
import co.elastic.apm.agent.httpclient.helper.ApacheHttpAsyncClientHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.TextHeaderSetter;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.method.MethodDescription;
diff --git a/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/ApacheHttpAsyncClientRedirectInstrumentation.java b/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/ApacheHttpAsyncClientRedirectInstrumentation.java
index 469bfc504d..94f9dcdc74 100644
--- a/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/ApacheHttpAsyncClientRedirectInstrumentation.java
+++ b/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/ApacheHttpAsyncClientRedirectInstrumentation.java
@@ -91,7 +91,7 @@ public ElementMatcher super TypeDescription> getTypeMatcher() {
* @return a matcher for LTE 4.3.2
*/
@Override
- public ElementMatcher.Junction getImplementationVersionPostFilter() {
+ public ElementMatcher.Junction getProtectionDomainPostFilter() {
return implementationVersionLte("4.3.2");
}
diff --git a/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/helper/package-info.java b/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/helper/package-info.java
index 32121d9716..90d43c2d10 100644
--- a/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/helper/package-info.java
+++ b/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/helper/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.httpclient.helper;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/package-info.java b/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/package-info.java
index 60a04e3091..0185d5ebdc 100644
--- a/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/package-info.java
+++ b/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.httpclient;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-apache-httpclient-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-apache-httpclient-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-apache-httpclient-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/AbstractSpanInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/AbstractSpanInstrumentation.java
index 0a8c4c543e..e9efdde0f0 100644
--- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/AbstractSpanInstrumentation.java
+++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/AbstractSpanInstrumentation.java
@@ -25,10 +25,10 @@
package co.elastic.apm.agent.plugin.api;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.Transaction;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/ElasticApmApiInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/ElasticApmApiInstrumentation.java
index 016d6beb4e..e54e51fd24 100644
--- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/ElasticApmApiInstrumentation.java
+++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/ElasticApmApiInstrumentation.java
@@ -25,8 +25,8 @@
package co.elastic.apm.agent.plugin.api;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.transaction.Transaction;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/LegacySpanInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/LegacySpanInstrumentation.java
index 821228e5cd..e9da34e2b6 100644
--- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/LegacySpanInstrumentation.java
+++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/LegacySpanInstrumentation.java
@@ -25,9 +25,9 @@
package co.elastic.apm.agent.plugin.api;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/TransactionInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/TransactionInstrumentation.java
index 935a0db712..9272fd8c3d 100644
--- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/TransactionInstrumentation.java
+++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/TransactionInstrumentation.java
@@ -25,9 +25,9 @@
package co.elastic.apm.agent.plugin.api;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.transaction.TraceContext;
import co.elastic.apm.agent.impl.transaction.Transaction;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/package-info.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/package-info.java
index c9832c5fa8..e409e50503 100644
--- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/package-info.java
+++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/plugin/api/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.plugin.api;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-api-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-api-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-api-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-api-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/AbstractAsyncHttpClientInstrumentation.java b/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/AbstractAsyncHttpClientInstrumentation.java
index df17719533..cd21987085 100644
--- a/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/AbstractAsyncHttpClientInstrumentation.java
+++ b/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/AbstractAsyncHttpClientInstrumentation.java
@@ -24,17 +24,17 @@
*/
package co.elastic.apm.agent.asynchttpclient;
-import co.elastic.apm.agent.bci.ElasticApmAgent;
-import co.elastic.apm.agent.bci.ElasticApmInstrumentation;
import co.elastic.apm.agent.bci.HelperClassManager;
import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.http.client.HttpClientHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.TextHeaderSetter;
+import co.elastic.apm.agent.sdk.DynamicTransformer;
+import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@@ -112,7 +112,7 @@ private static void onBeforeExecute(@Advice.Argument(value = 0) Request request,
if (parent == null) {
return;
}
- ElasticApmAgent.ensureInstrumented(asyncHandler.getClass(), ASYNC_HANDLER_INSTRUMENTATIONS);
+ DynamicTransformer.Accessor.get().ensureInstrumented(asyncHandler.getClass(), ASYNC_HANDLER_INSTRUMENTATIONS);
Uri uri = request.getUri();
span = HttpClientHelper.startHttpClientSpan(parent, request.getMethod(), uri.toUrl(), uri.getScheme(), uri.getHost(), uri.getPort());
@@ -166,7 +166,7 @@ protected AbstractAsyncHandlerInstrumentation(ElasticApmTracer tracer, ElementMa
}
/**
- * Overridden in {@link ElasticApmAgent#ensureInstrumented(Class, Collection)},
+ * Overridden in {@link DynamicTransformer#ensureInstrumented(Class, Collection)},
* based on the type of the {@linkplain AsyncHandler} implementation class.
*/
@Override
diff --git a/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/helper/package-info.java b/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/helper/package-info.java
index 8b7696b059..26a01cb598 100644
--- a/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/helper/package-info.java
+++ b/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/helper/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.asynchttpclient.helper;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/package-info.java b/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/package-info.java
index ca19e9ca1b..c386f08c4f 100644
--- a/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/package-info.java
+++ b/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.asynchttpclient;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-asynchttpclient-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-asynchttpclient-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-bootdelegation-plugin/src/main/java/co/elastic/apm/agent/bootdelegation/BootstrapDelegationClassLoaderInstrumentation.java b/apm-agent-plugins/apm-bootdelegation-plugin/src/main/java/co/elastic/apm/agent/bootdelegation/BootstrapDelegationClassLoaderInstrumentation.java
index 14a6442452..3adce861bb 100644
--- a/apm-agent-plugins/apm-bootdelegation-plugin/src/main/java/co/elastic/apm/agent/bootdelegation/BootstrapDelegationClassLoaderInstrumentation.java
+++ b/apm-agent-plugins/apm-bootdelegation-plugin/src/main/java/co/elastic/apm/agent/bootdelegation/BootstrapDelegationClassLoaderInstrumentation.java
@@ -24,7 +24,7 @@
*/
package co.elastic.apm.agent.bootdelegation;
-import co.elastic.apm.agent.bci.ElasticApmInstrumentation;
+import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.method.MethodDescription;
@@ -64,7 +64,7 @@
* under Apache License 2.0
*
*/
-public class BootstrapDelegationClassLoaderInstrumentation extends ElasticApmInstrumentation {
+public class BootstrapDelegationClassLoaderInstrumentation extends TracerAwareInstrumentation {
@Override
public ElementMatcher super NamedElement> getTypeMatcherPreFilter() {
diff --git a/apm-agent-plugins/apm-bootdelegation-plugin/src/main/java/co/elastic/apm/agent/bootdelegation/package-info.java b/apm-agent-plugins/apm-bootdelegation-plugin/src/main/java/co/elastic/apm/agent/bootdelegation/package-info.java
index 8183ab901a..3894fc6df0 100644
--- a/apm-agent-plugins/apm-bootdelegation-plugin/src/main/java/co/elastic/apm/agent/bootdelegation/package-info.java
+++ b/apm-agent-plugins/apm-bootdelegation-plugin/src/main/java/co/elastic/apm/agent/bootdelegation/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.bootdelegation;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-bootdelegation-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-bootdelegation-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-bootdelegation-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-bootdelegation-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaResponseFutureInstrumentation.java b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaResponseFutureInstrumentation.java
index b0607ce50b..86fc794897 100644
--- a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaResponseFutureInstrumentation.java
+++ b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaResponseFutureInstrumentation.java
@@ -24,11 +24,11 @@
*/
package co.elastic.apm.agent.dubbo;
-import co.elastic.apm.agent.bci.ElasticApmAgent;
-import co.elastic.apm.agent.bci.ElasticApmInstrumentation;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
+import co.elastic.apm.agent.sdk.DynamicTransformer;
+import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import com.alibaba.dubbo.remoting.exchange.ResponseCallback;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import net.bytebuddy.asm.Advice;
@@ -79,7 +79,7 @@ private static void onEnter(@Advice.Argument(value = 0, readOnly = false) Respon
return;
}
callbackSpanMap.put(callback, active);
- ElasticApmAgent.ensureInstrumented(callback.getClass(), RESPONSE_CALLBACK_INSTRUMENTATIONS);
+ DynamicTransformer.Accessor.get().ensureInstrumented(callback.getClass(), RESPONSE_CALLBACK_INSTRUMENTATIONS);
}
}
}
diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaRpcContextInstrumentation.java b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaRpcContextInstrumentation.java
index 139e6032e4..e28d0f4c4f 100644
--- a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaRpcContextInstrumentation.java
+++ b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaRpcContextInstrumentation.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -24,9 +24,9 @@
*/
package co.elastic.apm.agent.dubbo;
-import co.elastic.apm.agent.bci.ElasticApmAgent;
-import co.elastic.apm.agent.bci.ElasticApmInstrumentation;
import co.elastic.apm.agent.bci.VisibleForAdvice;
+import co.elastic.apm.agent.sdk.DynamicTransformer;
+import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
import com.alibaba.dubbo.rpc.RpcContext;
import com.alibaba.dubbo.rpc.protocol.dubbo.FutureAdapter;
import net.bytebuddy.asm.Advice;
@@ -63,7 +63,7 @@ public ElementMatcher super MethodDescription> getMethodMatcher() {
@Advice.OnMethodEnter(suppress = Throwable.class)
private static void onEnter(@Advice.Argument(0) Future> future) {
if (future instanceof FutureAdapter) {
- ElasticApmAgent.ensureInstrumented(((FutureAdapter>) future).getFuture().getClass(), RESPONSE_FUTURE_INSTRUMENTATION);
+ DynamicTransformer.Accessor.get().ensureInstrumented(((FutureAdapter>) future).getFuture().getClass(), RESPONSE_FUTURE_INSTRUMENTATION);
}
}
}
diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/package-info.java b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/package-info.java
index 62fc20ec89..0585013fe3 100644
--- a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/package-info.java
+++ b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.dubbo.advice;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/package-info.java b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/package-info.java
index 8fc7c7d63f..2515ad340c 100644
--- a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/package-info.java
+++ b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.dubbo.helper;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/package-info.java b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/package-info.java
index f0f2c0ff5f..ad2af535e7 100644
--- a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/package-info.java
+++ b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.dubbo;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-dubbo-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-dubbo-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-dubbo-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-error-logging-plugin/src/main/java/co/elastic/apm/agent/error/logging/package-info.java b/apm-agent-plugins/apm-error-logging-plugin/src/main/java/co/elastic/apm/agent/error/logging/package-info.java
index 9362b0ac5a..c82b883843 100644
--- a/apm-agent-plugins/apm-error-logging-plugin/src/main/java/co/elastic/apm/agent/error/logging/package-info.java
+++ b/apm-agent-plugins/apm-error-logging-plugin/src/main/java/co/elastic/apm/agent/error/logging/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.error.logging;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-error-logging-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-error-logging-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-error-logging-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-error-logging-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/es/restclient/v5_6/ElasticsearchClientAsyncInstrumentation.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/es/restclient/v5_6/ElasticsearchClientAsyncInstrumentation.java
index cf0d380555..fc26aa250a 100644
--- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/es/restclient/v5_6/ElasticsearchClientAsyncInstrumentation.java
+++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/es/restclient/v5_6/ElasticsearchClientAsyncInstrumentation.java
@@ -25,12 +25,12 @@
package co.elastic.apm.agent.es.restclient.v5_6;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentation;
import co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentationHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.transaction.Span;
-import co.elastic.apm.agent.threadlocal.GlobalThreadLocal;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
+import co.elastic.apm.agent.sdk.state.GlobalThreadLocal;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/es/restclient/v5_6/package-info.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/es/restclient/v5_6/package-info.java
index eecc902dd9..b3b59c752c 100644
--- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/es/restclient/v5_6/package-info.java
+++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/es/restclient/v5_6/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.es.restclient.v5_6;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/es/restclient/v6_4/ElasticsearchClientAsyncInstrumentation.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/es/restclient/v6_4/ElasticsearchClientAsyncInstrumentation.java
index 6627006865..d123b172f0 100644
--- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/es/restclient/v6_4/ElasticsearchClientAsyncInstrumentation.java
+++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/es/restclient/v6_4/ElasticsearchClientAsyncInstrumentation.java
@@ -25,12 +25,12 @@
package co.elastic.apm.agent.es.restclient.v6_4;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentation;
import co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentationHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.transaction.Span;
-import co.elastic.apm.agent.threadlocal.GlobalThreadLocal;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
+import co.elastic.apm.agent.sdk.state.GlobalThreadLocal;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/es/restclient/v6_4/package-info.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/es/restclient/v6_4/package-info.java
index 913a38ccae..8fab03706c 100644
--- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/es/restclient/v6_4/package-info.java
+++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/es/restclient/v6_4/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.es.restclient.v6_4;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/es/restclient/package-info.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/es/restclient/package-info.java
index 8b4ed24ee4..4b2c3e7f3d 100644
--- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/es/restclient/package-info.java
+++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/es/restclient/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.es.restclient;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-grails-plugin/src/main/java/co/elastic/apm/agent/grails/package-info.java b/apm-agent-plugins/apm-grails-plugin/src/main/java/co/elastic/apm/agent/grails/package-info.java
index 54d11ebbaa..5f6d11aa30 100644
--- a/apm-agent-plugins/apm-grails-plugin/src/main/java/co/elastic/apm/agent/grails/package-info.java
+++ b/apm-agent-plugins/apm-grails-plugin/src/main/java/co/elastic/apm/agent/grails/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.grails;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-grails-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-grails-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-grails-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-grails-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ClientCallImplInstrumentation.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ClientCallImplInstrumentation.java
index 700a88b6b7..15fc20f4b8 100644
--- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ClientCallImplInstrumentation.java
+++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ClientCallImplInstrumentation.java
@@ -24,12 +24,12 @@
*/
package co.elastic.apm.agent.grpc;
-import co.elastic.apm.agent.bci.ElasticApmAgent;
-import co.elastic.apm.agent.bci.ElasticApmInstrumentation;
import co.elastic.apm.agent.bci.VisibleForAdvice;
import co.elastic.apm.agent.grpc.helper.GrpcHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.transaction.Span;
+import co.elastic.apm.agent.sdk.DynamicTransformer;
+import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
import io.grpc.ClientCall;
import io.grpc.Metadata;
import io.grpc.Status;
@@ -110,7 +110,7 @@ private static void onEnter(@Advice.This ClientCall, ?> clientCall,
return;
}
- ElasticApmAgent.ensureInstrumented(listener.getClass(), RESPONSE_LISTENER_INSTRUMENTATIONS);
+ DynamicTransformer.Accessor.get().ensureInstrumented(listener.getClass(), RESPONSE_LISTENER_INSTRUMENTATIONS);
GrpcHelper helper = grpcHelperManager.getForClassLoaderOfClass(ClientCall.class);
if (helper != null) {
@@ -144,7 +144,7 @@ protected ListenerInstrumentation(ElasticApmTracer tracer) {
}
/**
- * Overridden in {@link ElasticApmAgent#ensureInstrumented(Class, Collection)},
+ * Overridden in {@link DynamicTransformer#ensureInstrumented(Class, Collection)},
* based on the type of the {@linkplain ClientCall.Listener} implementation class.
*/
@Override
diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/helper/GrpcHelperImpl.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/helper/GrpcHelperImpl.java
index 8110a60574..9c90a220bc 100644
--- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/helper/GrpcHelperImpl.java
+++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/helper/GrpcHelperImpl.java
@@ -24,7 +24,6 @@
*/
package co.elastic.apm.agent.grpc.helper;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.impl.Tracer;
import co.elastic.apm.agent.impl.context.Destination;
import co.elastic.apm.agent.impl.transaction.AbstractHeaderGetter;
@@ -33,6 +32,7 @@
import co.elastic.apm.agent.impl.transaction.TextHeaderGetter;
import co.elastic.apm.agent.impl.transaction.TextHeaderSetter;
import co.elastic.apm.agent.impl.transaction.Transaction;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import io.grpc.ClientCall;
import io.grpc.Metadata;
diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/helper/package-info.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/helper/package-info.java
index 4aed0e6f86..b1a02f9282 100644
--- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/helper/package-info.java
+++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/helper/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.grpc.helper;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/package-info.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/package-info.java
index 2f468e073d..8341a49800 100644
--- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/package-info.java
+++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.grpc;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-5_x/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-5_x/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-5_x/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-5_x/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-6_x/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-6_x/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-6_x/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-6_x/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/ExecutorInstrumentation.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/ExecutorInstrumentation.java
index 8467f32550..44463c1e88 100644
--- a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/ExecutorInstrumentation.java
+++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/ExecutorInstrumentation.java
@@ -25,8 +25,8 @@
package co.elastic.apm.agent.concurrent;
import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
-import co.elastic.apm.agent.util.GlobalVariables;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
+import co.elastic.apm.agent.sdk.state.GlobalVariables;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.method.MethodDescription;
diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/JavaConcurrent.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/JavaConcurrent.java
index 4ed27f92ce..652944821f 100644
--- a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/JavaConcurrent.java
+++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/JavaConcurrent.java
@@ -24,11 +24,11 @@
*/
package co.elastic.apm.agent.concurrent;
-import co.elastic.apm.agent.bci.ElasticApmAgent;
-import co.elastic.apm.agent.bci.ElasticApmInstrumentation;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.impl.Tracer;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
+import co.elastic.apm.agent.sdk.DynamicTransformer;
+import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import javax.annotation.Nullable;
@@ -92,7 +92,7 @@ public static Runnable withContext(@Nullable Runnable runnable, Tracer tracer) {
}
private static void captureContext(Object task, AbstractSpan> active) {
- ElasticApmAgent.ensureInstrumented(task.getClass(), RUNNABLE_CALLABLE_FJTASK_INSTRUMENTATION);
+ DynamicTransformer.Accessor.get().ensureInstrumented(task.getClass(), RUNNABLE_CALLABLE_FJTASK_INSTRUMENTATION);
contextMap.put(task, active);
active.incrementReferences();
// Do no discard branches leading to async operations so not to break span references
diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/RunnableCallableForkJoinTaskInstrumentation.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/RunnableCallableForkJoinTaskInstrumentation.java
index a9f2cbaf81..f813a9ac0e 100644
--- a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/RunnableCallableForkJoinTaskInstrumentation.java
+++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/RunnableCallableForkJoinTaskInstrumentation.java
@@ -26,6 +26,7 @@
import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
+import co.elastic.apm.agent.sdk.DynamicTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
@@ -45,7 +46,7 @@
/**
* Used only within {@link JavaConcurrent#withContext} to
- * {@linkplain co.elastic.apm.agent.bci.ElasticApmAgent#ensureInstrumented(Class, Collection) ensure}
+ * {@linkplain DynamicTransformer#ensureInstrumented(Class, Collection) ensure}
* that particular {@link Callable}, {@link Runnable} and {@link ForkJoinTask} classes are instrumented.
*/
public class RunnableCallableForkJoinTaskInstrumentation extends TracerAwareInstrumentation {
diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/package-info.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/package-info.java
index d4a49acc05..2c77e3845e 100644
--- a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/package-info.java
+++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/package-info.java
@@ -29,4 +29,4 @@
@NonnullApi
package co.elastic.apm.agent.concurrent;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-java-concurrent-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-java-concurrent-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/package-info.java b/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/package-info.java
index 9e3d7dd4d1..0fb8460e0c 100644
--- a/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/package-info.java
+++ b/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.jaxrs;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-jaxrs-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-jaxrs-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-jaxrs-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-jaxrs-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/package-info.java b/apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/package-info.java
index 4b671f6406..cd825f4ecf 100644
--- a/apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/package-info.java
+++ b/apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.jaxws;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-jaxws-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-jaxws-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-jaxws-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-jaxws-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcGlobalState.java b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcGlobalState.java
index d69862d618..de43521549 100644
--- a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcGlobalState.java
+++ b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcGlobalState.java
@@ -24,8 +24,8 @@
*/
package co.elastic.apm.agent.jdbc.helper;
-import co.elastic.apm.agent.bci.GlobalState;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
+import co.elastic.apm.agent.sdk.state.GlobalState;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import java.sql.Connection;
diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcHelper.java b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcHelper.java
index 1c02dcd6a5..d50e39c3a3 100644
--- a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcHelper.java
+++ b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcHelper.java
@@ -25,7 +25,6 @@
package co.elastic.apm.agent.jdbc.helper;
import co.elastic.apm.agent.impl.context.Destination;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.jdbc.signature.SignatureParser;
diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/package-info.java b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/package-info.java
index ccf8188386..7b52add3e9 100644
--- a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/package-info.java
+++ b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.jdbc.helper;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/package-info.java b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/package-info.java
index 3e612faef9..79355a26f2 100644
--- a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/package-info.java
+++ b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/package-info.java
@@ -30,4 +30,4 @@
@NonnullApi
package co.elastic.apm.agent.jdbc;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/signature/package-info.java b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/signature/package-info.java
index 0eec86eed5..9a6ced3a21 100644
--- a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/signature/package-info.java
+++ b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/signature/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.jdbc.signature;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-jdbc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-jdbc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-jdbc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-jms-plugin/src/main/java/co/elastic/apm/agent/jms/JmsMessageConsumerInstrumentation.java b/apm-agent-plugins/apm-jms-plugin/src/main/java/co/elastic/apm/agent/jms/JmsMessageConsumerInstrumentation.java
index 2f88c8f7a2..7f2d133761 100644
--- a/apm-agent-plugins/apm-jms-plugin/src/main/java/co/elastic/apm/agent/jms/JmsMessageConsumerInstrumentation.java
+++ b/apm-agent-plugins/apm-jms-plugin/src/main/java/co/elastic/apm/agent/jms/JmsMessageConsumerInstrumentation.java
@@ -25,12 +25,12 @@
package co.elastic.apm.agent.jms;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.configuration.MessagingConfiguration;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.Transaction;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.method.MethodDescription;
diff --git a/apm-agent-plugins/apm-jms-plugin/src/main/java/co/elastic/apm/agent/jms/package-info.java b/apm-agent-plugins/apm-jms-plugin/src/main/java/co/elastic/apm/agent/jms/package-info.java
index 338c392885..4352b57b2c 100644
--- a/apm-agent-plugins/apm-jms-plugin/src/main/java/co/elastic/apm/agent/jms/package-info.java
+++ b/apm-agent-plugins/apm-jms-plugin/src/main/java/co/elastic/apm/agent/jms/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -52,4 +52,4 @@
@NonnullApi
package co.elastic.apm.agent.jms;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-jms-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-jms-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-jms-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-jms-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/package-info.java b/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/package-info.java
index 7741c8d2b0..c4d5eca635 100644
--- a/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/package-info.java
+++ b/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.jmx;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/package-info.java b/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/package-info.java
index d5350f2167..f1519f0858 100644
--- a/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/package-info.java
+++ b/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.jsf;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-jsf-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-jsf-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-jsf-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-jsf-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaProducerInstrumentation.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaProducerInstrumentation.java
index d01f3bfcbf..6473064031 100644
--- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaProducerInstrumentation.java
+++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaProducerInstrumentation.java
@@ -24,10 +24,10 @@
*/
package co.elastic.apm.agent.kafka;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.kafka.helper.KafkaInstrumentationHelper;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
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/package-info.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/package-info.java
index 9658adcb20..de127f0929 100644
--- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/package-info.java
+++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.kafka.helper;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/package-info.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/package-info.java
index 0c75dcfe68..850a402d6c 100644
--- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/package-info.java
+++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -49,4 +49,4 @@
@NonnullApi
package co.elastic.apm.agent.kafka;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/ConsumerRecordsIteratorInstrumentation.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/ConsumerRecordsIteratorInstrumentation.java
index dbeee66996..2a05981783 100644
--- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/ConsumerRecordsIteratorInstrumentation.java
+++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/ConsumerRecordsIteratorInstrumentation.java
@@ -24,9 +24,9 @@
*/
package co.elastic.apm.agent.kafka;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.kafka.helper.KafkaInstrumentationHeadersHelper;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/ConsumerRecordsRecordListInstrumentation.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/ConsumerRecordsRecordListInstrumentation.java
index 899eeae21b..68e9b1fb47 100644
--- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/ConsumerRecordsRecordListInstrumentation.java
+++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/ConsumerRecordsRecordListInstrumentation.java
@@ -24,9 +24,9 @@
*/
package co.elastic.apm.agent.kafka;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.kafka.helper.KafkaInstrumentationHeadersHelper;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/ConsumerRecordsRecordsInstrumentation.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/ConsumerRecordsRecordsInstrumentation.java
index c32a026ecd..eeec578541 100644
--- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/ConsumerRecordsRecordsInstrumentation.java
+++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/ConsumerRecordsRecordsInstrumentation.java
@@ -24,9 +24,9 @@
*/
package co.elastic.apm.agent.kafka;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.kafka.helper.KafkaInstrumentationHeadersHelper;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-log-correlation-plugin/src/main/java/co/elastic/apm/agent/mdc/package-info.java b/apm-agent-plugins/apm-log-correlation-plugin/src/main/java/co/elastic/apm/agent/mdc/package-info.java
index bf125f9cbd..c3957db99e 100644
--- a/apm-agent-plugins/apm-log-correlation-plugin/src/main/java/co/elastic/apm/agent/mdc/package-info.java
+++ b/apm-agent-plugins/apm-log-correlation-plugin/src/main/java/co/elastic/apm/agent/mdc/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.mdc;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-log-shipper-plugin/src/main/java/co/elastic/apm/agent/log/shipper/package-info.java b/apm-agent-plugins/apm-log-shipper-plugin/src/main/java/co/elastic/apm/agent/log/shipper/package-info.java
index d2da1d6633..8d39b34fca 100644
--- a/apm-agent-plugins/apm-log-shipper-plugin/src/main/java/co/elastic/apm/agent/log/shipper/package-info.java
+++ b/apm-agent-plugins/apm-log-shipper-plugin/src/main/java/co/elastic/apm/agent/log/shipper/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.log.shipper;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-mongoclient-plugin/src/main/java/co/elastic/apm/agent/mongoclient/package-info.java b/apm-agent-plugins/apm-mongoclient-plugin/src/main/java/co/elastic/apm/agent/mongoclient/package-info.java
index cad07e0adf..d54f671e6e 100644
--- a/apm-agent-plugins/apm-mongoclient-plugin/src/main/java/co/elastic/apm/agent/mongoclient/package-info.java
+++ b/apm-agent-plugins/apm-mongoclient-plugin/src/main/java/co/elastic/apm/agent/mongoclient/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.mongoclient;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-mongoclient-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-mongoclient-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-mongoclient-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-mongoclient-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientAsyncInstrumentation.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientAsyncInstrumentation.java
index 77a458f2a5..0815567d33 100644
--- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientAsyncInstrumentation.java
+++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientAsyncInstrumentation.java
@@ -26,12 +26,12 @@
import co.elastic.apm.agent.bci.HelperClassManager;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.http.client.HttpClientHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.TextHeaderSetter;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientInstrumentation.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientInstrumentation.java
index f2fca7f7ab..ae4ac0efc3 100644
--- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientInstrumentation.java
+++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientInstrumentation.java
@@ -25,13 +25,13 @@
package co.elastic.apm.agent.okhttp;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.http.client.HttpClientHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.TextHeaderSetter;
-import co.elastic.apm.agent.threadlocal.GlobalThreadLocal;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
+import co.elastic.apm.agent.sdk.state.GlobalThreadLocal;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientAsyncInstrumentation.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientAsyncInstrumentation.java
index 8f162e02fa..d092e73f64 100644
--- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientAsyncInstrumentation.java
+++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientAsyncInstrumentation.java
@@ -26,12 +26,12 @@
import co.elastic.apm.agent.bci.HelperClassManager;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.http.client.HttpClientHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.TextHeaderSetter;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.Request;
diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientInstrumentation.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientInstrumentation.java
index 81e5467605..de5919a8c1 100644
--- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientInstrumentation.java
+++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientInstrumentation.java
@@ -25,13 +25,13 @@
package co.elastic.apm.agent.okhttp;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.http.client.HttpClientHelper;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.TextHeaderSetter;
-import co.elastic.apm.agent.threadlocal.GlobalThreadLocal;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
+import co.elastic.apm.agent.sdk.state.GlobalThreadLocal;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.Request;
import net.bytebuddy.asm.Advice;
diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/package-info.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/package-info.java
index af2bfbd326..bf85592189 100644
--- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/package-info.java
+++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.okhttp;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-okhttp-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-okhttp-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-okhttp-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ApmSpanBuilderInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ApmSpanBuilderInstrumentation.java
index 911458a15e..7482306b96 100644
--- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ApmSpanBuilderInstrumentation.java
+++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ApmSpanBuilderInstrumentation.java
@@ -25,7 +25,6 @@
package co.elastic.apm.agent.opentracing.impl;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.GlobalTracer;
import co.elastic.apm.agent.impl.sampling.ConstantSampler;
@@ -33,6 +32,7 @@
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.TraceContext;
import co.elastic.apm.agent.impl.transaction.Transaction;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ApmSpanInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ApmSpanInstrumentation.java
index 6c36d78e59..3c5ccf4134 100644
--- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ApmSpanInstrumentation.java
+++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ApmSpanInstrumentation.java
@@ -25,11 +25,11 @@
package co.elastic.apm.agent.opentracing.impl;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.context.web.ResultUtil;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.Transaction;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ExternalSpanContextInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ExternalSpanContextInstrumentation.java
index 031533e416..ee33c323e4 100644
--- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ExternalSpanContextInstrumentation.java
+++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ExternalSpanContextInstrumentation.java
@@ -25,10 +25,10 @@
package co.elastic.apm.agent.opentracing.impl;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.impl.GlobalTracer;
import co.elastic.apm.agent.impl.transaction.TraceContext;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ScopeManagerInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ScopeManagerInstrumentation.java
index ce8af3419f..576e56bcda 100644
--- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ScopeManagerInstrumentation.java
+++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/ScopeManagerInstrumentation.java
@@ -25,9 +25,8 @@
package co.elastic.apm.agent.opentracing.impl;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
-import co.elastic.apm.agent.impl.GlobalTracer;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/SpanContextInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/SpanContextInstrumentation.java
index c767909f58..00c880b5ac 100644
--- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/SpanContextInstrumentation.java
+++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/SpanContextInstrumentation.java
@@ -25,8 +25,8 @@
package co.elastic.apm.agent.opentracing.impl;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/package-info.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/package-info.java
index 539bb572bc..98782e58a2 100644
--- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/package-info.java
+++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracing/impl/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -29,4 +29,4 @@
@NonnullApi
package co.elastic.apm.agent.opentracing.impl;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-opentracing-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-opentracing-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-opentracing-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/CommonsExecAsyncInstrumentation.java b/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/CommonsExecAsyncInstrumentation.java
index 3c0f4d39ca..898874c95b 100644
--- a/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/CommonsExecAsyncInstrumentation.java
+++ b/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/CommonsExecAsyncInstrumentation.java
@@ -25,8 +25,8 @@
package co.elastic.apm.agent.process;
import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.concurrent.JavaConcurrent;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.method.MethodDescription;
diff --git a/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessHelper.java b/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessHelper.java
index 042cd40023..513ad3e7c0 100644
--- a/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessHelper.java
+++ b/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessHelper.java
@@ -24,9 +24,9 @@
*/
package co.elastic.apm.agent.process;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.impl.transaction.AbstractSpan;
import co.elastic.apm.agent.impl.transaction.Span;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import javax.annotation.Nonnull;
diff --git a/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/package-info.java b/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/package-info.java
index 1191c4d06c..405320e72e 100644
--- a/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/package-info.java
+++ b/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.process;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-process-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-process-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-process-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-process-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-process-plugin/src/test/java/co/elastic/apm/agent/process/ProcessHelperTest.java b/apm-agent-plugins/apm-process-plugin/src/test/java/co/elastic/apm/agent/process/ProcessHelperTest.java
index cb6e5c6aa1..741aff8fc4 100644
--- a/apm-agent-plugins/apm-process-plugin/src/test/java/co/elastic/apm/agent/process/ProcessHelperTest.java
+++ b/apm-agent-plugins/apm-process-plugin/src/test/java/co/elastic/apm/agent/process/ProcessHelperTest.java
@@ -26,7 +26,6 @@
import co.elastic.apm.agent.AbstractInstrumentationTest;
import co.elastic.apm.agent.TransactionUtils;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.Transaction;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
@@ -34,7 +33,6 @@
import org.junit.jupiter.api.Test;
import javax.annotation.Nullable;
-
import java.nio.file.Paths;
import static org.assertj.core.api.Assertions.assertThat;
diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/package-info.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/package-info.java
index afdd5b5aa8..98052a7e7b 100644
--- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/package-info.java
+++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.profiler.asyncprofiler;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/package-info.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/package-info.java
index 243290a916..25f87d5e19 100644
--- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/package-info.java
+++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.profiler;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-quartz-job-plugin/src/main/java/co/elastic/apm/agent/quartz/job/package-info.java b/apm-agent-plugins/apm-quartz-job-plugin/src/main/java/co/elastic/apm/agent/quartz/job/package-info.java
index e822269822..e31e96dd97 100644
--- a/apm-agent-plugins/apm-quartz-job-plugin/src/main/java/co/elastic/apm/agent/quartz/job/package-info.java
+++ b/apm-agent-plugins/apm-quartz-job-plugin/src/main/java/co/elastic/apm/agent/quartz/job/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.quartz.job;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-quartz-job-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-quartz-job-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-quartz-job-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-quartz-job-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/src/main/java/co/elastic/apm/agent/redis/jedis/package-info.java b/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/src/main/java/co/elastic/apm/agent/redis/jedis/package-info.java
index 0507641c94..60e912b721 100644
--- a/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/src/main/java/co/elastic/apm/agent/redis/jedis/package-info.java
+++ b/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/src/main/java/co/elastic/apm/agent/redis/jedis/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.redis.jedis;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/redis/lettuce/Lettuce34Instrumentation.java b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/redis/lettuce/Lettuce34Instrumentation.java
index 750900dbd1..57d59061d5 100644
--- a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/redis/lettuce/Lettuce34Instrumentation.java
+++ b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/redis/lettuce/Lettuce34Instrumentation.java
@@ -26,8 +26,8 @@
import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.impl.transaction.Span;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import com.lambdaworks.redis.protocol.RedisCommand;
import net.bytebuddy.matcher.ElementMatcher;
diff --git a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/redis/lettuce/Lettuce5StartSpanInstrumentation.java b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/redis/lettuce/Lettuce5StartSpanInstrumentation.java
index d7a5417674..e797bd7eeb 100644
--- a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/redis/lettuce/Lettuce5StartSpanInstrumentation.java
+++ b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/redis/lettuce/Lettuce5StartSpanInstrumentation.java
@@ -26,9 +26,9 @@
import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.redis.RedisSpanUtils;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import io.lettuce.core.protocol.RedisCommand;
import net.bytebuddy.asm.Advice;
diff --git a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/redis/lettuce/package-info.java b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/redis/lettuce/package-info.java
index 49a9253ba5..0f5995837b 100644
--- a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/redis/lettuce/package-info.java
+++ b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/redis/lettuce/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -28,4 +28,4 @@
@NonnullApi
package co.elastic.apm.agent.redis.lettuce;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/src/main/java/co/elastic/apm/agent/redis/redisson/package-info.java b/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/src/main/java/co/elastic/apm/agent/redis/redisson/package-info.java
index 9bf5ff0309..ce95cf71c6 100644
--- a/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/src/main/java/co/elastic/apm/agent/redis/redisson/package-info.java
+++ b/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/src/main/java/co/elastic/apm/agent/redis/redisson/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.redis.redisson;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-scala-concurrent-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-scala-concurrent-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-scala-concurrent-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-scala-concurrent-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/spring/scheduled/package-info.java b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/spring/scheduled/package-info.java
index a18f09031d..df72455604 100644
--- a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/spring/scheduled/package-info.java
+++ b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/spring/scheduled/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.spring.scheduled;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/AsyncInstrumentation.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/AsyncInstrumentation.java
index 5d8add8b91..dca0a567b5 100644
--- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/AsyncInstrumentation.java
+++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/AsyncInstrumentation.java
@@ -24,9 +24,9 @@
*/
package co.elastic.apm.agent.servlet;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.concurrent.JavaConcurrent;
import co.elastic.apm.agent.impl.GlobalTracer;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
import co.elastic.apm.agent.servlet.helper.AsyncContextAdviceHelperImpl;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.NamedElement;
@@ -40,7 +40,6 @@
import javax.servlet.ServletResponse;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Objects;
import static net.bytebuddy.matcher.ElementMatchers.hasSuperType;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/RequestStreamRecordingInstrumentation.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/RequestStreamRecordingInstrumentation.java
index fb61ca3e77..3bd6fccf94 100644
--- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/RequestStreamRecordingInstrumentation.java
+++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/RequestStreamRecordingInstrumentation.java
@@ -24,10 +24,10 @@
*/
package co.elastic.apm.agent.servlet;
-import co.elastic.apm.agent.bci.bytebuddy.postprocessor.AssignTo;
import co.elastic.apm.agent.impl.transaction.Transaction;
+import co.elastic.apm.agent.sdk.advice.AssignTo;
+import co.elastic.apm.agent.sdk.state.CallDepth;
import co.elastic.apm.agent.servlet.helper.RecordingServletInputStreamWrapper;
-import co.elastic.apm.agent.util.CallDepth;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.method.MethodDescription;
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 192891f7a3..ae738bc14f 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
@@ -31,8 +31,8 @@
import co.elastic.apm.agent.impl.context.Request;
import co.elastic.apm.agent.impl.context.Response;
import co.elastic.apm.agent.impl.transaction.Transaction;
+import co.elastic.apm.agent.sdk.state.GlobalThreadLocal;
import co.elastic.apm.agent.servlet.helper.ServletTransactionCreationHelper;
-import co.elastic.apm.agent.threadlocal.GlobalThreadLocal;
import net.bytebuddy.asm.Advice;
import javax.annotation.Nullable;
diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletGlobalState.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletGlobalState.java
index 2b0b60dd72..eb7a489085 100644
--- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletGlobalState.java
+++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletGlobalState.java
@@ -24,7 +24,7 @@
*/
package co.elastic.apm.agent.servlet;
-import co.elastic.apm.agent.bci.GlobalState;
+import co.elastic.apm.agent.sdk.state.GlobalState;
import java.util.Collections;
import java.util.Set;
diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletVersionInstrumentation.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletVersionInstrumentation.java
index a68ac051eb..11566e17d0 100644
--- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletVersionInstrumentation.java
+++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletVersionInstrumentation.java
@@ -24,7 +24,7 @@
*/
package co.elastic.apm.agent.servlet;
-import co.elastic.apm.agent.util.GlobalVariables;
+import co.elastic.apm.agent.sdk.state.GlobalVariables;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.method.MethodDescription;
diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/package-info.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/package-info.java
index 37c5ddb961..57bccd72e6 100644
--- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/package-info.java
+++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.servlet.helper;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/package-info.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/package-info.java
index b6c9940b67..388115047f 100644
--- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/package-info.java
+++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.servlet;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-servlet-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-servlet-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-servlet-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-spring-resttemplate-plugin/src/main/java/co/elastic/apm/agent/resttemplate/package-info.java b/apm-agent-plugins/apm-spring-resttemplate-plugin/src/main/java/co/elastic/apm/agent/resttemplate/package-info.java
index 7a3593d454..5ab3e01393 100644
--- a/apm-agent-plugins/apm-spring-resttemplate-plugin/src/main/java/co/elastic/apm/agent/resttemplate/package-info.java
+++ b/apm-agent-plugins/apm-spring-resttemplate-plugin/src/main/java/co/elastic/apm/agent/resttemplate/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.resttemplate;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-spring-resttemplate-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-spring-resttemplate-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-spring-resttemplate-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-spring-resttemplate-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/spring/webmvc/package-info.java b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/spring/webmvc/package-info.java
index 2c7fc0981a..e03d61361e 100644
--- a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/spring/webmvc/package-info.java
+++ b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/spring/webmvc/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.spring.webmvc;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-spring-webmvc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-spring-webmvc-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentation.java b/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentation.java
index 449761d1cf..698c0ab6cb 100644
--- a/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentation.java
+++ b/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentation.java
@@ -26,10 +26,10 @@
import co.elastic.apm.agent.bci.TracerAwareInstrumentation;
import co.elastic.apm.agent.bci.VisibleForAdvice;
-import co.elastic.apm.agent.collections.WeakMapSupplier;
import co.elastic.apm.agent.http.client.HttpClientHelper;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.TraceContext;
+import co.elastic.apm.agent.sdk.weakmap.WeakMapSupplier;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.NamedElement;
diff --git a/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/package-info.java b/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/package-info.java
index adf2cd8112..a3a6f6df44 100644
--- a/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/package-info.java
+++ b/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/package-info.java
@@ -11,9 +11,9 @@
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.agent.urlconnection;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/apm-agent-plugins/apm-urlconnection-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation b/apm-agent-plugins/apm-urlconnection-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
similarity index 100%
rename from apm-agent-plugins/apm-urlconnection-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.bci.ElasticApmInstrumentation
rename to apm-agent-plugins/apm-urlconnection-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
diff --git a/apm-opentracing/src/test/java/co/elastic/apm/opentracing/package-info.java b/apm-opentracing/src/test/java/co/elastic/apm/opentracing/package-info.java
index b710f24f0c..89b2aff808 100644
--- a/apm-opentracing/src/test/java/co/elastic/apm/opentracing/package-info.java
+++ b/apm-opentracing/src/test/java/co/elastic/apm/opentracing/package-info.java
@@ -25,4 +25,4 @@
@NonnullApi
package co.elastic.apm.opentracing;
-import co.elastic.apm.agent.annotation.NonnullApi;
+import co.elastic.apm.agent.sdk.NonnullApi;
diff --git a/elastic-apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporterTest.java b/elastic-apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporterTest.java
index 5fa19c8cb0..59ad6346e9 100644
--- a/elastic-apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporterTest.java
+++ b/elastic-apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporterTest.java
@@ -25,7 +25,7 @@
package co.elastic.apm.agent.configuration;
import co.elastic.apm.agent.MockTracer;
-import co.elastic.apm.agent.bci.ElasticApmInstrumentation;
+import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
import co.elastic.apm.agent.util.DependencyInjectingServiceLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
diff --git a/integration-tests/external-plugin-test/pom.xml b/integration-tests/external-plugin-test/pom.xml
new file mode 100644
index 0000000000..5255dd3b09
--- /dev/null
+++ b/integration-tests/external-plugin-test/pom.xml
@@ -0,0 +1,95 @@
+
+
+
+ integration-tests
+ co.elastic.apm
+ 1.17.1-SNAPSHOT
+
+ 4.0.0
+
+ external-plugin-test
+ ${project.groupId}:${project.artifactId}
+
+
+ ${project.basedir}/../..
+
+
+
+
+ ${project.groupId}
+ apm-agent-plugin-sdk
+ ${project.version}
+ provided
+
+
+ ${project.groupId}
+ apm-agent-api
+ ${project.version}
+
+
+
+
+
+
+ ${project.groupId}
+ elastic-apm-agent
+ ${project.version}
+ test
+
+
+
+
+ ${project.groupId}
+ apm-agent-core
+ test-jar
+ ${project.version}
+ test
+
+
+
+
+
+
+
+ maven-shade-plugin
+
+
+ package
+
+ shade
+
+
+ false
+
+
+ net.bytebuddy
+ co.elastic.apm.agent.shaded.bytebuddy
+
+
+
+
+
+
+
+
+
diff --git a/integration-tests/external-plugin-test/src/main/java/co/elastic/apm/plugin/PluginInstrumentation.java b/integration-tests/external-plugin-test/src/main/java/co/elastic/apm/plugin/PluginInstrumentation.java
new file mode 100644
index 0000000000..3d2e603715
--- /dev/null
+++ b/integration-tests/external-plugin-test/src/main/java/co/elastic/apm/plugin/PluginInstrumentation.java
@@ -0,0 +1,68 @@
+/*-
+ * #%L
+ * Elastic APM Java agent
+ * %%
+ * Copyright (C) 2018 - 2020 Elastic and contributors
+ * %%
+ * 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.
+ * #L%
+ */
+package co.elastic.apm.plugin;
+
+import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
+import co.elastic.apm.api.ElasticApm;
+import co.elastic.apm.api.Transaction;
+import net.bytebuddy.asm.Advice;
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+
+public class PluginInstrumentation extends ElasticApmInstrumentation {
+
+ @Override
+ public ElementMatcher super TypeDescription> getTypeMatcher() {
+ return named(System.getProperty("elastic.apm.plugin.instrumented_class", "co.elastic.apm.plugin.PluginInstrumentationTest"));
+ }
+
+ @Override
+ public ElementMatcher super MethodDescription> getMethodMatcher() {
+ return named(System.getProperty("elastic.apm.plugin.instrumented_method", "traceMe"));
+ }
+
+ @Override
+ public Collection getInstrumentationGroupNames() {
+ return Collections.singletonList("test-plugin");
+ }
+
+ @Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
+ public static Object onEnter(@Advice.Origin(value = "#m") String methodName) {
+ return ElasticApm.startTransaction().setName(methodName);
+ }
+
+ @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false)
+ public static void onExit(@Advice.Thrown Throwable thrown, @Advice.Enter Object transactionObject) {
+ Transaction transaction = (Transaction) transactionObject;
+ transaction.captureException(thrown);
+ transaction.end();
+ }
+}
diff --git a/integration-tests/external-plugin-test/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation b/integration-tests/external-plugin-test/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
new file mode 100644
index 0000000000..ae7031ec11
--- /dev/null
+++ b/integration-tests/external-plugin-test/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
@@ -0,0 +1 @@
+co.elastic.apm.plugin.PluginInstrumentation
diff --git a/integration-tests/external-plugin-test/src/test/java/co/elastic/apm/plugin/PluginInstrumentationTest.java b/integration-tests/external-plugin-test/src/test/java/co/elastic/apm/plugin/PluginInstrumentationTest.java
new file mode 100644
index 0000000000..53553d1911
--- /dev/null
+++ b/integration-tests/external-plugin-test/src/test/java/co/elastic/apm/plugin/PluginInstrumentationTest.java
@@ -0,0 +1,43 @@
+/*-
+ * #%L
+ * Elastic APM Java agent
+ * %%
+ * Copyright (C) 2018 - 2020 Elastic and contributors
+ * %%
+ * 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.
+ * #L%
+ */
+package co.elastic.apm.plugin;
+
+import co.elastic.apm.agent.AbstractInstrumentationTest;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class PluginInstrumentationTest extends AbstractInstrumentationTest {
+
+ @Test
+ void testCreateTransaction() {
+ traceMe();
+ assertThat(reporter.getTransactions()).hasSize(1);
+ assertThat(reporter.getFirstTransaction().getNameAsString()).isEqualTo("traceMe");
+ }
+
+ private void traceMe() {
+ }
+}
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 07ac34bf2d..eca9a11dbe 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -20,6 +20,7 @@
spring-boot-2
soap-test
cdi-app
+ external-plugin-test
diff --git a/pom.xml b/pom.xml
index 2ec372bc2b..28ce79900d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,6 +62,7 @@
apm-opentracing
integration-tests
apm-agent-attach
+ apm-agent-plugin-sdk