diff --git a/apm-agent-core/pom.xml b/apm-agent-core/pom.xml index 50b14298dcd..72ec146e2de 100644 --- a/apm-agent-core/pom.xml +++ b/apm-agent-core/pom.xml @@ -38,6 +38,11 @@ apm-agent-cached-lookup-key ${project.version} + + ${project.groupId} + apm-agent-plugin-spi + ${project.version} + com.blogspot.mydailyjava weak-lock-free diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/SpanConcurrentHashMap.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/SpanConcurrentHashMap.java index f83974f0aa9..6f0639e214e 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/SpanConcurrentHashMap.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/SpanConcurrentHashMap.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.collections; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.AbstractSpan; import javax.annotation.Nullable; import java.util.Iterator; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakConcurrentProviderImpl.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakConcurrentProviderImpl.java index b34024b84c3..0f4057bbc83 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakConcurrentProviderImpl.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakConcurrentProviderImpl.java @@ -18,11 +18,11 @@ */ package co.elastic.apm.agent.collections; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; import co.elastic.apm.agent.sdk.weakconcurrent.DetachedThreadLocal; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import co.elastic.apm.agent.sdk.weakconcurrent.WeakSet; +import co.elastic.apm.plugin.spi.AbstractSpan; import com.blogspot.mydailyjava.weaklockfree.AbstractWeakConcurrentMap; import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentSet; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServiceInfo.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServiceInfo.java index 7d6e36b7694..457995bf59e 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServiceInfo.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServiceInfo.java @@ -28,18 +28,13 @@ import java.util.jar.JarFile; import java.util.jar.Manifest; -public class ServiceInfo { +public class ServiceInfo extends co.elastic.apm.plugin.spi.ServiceInfo { private static final String JAR_VERSION_SUFFIX = "-(\\d+\\.)+(\\d+)(.*)?$"; private static final String DEFAULT_SERVICE_NAME = "unknown-java-service"; private static final ServiceInfo EMPTY = new ServiceInfo(null, null); private static final ServiceInfo AUTO_DETECTED = autoDetect(System.getProperties(), PrivilegedActionUtils.getEnv()); - private final String serviceName; - @Nullable - private final String serviceVersion; - private final boolean multiServiceContainer; - public ServiceInfo(@Nullable String serviceName) { this(serviceName, null); } @@ -49,13 +44,7 @@ private ServiceInfo(@Nullable String serviceName, @Nullable String serviceVersio } private ServiceInfo(@Nullable String serviceName, @Nullable String serviceVersion, boolean multiServiceContainer) { - this.multiServiceContainer = multiServiceContainer; - if (serviceName == null || serviceName.trim().isEmpty()) { - this.serviceName = DEFAULT_SERVICE_NAME; - } else { - this.serviceName = replaceDisallowedServiceNameChars(serviceName).trim(); - } - this.serviceVersion = serviceVersion; + super(serviceName, serviceVersion, multiServiceContainer); } public static ServiceInfo empty() { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/BasicTracer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/BasicTracer.java index 8d3238e41cf..2b539e3221f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/BasicTracer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/BasicTracer.java @@ -28,7 +28,6 @@ import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; -import org.stagemonitor.configuration.ConfigurationOptionProvider; import javax.annotation.Nullable; import java.util.Collections; @@ -326,11 +325,11 @@ protected boolean hasServiceName() { @Nullable @Override - public ServiceInfo getServiceInfoForClassLoader(@Nullable ClassLoader initiatingClassLoader) { - if (initiatingClassLoader == null) { + public ServiceInfo getServiceInfoForClassLoader(@Nullable ClassLoader classLoader) { + if (classLoader == null) { return null; } - return serviceInfoByClassLoader.get(initiatingClassLoader); + return serviceInfoByClassLoader.get(classLoader); } @Override @@ -441,11 +440,68 @@ public TracerState getState() { } @Override - public T getConfig(Class configProvider) { + public T getConfig(Class configProvider) { try { return configProvider.getConstructor().newInstance(); } catch (Exception e) { throw new IllegalStateException("Failed to create empty configuration for " + configProvider.getName(), e); } } + + @Nullable + @Override + public co.elastic.apm.plugin.spi.Transaction startChildTransaction(@Nullable C headerCarrier, final co.elastic.apm.plugin.spi.TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader) { + return startChildTransaction(headerCarrier, new TextHeaderGetterBridge<>(textHeadersGetter), initiatingClassLoader); + } + + @Nullable + @Override + public co.elastic.apm.plugin.spi.Transaction startChildTransaction(@Nullable C headerCarrier, co.elastic.apm.plugin.spi.TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader, long epochMicros) { + return startChildTransaction(headerCarrier, new TextHeaderGetterBridge(textHeadersGetter), initiatingClassLoader, epochMicros); + } + + @Nullable + @Override + public co.elastic.apm.plugin.spi.Transaction startChildTransaction(@Nullable C headerCarrier, co.elastic.apm.plugin.spi.BinaryHeaderGetter binaryHeadersGetter, @Nullable ClassLoader initiatingClassLoader) { + return startChildTransaction(headerCarrier, new BinaryHeaderGetterBridge(binaryHeadersGetter), initiatingClassLoader); + } + + @Nullable + @Override + public String captureAndReportException(long epochMicros, @Nullable Throwable e, @Nullable co.elastic.apm.plugin.spi.AbstractSpan parent) { + return captureAndReportException(epochMicros, e, (AbstractSpan) parent); + } + + @Nullable + @Override + public co.elastic.apm.plugin.spi.ErrorCapture captureException(@Nullable Throwable e, @Nullable co.elastic.apm.plugin.spi.AbstractSpan parent, @Nullable ClassLoader initiatingClassLoader) { + return captureException(e, (AbstractSpan) parent, initiatingClassLoader); + } + + @Override + public void endSpan(co.elastic.apm.plugin.spi.Span span) { + endSpan((Span) span); + } + + @Override + public void endTransaction(co.elastic.apm.plugin.spi.Transaction transaction) { + endTransaction((Transaction) transaction); + } + + @Override + public void endError(co.elastic.apm.plugin.spi.ErrorCapture errorCapture) { + endError((ErrorCapture) errorCapture); + } + + @Override + public void setServiceInfoForClassLoader(ClassLoader classLoader, co.elastic.apm.plugin.spi.ServiceInfo serviceInfo) { + setServiceInfoForClassLoader(classLoader, serviceInfo.isMultiServiceContainer() + ? ServiceInfo.ofMultiServiceContainer(serviceInfo.getServiceName()) + : ServiceInfo.of(serviceInfo.getServiceName(), serviceInfo.getServiceVersion())); + } + + @Override + public ServiceInfo autoDetectedServiceName() { + return ServiceInfo.autoDetected(); + } } 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 9b9e7ec180e..2043aabda7c 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 @@ -207,8 +207,13 @@ public ConfigurationRegistry getConfigurationRegistry() { } @Override - public T getConfig(Class configProvider) { - return configurationRegistry.getConfig(configProvider); + @SuppressWarnings({"unchecked", "rawtypes"}) + public T getConfig(Class configProvider) { + if (ConfigurationOptionProvider.class.isAssignableFrom(configProvider)) { + return (T) configurationRegistry.getConfig((Class) configProvider); + } else { + throw new IllegalArgumentException("Configuration types must subclass " + ConfigurationOptionProvider.class.getName()); + } } @Override diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/GlobalTracer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/GlobalTracer.java index b8821fc0002..6b5cbdc3404 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/GlobalTracer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/GlobalTracer.java @@ -29,7 +29,6 @@ import co.elastic.apm.agent.objectpool.ObjectPoolFactory; import co.elastic.apm.agent.util.PrivilegedActionUtils; import co.elastic.apm.agent.util.VersionUtils; -import org.stagemonitor.configuration.ConfigurationOptionProvider; import javax.annotation.Nullable; import java.io.File; @@ -125,6 +124,7 @@ public static synchronized void init(Tracer tracer) { if (!isNoop()) { throw new IllegalStateException("Tracer is already initialized"); } + co.elastic.apm.plugin.spi.GlobalTracer.init(tracer); INSTANCE.tracer = tracer; } @@ -264,7 +264,7 @@ public void endError(ErrorCapture errorCapture) { } @Override - public T getConfig(Class configuration) { + public T getConfig(Class configuration) { return tracer.getConfig(configuration); } @@ -277,4 +277,59 @@ public ObjectPoolFactory getObjectPoolFactory() { public void recycle(ErrorCapture errorCapture) { tracer.recycle(errorCapture); } + + @Nullable + @Override + public co.elastic.apm.plugin.spi.Transaction startChildTransaction(@Nullable C headerCarrier, co.elastic.apm.plugin.spi.TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader) { + return tracer.startChildTransaction(headerCarrier, textHeadersGetter, initiatingClassLoader); + } + + @Nullable + @Override + public co.elastic.apm.plugin.spi.Transaction startChildTransaction(@Nullable C headerCarrier, co.elastic.apm.plugin.spi.TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader, long epochMicros) { + return tracer.startChildTransaction(headerCarrier, textHeadersGetter, initiatingClassLoader, epochMicros); + } + + @Nullable + @Override + public co.elastic.apm.plugin.spi.Transaction startChildTransaction(@Nullable C headerCarrier, co.elastic.apm.plugin.spi.BinaryHeaderGetter binaryHeadersGetter, @Nullable ClassLoader initiatingClassLoader) { + return tracer.startChildTransaction(headerCarrier, binaryHeadersGetter, initiatingClassLoader); + } + + @Nullable + @Override + public String captureAndReportException(long epochMicros, @Nullable Throwable e, @Nullable co.elastic.apm.plugin.spi.AbstractSpan parent) { + return tracer.captureAndReportException(epochMicros, e, parent); + } + + @Nullable + @Override + public co.elastic.apm.plugin.spi.ErrorCapture captureException(@Nullable Throwable e, @Nullable co.elastic.apm.plugin.spi.AbstractSpan parent, @Nullable ClassLoader initiatingClassLoader) { + return tracer.captureException(e, parent, initiatingClassLoader); + } + + @Override + public void endSpan(co.elastic.apm.plugin.spi.Span span) { + tracer.endSpan(span); + } + + @Override + public void endTransaction(co.elastic.apm.plugin.spi.Transaction transaction) { + tracer.endTransaction(transaction); + } + + @Override + public void endError(co.elastic.apm.plugin.spi.ErrorCapture errorCapture) { + tracer.endError(errorCapture); + } + + @Override + public void setServiceInfoForClassLoader(ClassLoader classLoader, co.elastic.apm.plugin.spi.ServiceInfo serviceInfo) { + tracer.setServiceInfoForClassLoader(classLoader, serviceInfo); + } + + @Override + public ServiceInfo autoDetectedServiceName() { + return tracer.autoDetectedServiceName(); + } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopTracer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopTracer.java index 49f58d15651..21d59fb092d 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopTracer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopTracer.java @@ -27,7 +27,6 @@ import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.objectpool.ObjectPoolFactory; -import org.stagemonitor.configuration.ConfigurationOptionProvider; import javax.annotation.Nullable; @@ -173,7 +172,7 @@ public void endTransaction(Transaction transaction) { } public void endError(ErrorCapture errorCapture) { } @Override - public T getConfig(Class configuration) { + public T getConfig(Class configuration) { return null; } @@ -181,4 +180,55 @@ public T getConfig(Class configuratio public ObjectPoolFactory getObjectPoolFactory() { return null; } + + @Nullable + @Override + public co.elastic.apm.plugin.spi.Transaction startChildTransaction(@Nullable C headerCarrier, co.elastic.apm.plugin.spi.TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader) { + return null; + } + + @Nullable + @Override + public co.elastic.apm.plugin.spi.Transaction startChildTransaction(@Nullable C headerCarrier, co.elastic.apm.plugin.spi.TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader, long epochMicros) { + return null; + } + + @Nullable + @Override + public co.elastic.apm.plugin.spi.Transaction startChildTransaction(@Nullable C headerCarrier, co.elastic.apm.plugin.spi.BinaryHeaderGetter binaryHeadersGetter, @Nullable ClassLoader initiatingClassLoader) { + return null; + } + + @Nullable + @Override + public String captureAndReportException(long epochMicros, @Nullable Throwable e, @Nullable co.elastic.apm.plugin.spi.AbstractSpan parent) { + return null; + } + + @Nullable + @Override + public co.elastic.apm.plugin.spi.ErrorCapture captureException(@Nullable Throwable e, @Nullable co.elastic.apm.plugin.spi.AbstractSpan parent, @Nullable ClassLoader initiatingClassLoader) { + return null; + } + + @Override + public void endSpan(co.elastic.apm.plugin.spi.Span span) { + } + + @Override + public void endTransaction(co.elastic.apm.plugin.spi.Transaction transaction) { + } + + @Override + public void endError(co.elastic.apm.plugin.spi.ErrorCapture errorCapture) { + } + + @Override + public void setServiceInfoForClassLoader(ClassLoader classLoader, co.elastic.apm.plugin.spi.ServiceInfo serviceInfo) { + } + + @Override + public ServiceInfo autoDetectedServiceName() { + return null; + } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Scope.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Scope.java index 81ee98d916c..17eef45535f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Scope.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Scope.java @@ -41,7 +41,7 @@ * {@link co.elastic.apm.agent.impl.transaction.AbstractSpan}. *

*/ -public interface Scope extends AutoCloseable { +public interface Scope extends AutoCloseable, co.elastic.apm.plugin.spi.Scope { @Override void close(); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Tracer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Tracer.java index 904f26c8a88..dfaa47943c4 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Tracer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Tracer.java @@ -28,11 +28,10 @@ import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.objectpool.ObjectPoolFactory; -import org.stagemonitor.configuration.ConfigurationOptionProvider; import javax.annotation.Nullable; -public interface Tracer { +public interface Tracer extends co.elastic.apm.plugin.spi.Tracer { /** * Starts a trace-root transaction @@ -191,10 +190,12 @@ Transaction startChildTransaction(@Nullable C headerCarrier, BinaryHeaderGet void endError(ErrorCapture errorCapture); - T getConfig(Class configuration); + T getConfig(Class configuration); ObjectPoolFactory getObjectPoolFactory(); + ServiceInfo autoDetectedServiceName(); + /** * An enumeration used to represent the current tracer state. */ diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/AbstractContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/AbstractContext.java index 67d46c115b4..30595686e12 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/AbstractContext.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/AbstractContext.java @@ -25,7 +25,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -public abstract class AbstractContext implements Recyclable { +public abstract class AbstractContext implements Recyclable, co.elastic.apm.plugin.spi.AbstractContext { public static final String REDACTED_CONTEXT_STRING = "[REDACTED]"; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/CloudOrigin.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/CloudOrigin.java index 92f474566ac..cfb4024c6ad 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/CloudOrigin.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/CloudOrigin.java @@ -28,7 +28,7 @@ * If a request originated from a cloud component that provides information about the cloud origin, * the cloud origin interface can be used to collect this information. */ -public class CloudOrigin implements Recyclable { +public class CloudOrigin implements Recyclable, co.elastic.apm.plugin.spi.CloudOrigin { @Nullable protected String accountId; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Db.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Db.java index 897312cd533..edc6ba1a53f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Db.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Db.java @@ -34,7 +34,7 @@ /** * An object containing contextual data for database spans */ -public class Db implements Recyclable { +public class Db implements Recyclable, co.elastic.apm.plugin.spi.Db { private static final ObjectPool charBufferPool = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, new Allocator() { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Destination.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Destination.java index 1d7faa7e85f..ea8d38001f9 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Destination.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Destination.java @@ -28,7 +28,7 @@ /** * Context information about a destination of outgoing calls. */ -public class Destination implements Recyclable { +public class Destination implements Recyclable, co.elastic.apm.plugin.spi.Destination { /** * An IP (v4 or v6) or a host/domain name. @@ -184,7 +184,7 @@ public Destination withInetAddress(InetAddress inetAddress) { return this; } - public static class Cloud implements Recyclable { + public static class Cloud implements Recyclable, co.elastic.apm.plugin.spi.Cloud { private final StringBuilder region = new StringBuilder(); public Cloud withRegion(@Nullable String region) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Http.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Http.java index 1262dccedeb..cca4950e794 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Http.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Http.java @@ -22,7 +22,7 @@ import javax.annotation.Nullable; -public class Http implements Recyclable { +public class Http implements Recyclable, co.elastic.apm.plugin.spi.Http { /** * URL used by this HTTP outgoing span diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Message.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Message.java index 9a1c79fc62b..f459b89d367 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Message.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Message.java @@ -29,7 +29,7 @@ import static co.elastic.apm.agent.impl.context.AbstractContext.REDACTED_CONTEXT_STRING; -public class Message implements Recyclable { +public class Message implements Recyclable, co.elastic.apm.plugin.spi.Message { private static final ObjectPool stringBuilderPool = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, new Allocator() { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Request.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Request.java index 1a85d88d2f9..9628ed9c8b9 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Request.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Request.java @@ -40,7 +40,7 @@ *

* If a log record was generated as a result of a http request, the http interface can be used to collect this information. */ -public class Request implements Recyclable { +public class Request implements Recyclable, co.elastic.apm.plugin.spi.Request { private static final ObjectPool charBufferPool = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Response.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Response.java index b4f8345f137..459747845ff 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Response.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Response.java @@ -24,7 +24,7 @@ import javax.annotation.Nullable; import java.util.Collection; -public class Response implements Recyclable { +public class Response implements Recyclable, co.elastic.apm.plugin.spi.Response { /** * A mapping of HTTP headers of the response object diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceTarget.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceTarget.java index 9b239adc83b..65c405776a1 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceTarget.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceTarget.java @@ -25,7 +25,7 @@ /** * Represents a target service */ -public class ServiceTarget implements Recyclable { +public class ServiceTarget implements Recyclable, co.elastic.apm.plugin.spi.ServiceTarget { @Nullable private String type; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Socket.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Socket.java index c35035ab2bb..ca2507266ac 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Socket.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Socket.java @@ -22,7 +22,7 @@ import javax.annotation.Nullable; -public class Socket implements Recyclable { +public class Socket implements Recyclable, co.elastic.apm.plugin.spi.Socket { @Nullable private String remoteAddress; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SpanContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SpanContext.java index b088d3a944b..66f4e7acef3 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SpanContext.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SpanContext.java @@ -22,7 +22,7 @@ /** * Any other arbitrary data captured by the agent, optionally provided by the user */ -public class SpanContext extends AbstractContext { +public class SpanContext extends AbstractContext implements co.elastic.apm.plugin.spi.SpanContext { /** * An object containing contextual data for database spans diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/TransactionContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/TransactionContext.java index edf55a51cc8..8c9ab9c7fc9 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/TransactionContext.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/TransactionContext.java @@ -28,7 +28,7 @@ *

* Any arbitrary contextual information regarding the event, captured by the agent, optionally provided by the user */ -public class TransactionContext extends AbstractContext { +public class TransactionContext extends AbstractContext implements co.elastic.apm.plugin.spi.TransactionContext { /** * A flat mapping of user-defined {@link String} keys and {@link String}, {@link Number} or {@link Boolean} values diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Url.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Url.java index 7b82da35e4a..ead8f5fa166 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Url.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Url.java @@ -30,7 +30,7 @@ /** * A complete URL, with scheme, host, port, path and query string. */ -public class Url implements Recyclable { +public class Url implements Recyclable, co.elastic.apm.plugin.spi.Url { /** * The full, possibly agent-assembled URL of the request, e.g https://example.com:443/search?q=elasticsearch#top. @@ -223,6 +223,16 @@ public void fillFrom(URI uri) { .updateFull(); } + @Override + public void fillFrom(@Nullable String scheme, @Nullable String serverName, int serverPort, @Nullable String requestURI, @Nullable String queryString) { + withProtocol(scheme) + .withHostname(hostname) + .withPort(normalizePort(port, scheme)) + .withPathname(pathname) + .withSearch(queryString) + .updateFull(); + } + /** * Fills all attributes of Url from {@link URL} instance, also updates full * diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/User.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/User.java index 90bf8442213..47adc0b63a6 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/User.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/User.java @@ -28,7 +28,7 @@ *

* Describes the authenticated User for a request. */ -public class User implements Recyclable { +public class User implements Recyclable, co.elastic.apm.plugin.spi.User { /** * Domain of the logged in user diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/ErrorCapture.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/ErrorCapture.java index 927073d15ed..13d4dec3162 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/ErrorCapture.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/ErrorCapture.java @@ -38,7 +38,7 @@ /** * Data captured by an agent representing an event occurring in a monitored service */ -public class ErrorCapture implements Recyclable { +public class ErrorCapture implements Recyclable, co.elastic.apm.plugin.spi.ErrorCapture { private static final Logger logger = LoggerFactory.getLogger(ErrorCapture.class); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractHeaderGetter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractHeaderGetter.java index f48e06135a8..01ef195115d 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractHeaderGetter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractHeaderGetter.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.impl.transaction; -public abstract class AbstractHeaderGetter implements HeaderGetter { +public abstract class AbstractHeaderGetter extends co.elastic.apm.plugin.spi.AbstractHeaderGetter implements HeaderGetter { @Override - public void forEach(String headerName, C carrier, S state, HeaderConsumer consumer) { + public void forEach(String headerName, C carrier, S state, HeaderGetter.HeaderConsumer consumer) { T firstHeader = getFirstHeader(headerName, carrier); if (firstHeader != null) { consumer.accept(firstHeader, state); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractSpan.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractSpan.java index 1be9e7c70d3..5e445458c81 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractSpan.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractSpan.java @@ -29,6 +29,7 @@ import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.util.LoggerUtils; +import co.elastic.apm.plugin.spi.HeaderChildContextCreator; import javax.annotation.Nullable; import java.util.HashMap; @@ -38,7 +39,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -public abstract class AbstractSpan> implements Recyclable, ElasticContext { +public abstract class AbstractSpan> implements Recyclable, ElasticContext, co.elastic.apm.plugin.spi.AbstractSpan { public static final int PRIO_USER_SUPPLIED = 1000; public static final int PRIO_HIGH_LEVEL_FRAMEWORK = 100; public static final int PRIO_METHOD_SIGNATURE = 100; @@ -139,7 +140,7 @@ public int getReferenceCount() { */ public T requestDiscarding() { this.discardRequested = true; - return (T) this; + return thiz(); } /** @@ -521,7 +522,7 @@ public Span createExitSpan() { public T asExit() { isExit = true; - return (T) this; + return thiz(); } public boolean isExit() { @@ -541,7 +542,7 @@ public T captureException(@Nullable Throwable t) { if (t != null) { captureExceptionAndGetErrorId(getTraceContext().getClock().getEpochMicros(), t); } - return (T) this; + return thiz(); } public void endExceptionally(@Nullable Throwable t) { @@ -650,13 +651,13 @@ private boolean hasChildId(Id spanId) { @Override public T activate() { tracer.activate(this); - return (T) this; + return thiz(); } @Override public T deactivate() { tracer.deactivate(this); - return (T) this; + return thiz(); } @Override @@ -854,4 +855,62 @@ private String normalizeType(@Nullable String type) { return type; } + @Override + public boolean addSpanLink(HeaderChildContextCreator childContextCreator, final co.elastic.apm.plugin.spi.HeaderGetter headerGetter, @Nullable C carrier) { + return addSpanLink(childContextCreator, new HeaderGetter() { + @Nullable + @Override + public H getFirstHeader(String headerName, C carrier) { + return headerGetter.getFirstHeader(headerName, carrier); + } + + @Override + public void forEach(String headerName, C carrier, S state, HeaderConsumer consumer) { + headerGetter.forEach(headerName, carrier, state, consumer); + } + + @Override + public void forEach(String headerName, C carrier, S state, co.elastic.apm.plugin.spi.HeaderGetter.HeaderConsumer consumer) { + headerGetter.forEach(headerName, carrier, state, consumer); + } + }, carrier); + } + + @Override + public boolean propagateTraceContext(C carrier, final co.elastic.apm.plugin.spi.BinaryHeaderSetter headerSetter) { + return propagateTraceContext(carrier, new BinaryHeaderSetter() { + @Nullable + @Override + public byte[] getFixedLengthByteArray(String headerName, int length) { + return headerSetter.getFixedLengthByteArray(headerName, length); + } + + @Override + public void setHeader(String headerName, byte[] headerValue, C carrier) { + headerSetter.setHeader(headerName, headerValue, carrier); + } + }); + } + + @Override + public void propagateTraceContext(C carrier, final co.elastic.apm.plugin.spi.TextHeaderSetter headerSetter) { + propagateTraceContext(carrier, new TextHeaderSetter() { + @Override + public void setHeader(String headerName, String headerValue, C carrier) { + headerSetter.setHeader(headerName, headerValue, carrier); + } + }); + } + + @Override + public T withOutcome(co.elastic.apm.plugin.spi.Outcome outcome) { + String name = outcome.name(); + if (name.equals(Outcome.FAILURE.name())) { + return withOutcome(Outcome.FAILURE); + } else if (name.equals(Outcome.SUCCESS.name())) { + return withOutcome(Outcome.SUCCESS); + } else { + return withOutcome(Outcome.UNKNOWN); + } + } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderGetter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderGetter.java index 7f348044edf..38c01128d9a 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderGetter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderGetter.java @@ -18,5 +18,5 @@ */ package co.elastic.apm.agent.impl.transaction; -public interface BinaryHeaderGetter extends HeaderGetter { +public interface BinaryHeaderGetter extends HeaderGetter, co.elastic.apm.plugin.spi.BinaryHeaderGetter { } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderGetterBridge.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderGetterBridge.java new file mode 100644 index 00000000000..8816f0e9e4d --- /dev/null +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderGetterBridge.java @@ -0,0 +1,30 @@ +package co.elastic.apm.agent.impl.transaction; + +import co.elastic.apm.plugin.spi.HeaderGetter; + +import javax.annotation.Nullable; + +public class BinaryHeaderGetterBridge implements BinaryHeaderGetter { + + private final co.elastic.apm.plugin.spi.BinaryHeaderGetter binaryHeaderGetter; + + public BinaryHeaderGetterBridge(co.elastic.apm.plugin.spi.BinaryHeaderGetter binaryHeaderGetter) { + this.binaryHeaderGetter = binaryHeaderGetter; + } + + @Nullable + @Override + public byte[] getFirstHeader(String headerName, C carrier) { + return binaryHeaderGetter.getFirstHeader(headerName, carrier); + } + + @Override + public void forEach(String headerName, C carrier, S state, co.elastic.apm.agent.impl.transaction.HeaderGetter.HeaderConsumer consumer) { + binaryHeaderGetter.forEach(headerName, carrier, state, consumer); + } + + @Override + public void forEach(String headerName, C carrier, S state, HeaderGetter.HeaderConsumer consumer) { + binaryHeaderGetter.forEach(headerName, carrier, state, consumer); + } +} diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderSetter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderSetter.java index 8efccc96a42..4dcbed9a767 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderSetter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderSetter.java @@ -20,7 +20,7 @@ import javax.annotation.Nullable; -public interface BinaryHeaderSetter extends HeaderSetter { +public interface BinaryHeaderSetter extends HeaderSetter, co.elastic.apm.plugin.spi.BinaryHeaderSetter { /** * Since the implementation itself knows the intrinsics of the headers and carrier lifecycle and handling, it should diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContext.java index 6b9ccf4b2e1..155a149b2db 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContext.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContext.java @@ -22,7 +22,7 @@ import javax.annotation.Nullable; -public interface ElasticContext> { +public interface ElasticContext> extends co.elastic.apm.plugin.spi.ElasticContext { /** * Makes the context active diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Faas.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Faas.java index 4068f3604dd..c436c4ea860 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Faas.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Faas.java @@ -22,7 +22,7 @@ import javax.annotation.Nullable; -public class Faas implements Recyclable { +public class Faas implements Recyclable, co.elastic.apm.plugin.spi.Faas { @Nullable private String execution; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderConsumerBridge.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderConsumerBridge.java new file mode 100644 index 00000000000..012de108567 --- /dev/null +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderConsumerBridge.java @@ -0,0 +1,17 @@ +package co.elastic.apm.agent.impl.transaction; + +import javax.annotation.Nullable; + +public class HeaderConsumerBridge implements HeaderGetter.HeaderConsumer { + + private final co.elastic.apm.plugin.spi.HeaderGetter.HeaderConsumer headerConsumer; + + public HeaderConsumerBridge(co.elastic.apm.plugin.spi.HeaderGetter.HeaderConsumer headerConsumer) { + this.headerConsumer = headerConsumer; + } + + @Override + public void accept(@Nullable T headerValue, C state) { + headerConsumer.accept(headerValue, state); + } +} diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderGetter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderGetter.java index c973af101b6..708079974d5 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderGetter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderGetter.java @@ -20,7 +20,7 @@ import javax.annotation.Nullable; -public interface HeaderGetter { +public interface HeaderGetter extends co.elastic.apm.plugin.spi.HeaderGetter { @Nullable T getFirstHeader(String headerName, C carrier); @@ -41,7 +41,7 @@ public interface HeaderGetter { */ void forEach(String headerName, C carrier, S state, HeaderConsumer consumer); - interface HeaderConsumer { + interface HeaderConsumer extends co.elastic.apm.plugin.spi.HeaderGetter.HeaderConsumer { void accept(@Nullable T headerValue, S state); } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderGetterBridge.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderGetterBridge.java new file mode 100644 index 00000000000..78cab4611da --- /dev/null +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderGetterBridge.java @@ -0,0 +1,28 @@ +package co.elastic.apm.agent.impl.transaction; + +import javax.annotation.Nullable; + +public class HeaderGetterBridge implements HeaderGetter { + + private final co.elastic.apm.plugin.spi.HeaderGetter headerGetter; + + public HeaderGetterBridge(co.elastic.apm.plugin.spi.HeaderGetter headerGetter) { + this.headerGetter = headerGetter; + } + + @Nullable + @Override + public T getFirstHeader(String headerName, C carrier) { + return headerGetter.getFirstHeader(headerName, carrier); + } + + @Override + public void forEach(String headerName, C carrier, S state, HeaderConsumer consumer) { + headerGetter.forEach(headerName, carrier, state, consumer); + } + + @Override + public void forEach(String headerName, C carrier, S state, co.elastic.apm.plugin.spi.HeaderGetter.HeaderConsumer consumer) { + headerGetter.forEach(headerName, carrier, state, new HeaderConsumerBridge<>(consumer)); + } +} diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderRemover.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderRemover.java index e0f3a2251f9..265f102970a 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderRemover.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderRemover.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.transaction; -public interface HeaderRemover { +public interface HeaderRemover extends co.elastic.apm.plugin.spi.HeaderRemover { void remove(String headerName, C carrier); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderSetter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderSetter.java index be369d3cf0e..7940e03588a 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderSetter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderSetter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.transaction; -public interface HeaderSetter { +public interface HeaderSetter extends co.elastic.apm.plugin.spi.HeaderSetter { void setHeader(String headerName, T headerValue, C carrier); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Id.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Id.java index 166f5979047..8c25277d7c2 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Id.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Id.java @@ -31,7 +31,7 @@ /** * A 128 bit globally unique ID of the whole trace forest */ -public class Id implements Recyclable { +public class Id implements Recyclable, co.elastic.apm.plugin.spi.Id { private final byte[] data; private boolean empty = true; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/MultiValueMapAccessor.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/MultiValueMapAccessor.java index dd902706640..10bf22372c9 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/MultiValueMapAccessor.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/MultiValueMapAccessor.java @@ -37,7 +37,7 @@ public String getFirstHeader(String headerName, PotentiallyMultiValuedMap header } @Override - public void forEach(String headerName, PotentiallyMultiValuedMap headerMap, S state, HeaderConsumer consumer) { + public void forEach(String headerName, PotentiallyMultiValuedMap headerMap, S state, HeaderGetter.HeaderConsumer consumer) { for (String headerValue : headerMap.getAll(headerName)) { consumer.accept(headerValue, state); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Outcome.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Outcome.java index c530d46a714..bfdd846032b 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Outcome.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Outcome.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.transaction; -public enum Outcome { +public enum Outcome implements co.elastic.apm.plugin.spi.Outcome { SUCCESS("success"), FAILURE("failure"), UNKNOWN("unknown"); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Span.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Span.java index a5e1740dbac..92792a47bbb 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Span.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Span.java @@ -36,7 +36,7 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; -public class Span extends AbstractSpan implements Recyclable { +public class Span extends AbstractSpan implements Recyclable, co.elastic.apm.plugin.spi.Span { private static final Logger logger = LoggerFactory.getLogger(Span.class); public static final long MAX_LOG_INTERVAL_MICRO_SECS = TimeUnit.MINUTES.toMicros(5); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderGetter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderGetter.java index 88ca8ee8395..0cb46fc82db 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderGetter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderGetter.java @@ -18,5 +18,5 @@ */ package co.elastic.apm.agent.impl.transaction; -public interface TextHeaderGetter extends HeaderGetter { +public interface TextHeaderGetter extends HeaderGetter, co.elastic.apm.plugin.spi.TextHeaderGetter { } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderGetterBridge.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderGetterBridge.java new file mode 100644 index 00000000000..c1a5828b115 --- /dev/null +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderGetterBridge.java @@ -0,0 +1,28 @@ +package co.elastic.apm.agent.impl.transaction; + +import javax.annotation.Nullable; + +public class TextHeaderGetterBridge implements TextHeaderGetter { + + private final co.elastic.apm.plugin.spi.TextHeaderGetter textHeadersGetter; + + public TextHeaderGetterBridge(co.elastic.apm.plugin.spi.TextHeaderGetter textHeadersGetter) { + this.textHeadersGetter = textHeadersGetter; + } + + @Nullable + @Override + public String getFirstHeader(String headerName, C carrier) { + return textHeadersGetter.getFirstHeader(headerName, carrier); + } + + @Override + public void forEach(String headerName, C carrier, S state, HeaderGetter.HeaderConsumer consumer) { + textHeadersGetter.forEach(headerName, carrier, state, consumer); + } + + @Override + public void forEach(String headerName, C carrier, S state, co.elastic.apm.plugin.spi.HeaderGetter.HeaderConsumer consumer) { + textHeadersGetter.forEach(headerName, carrier, state, consumer); + } +} diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderSetter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderSetter.java index 051165e44ad..5f589d53be9 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderSetter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderSetter.java @@ -18,5 +18,5 @@ */ package co.elastic.apm.agent.impl.transaction; -public interface TextHeaderSetter extends HeaderSetter { +public interface TextHeaderSetter extends HeaderSetter, co.elastic.apm.plugin.spi.TextHeaderSetter { } 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 75e474fe9c7..bb7518afbf4 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 @@ -20,7 +20,6 @@ import co.elastic.apm.agent.configuration.CoreConfiguration; 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.impl.sampling.Sampler; import co.elastic.apm.agent.objectpool.Recyclable; @@ -67,7 +66,7 @@ * 2, 1] * */ -public class TraceContext implements Recyclable { +public class TraceContext implements Recyclable, co.elastic.apm.plugin.spi.TraceContext { public static final String ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME = "elastic-apm-traceparent"; public static final String W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME = "traceparent"; @@ -94,20 +93,20 @@ public class TraceContext implements Recyclable { private static final Double SAMPLE_RATE_ZERO = 0d; - private static final ChildContextCreator FROM_PARENT_CONTEXT = new ChildContextCreator() { + private static final ChildContextCreator FROM_PARENT_CONTEXT = new ChildContextCreatorBridge(new co.elastic.apm.plugin.spi.ChildContextCreator() { @Override - public boolean asChildOf(TraceContext child, TraceContext parent) { + public boolean asChildOf(co.elastic.apm.plugin.spi.TraceContext child, TraceContext parent) { child.asChildOf(parent); return true; } - }; - private static final ChildContextCreator> FROM_PARENT = new ChildContextCreator>() { + }); + private static final ChildContextCreator> FROM_PARENT = new ChildContextCreatorBridge>(new co.elastic.apm.plugin.spi.ChildContextCreator>() { @Override - public boolean asChildOf(TraceContext child, AbstractSpan parent) { + public boolean asChildOf(co.elastic.apm.plugin.spi.TraceContext child, AbstractSpan parent) { child.asChildOf(parent.getTraceContext()); return true; } - }; + }); private static final HeaderGetter.HeaderConsumer TRACESTATE_HEADER_CONSUMER = new HeaderGetter.HeaderConsumer() { @Override public void accept(@Nullable String tracestateHeaderValue, TraceContext state) { @@ -117,9 +116,9 @@ public void accept(@Nullable String tracestateHeaderValue, TraceContext state) { } }; private static final HeaderChildContextCreator FROM_TRACE_CONTEXT_TEXT_HEADERS = - new HeaderChildContextCreator() { + new HeaderChildContextCreatorBridge(new co.elastic.apm.plugin.spi.HeaderChildContextCreator() { @Override - public boolean asChildOf(TraceContext child, @Nullable Object carrier, HeaderGetter traceContextHeaderGetter) { + public boolean asChildOf(co.elastic.apm.plugin.spi.TraceContext child, @Nullable Object carrier, co.elastic.apm.plugin.spi.HeaderGetter traceContextHeaderGetter) { if (carrier == null) { return false; } @@ -127,25 +126,25 @@ public boolean asChildOf(TraceContext child, @Nullable Object carrier, HeaderGet boolean isValid = false; String traceparent = traceContextHeaderGetter.getFirstHeader(W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, carrier); if (traceparent != null) { - isValid = child.asChildOf(traceparent); + isValid = ((TraceContext) child).asChildOf(traceparent); } if (!isValid) { // Look for the legacy Elastic traceparent header (in case this comes from an older agent) traceparent = traceContextHeaderGetter.getFirstHeader(ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, carrier); if (traceparent != null) { - isValid = child.asChildOf(traceparent); + isValid = ((TraceContext) child).asChildOf(traceparent); } } if (isValid) { // as per spec, the tracestate header can be multi-valued - traceContextHeaderGetter.forEach(TRACESTATE_HEADER_NAME, carrier, child, TRACESTATE_HEADER_CONSUMER); + traceContextHeaderGetter.forEach(TRACESTATE_HEADER_NAME, carrier, ((TraceContext) child), TRACESTATE_HEADER_CONSUMER); } return isValid; } - }; + }); private static final HeaderChildContextCreator FROM_TRACE_CONTEXT_BINARY_HEADERS = new HeaderChildContextCreator() { @Override @@ -159,10 +158,15 @@ public boolean asChildOf(TraceContext child, @Nullable Object carrier, HeaderGet } return false; } + + @Override + public boolean asChildOf(co.elastic.apm.plugin.spi.TraceContext child, @Nullable Object carrier, co.elastic.apm.plugin.spi.HeaderGetter headerGetter) { + return asChildOf((TraceContext) child, carrier, new HeaderGetterBridge(headerGetter)); + } }; - private static final ChildContextCreator FROM_ACTIVE = new ChildContextCreator() { + private static final ChildContextCreator FROM_ACTIVE = new ChildContextCreatorBridge(new co.elastic.apm.plugin.spi.ChildContextCreator() { @Override - public boolean asChildOf(TraceContext child, Tracer tracer) { + public boolean asChildOf(co.elastic.apm.plugin.spi.TraceContext child, Tracer tracer) { final AbstractSpan active = tracer.getActive(); if (active != null) { return fromParent().asChildOf(child, active); @@ -170,14 +174,13 @@ public boolean asChildOf(TraceContext child, Tracer tracer) { } return false; } - }; - private static final ChildContextCreator AS_ROOT = new ChildContextCreator() { + }); + private static final ChildContextCreator AS_ROOT = new ChildContextCreatorBridge(new co.elastic.apm.plugin.spi.ChildContextCreator() { @Override - public boolean asChildOf(TraceContext child, Object ignore) { + public boolean asChildOf(co.elastic.apm.plugin.spi.TraceContext child, Object ignore) { return false; } - }; - + }); public static boolean containsTraceContextTextHeaders(C carrier, TextHeaderGetter headerGetter) { return headerGetter.getFirstHeader(W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, carrier) != null; @@ -297,7 +300,7 @@ public static ChildContextCreator asRoot() { * @param traceParentHeader traceparent text header value * @return {@literal true} if header value is valid, {@literal false} otherwise */ - boolean asChildOf(String traceParentHeader) { + public boolean asChildOf(String traceParentHeader) { traceParentHeader = traceParentHeader.trim(); try { if (traceParentHeader.length() < TEXT_HEADER_EXPECTED_LENGTH) { @@ -354,7 +357,7 @@ && noDashAtPosition(traceParentHeader, TEXT_HEADER_EXPECTED_LENGTH)) { * @param traceParentHeader traceparent binary header value * @return {@literal true} if header value is valid, {@literal false} otherwise */ - boolean asChildOf(byte[] traceParentHeader) { + public boolean asChildOf(byte[] traceParentHeader) { if (logger.isTraceEnabled()) { logger.trace("Binary header content UTF-8-decoded: {}", new String(traceParentHeader, StandardCharsets.UTF_8)); } @@ -435,6 +438,16 @@ public void asChildOf(TraceContext parent) { onMutation(); } + @Override + public void asChildOf(co.elastic.apm.plugin.spi.TraceContext parent) { + asChildOf((TraceContext) parent); + } + + @Override + public void addTraceState(String header) { + traceState.addTextHeader(header); + } + @Override public void resetState() { traceId.resetState(); @@ -799,14 +812,52 @@ public byte getFlags() { return flags; } - public interface ChildContextCreator { + public interface ChildContextCreator extends co.elastic.apm.plugin.spi.ChildContextCreator { boolean asChildOf(TraceContext child, T parent); } - public interface HeaderChildContextCreator { + public static class ChildContextCreatorBridge implements ChildContextCreator { + + private final co.elastic.apm.plugin.spi.ChildContextCreator childContextCreator; + + public ChildContextCreatorBridge(co.elastic.apm.plugin.spi.ChildContextCreator childContextCreator) { + this.childContextCreator = childContextCreator; + } + + @Override + public boolean asChildOf(TraceContext child, T parent) { + return childContextCreator.asChildOf(child, parent); + } + + @Override + public boolean asChildOf(co.elastic.apm.plugin.spi.TraceContext child, T parent) { + return childContextCreator.asChildOf(child, parent); + } + } + + public interface HeaderChildContextCreator extends co.elastic.apm.plugin.spi.HeaderChildContextCreator { boolean asChildOf(TraceContext child, @Nullable C carrier, HeaderGetter headerGetter); } + public static class HeaderChildContextCreatorBridge implements HeaderChildContextCreator { + + private final co.elastic.apm.plugin.spi.HeaderChildContextCreator headerChildContextCreator; + + public HeaderChildContextCreatorBridge(co.elastic.apm.plugin.spi.HeaderChildContextCreator headerChildContextCreator) { + this.headerChildContextCreator = headerChildContextCreator; + } + + @Override + public boolean asChildOf(TraceContext child, @Nullable C carrier, HeaderGetter headerGetter) { + return headerChildContextCreator.asChildOf(child, carrier, headerGetter); + } + + @Override + public boolean asChildOf(co.elastic.apm.plugin.spi.TraceContext child, @Nullable C carrier, co.elastic.apm.plugin.spi.HeaderGetter headerGetter) { + return headerChildContextCreator.asChildOf(child, carrier, headerGetter); + } + } + public TraceContext copy() { final TraceContext copy; final int idLength = id.getLength(); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Transaction.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Transaction.java index 29f792cd6bb..5ebc09fdc57 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Transaction.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Transaction.java @@ -38,7 +38,7 @@ /** * Data captured by an agent representing an event occurring in a monitored service */ -public class Transaction extends AbstractSpan { +public class Transaction extends AbstractSpan implements co.elastic.apm.plugin.spi.Transaction { public static final String TYPE_REQUEST = "request"; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Allocator.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Allocator.java index 87ebd0287b7..dba36100c04 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Allocator.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Allocator.java @@ -23,7 +23,7 @@ * * @param pooled object type */ -public interface Allocator { +public interface Allocator extends co.elastic.apm.plugin.spi.Allocator { /** * @return new instance of pooled object type diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPool.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPool.java index caf85ae2d49..fcc303c675b 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPool.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPool.java @@ -24,7 +24,7 @@ * @param pooled object type. Does not have to implement {@link Recyclable} in order to allow for dealing with objects * that are outside of elastic apm agent (like standard JDK or third party library classes). */ -public interface ObjectPool { +public interface ObjectPool extends co.elastic.apm.plugin.spi.ObjectPool { /** * Tries to reuse any existing instance if pool has any, otherwise creates a new un-pooled instance diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPoolFactory.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPoolFactory.java index f39f1d1e2f8..fee8f397d08 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPoolFactory.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPoolFactory.java @@ -28,10 +28,16 @@ import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; import org.jctools.queues.atomic.MpmcAtomicArrayQueue; -public class ObjectPoolFactory { +public class ObjectPoolFactory implements co.elastic.apm.plugin.spi.ObjectPoolFactory { public static final ObjectPoolFactory INSTANCE = new ObjectPoolFactory(); + @Override + public co.elastic.apm.plugin.spi.ObjectPool createRecyclableObjectPool(int maxCapacity, co.elastic.apm.plugin.spi.Allocator allocator) { + // TODO return QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue((maxCapacity)), false, allocator); + return null; + } + public ObjectPool createRecyclableObjectPool(int maxCapacity, Allocator allocator) { return QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue((maxCapacity)), false, allocator); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Recyclable.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Recyclable.java index ce517f851f0..e376a767b61 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Recyclable.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Recyclable.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.objectpool; -public interface Recyclable { +public interface Recyclable extends co.elastic.apm.plugin.spi.Recyclable { /** * resets pooled object state so it can be reused diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/PotentiallyMultiValuedMap.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/PotentiallyMultiValuedMap.java index 83c918e5192..b1608b8c85a 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/PotentiallyMultiValuedMap.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/PotentiallyMultiValuedMap.java @@ -34,7 +34,7 @@ * {@link #get(String)} will return a collection of values. *

*/ -public class PotentiallyMultiValuedMap implements Recyclable { +public class PotentiallyMultiValuedMap implements Recyclable, co.elastic.apm.plugin.spi.PotentiallyMultiValuedMap { private final List keys; private final List values; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/BinaryHeaderMapAccessor.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/BinaryHeaderMapAccessor.java index 1c1c0a8d1f9..01089474f7b 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/BinaryHeaderMapAccessor.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/BinaryHeaderMapAccessor.java @@ -22,6 +22,7 @@ import co.elastic.apm.agent.impl.transaction.BinaryHeaderSetter; import co.elastic.apm.agent.impl.transaction.HeaderRemover; import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.HeaderGetter; import javax.annotation.Nullable; import java.util.HashMap; @@ -44,7 +45,15 @@ public byte[] getFirstHeader(String headerName, Map headerMap) { } @Override - public void forEach(String headerName, Map carrier, S state, HeaderConsumer consumer) { + public void forEach(String headerName, Map carrier, S state, co.elastic.apm.agent.impl.transaction.HeaderGetter.HeaderConsumer consumer) { + byte[] headerValue = carrier.get(headerName); + if (headerValue != null) { + consumer.accept(headerValue, state); + } + } + + @Override + public void forEach(String headerName, Map carrier, S state, HeaderGetter.HeaderConsumer consumer) { byte[] headerValue = carrier.get(headerName); if (headerValue != null) { consumer.accept(headerValue, state); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/AbstractTextHeaderGetterTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/AbstractTextHeaderGetterTest.java index f1e5bd8ef2b..d77a8d59585 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/AbstractTextHeaderGetterTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/AbstractTextHeaderGetterTest.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.impl.transaction; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import org.junit.jupiter.api.Test; import java.util.ArrayList; diff --git a/apm-agent-plugin-spi/pom.xml b/apm-agent-plugin-spi/pom.xml new file mode 100644 index 00000000000..112155d86c0 --- /dev/null +++ b/apm-agent-plugin-spi/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + co.elastic.apm + apm-agent-parent + 1.36.1-SNAPSHOT + + + apm-agent-plugin-spi + + diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/AbstractContext.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/AbstractContext.java new file mode 100644 index 00000000000..8455ffc648c --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/AbstractContext.java @@ -0,0 +1,6 @@ +package co.elastic.apm.plugin.spi; + +public interface AbstractContext { + + Message getMessage(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/AbstractHeaderGetter.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/AbstractHeaderGetter.java new file mode 100644 index 00000000000..fbe3e504940 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/AbstractHeaderGetter.java @@ -0,0 +1,29 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +public abstract class AbstractHeaderGetter implements HeaderGetter { + @Override + public void forEach(String headerName, C carrier, S state, HeaderConsumer consumer) { + T firstHeader = getFirstHeader(headerName, carrier); + if (firstHeader != null) { + consumer.accept(firstHeader, state); + } + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/AbstractSpan.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/AbstractSpan.java new file mode 100644 index 00000000000..4231446ce6d --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/AbstractSpan.java @@ -0,0 +1,92 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface AbstractSpan> extends ElasticContext { + + int PRIO_USER_SUPPLIED = 1000; + int PRIO_HIGH_LEVEL_FRAMEWORK = 100; + int PRIO_METHOD_SIGNATURE = 100; + int PRIO_LOW_LEVEL_FRAMEWORK = 10; + int PRIO_DEFAULT = 0; + int MAX_ALLOWED_SPAN_LINKS = 1000; + + AbstractContext getContext(); + + boolean isDiscarded(); + + boolean isReferenced(); + + boolean isFinished(); + + boolean isSampled(); + + @Nullable + String getType(); + + @Nullable + StringBuilder getAndOverrideName(int namePriority); + + @Nullable + StringBuilder getAndOverrideName(int namePriority, boolean overrideIfSamePriority); + + void updateName(Class clazz, String methodName); + + void setNonDiscardable(); + + T requestDiscarding(); + + T appendToName(CharSequence cs); + + T appendToName(CharSequence cs, int priority); + + T appendToName(CharSequence cs, int priority, int startIndex, int endIndex); + + T withName(@Nullable String name); + + T withName(@Nullable String name, int priority); + + T withName(@Nullable String name, int priority, boolean overrideIfSamePriority); + + T withType(@Nullable String type); + + T withSync(boolean sync); + + TraceContext getTraceContext(); + + boolean addSpanLink( + HeaderChildContextCreator childContextCreator, + HeaderGetter headerGetter, + @Nullable C carrier + ); + + Span createSpan(); + + Span createSpan(long epochMicros); + + T asExit(); + + T captureException(@Nullable Throwable t); + + void endExceptionally(@Nullable Throwable t); + + void end(); + + void end(long epochMicros); + + boolean propagateTraceContext(C carrier, BinaryHeaderSetter headerSetter); + + void propagateTraceContext(C carrier, TextHeaderSetter headerSetter); + + Outcome getOutcome(); + + T withOutcome(Outcome outcome); + + Span createExitSpan(); + + void incrementReferences(); + + void decrementReferences(); + + int getReferenceCount(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Allocator.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Allocator.java new file mode 100644 index 00000000000..0b71cf27be0 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Allocator.java @@ -0,0 +1,6 @@ +package co.elastic.apm.plugin.spi; + +public interface Allocator { + + T createInstance(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/BinaryHeaderGetter.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/BinaryHeaderGetter.java new file mode 100644 index 00000000000..97e40f827b8 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/BinaryHeaderGetter.java @@ -0,0 +1,4 @@ +package co.elastic.apm.plugin.spi; + +public interface BinaryHeaderGetter extends HeaderGetter { +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/BinaryHeaderSetter.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/BinaryHeaderSetter.java new file mode 100644 index 00000000000..5726da122e7 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/BinaryHeaderSetter.java @@ -0,0 +1,9 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface BinaryHeaderSetter extends HeaderSetter { + + @Nullable + byte[] getFixedLengthByteArray(String headerName, int length); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ChildContextCreator.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ChildContextCreator.java new file mode 100644 index 00000000000..74a533927ff --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ChildContextCreator.java @@ -0,0 +1,5 @@ +package co.elastic.apm.plugin.spi; + +public interface ChildContextCreator { + boolean asChildOf(TraceContext child, T parent); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Cloud.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Cloud.java new file mode 100644 index 00000000000..ab1584be409 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Cloud.java @@ -0,0 +1,8 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface Cloud { + + Cloud withRegion(@Nullable String region); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/CloudOrigin.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/CloudOrigin.java new file mode 100644 index 00000000000..7bef6ca32ca --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/CloudOrigin.java @@ -0,0 +1,14 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface CloudOrigin { + + CloudOrigin withAccountId(@Nullable String accountId); + + CloudOrigin withProvider(@Nullable String provider); + + CloudOrigin withRegion(@Nullable String region); + + CloudOrigin withServiceName(@Nullable String serviceName); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Db.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Db.java new file mode 100644 index 00000000000..fc4abe33234 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Db.java @@ -0,0 +1,19 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.nio.CharBuffer; + +public interface Db { + + Db withInstance(@Nullable String instance); + + Db withType(@Nullable String type); + + Db withStatement(@Nullable String statement); + + Db withUser(@Nullable String user); + + Db withAffectedRowsCount(long returnValue); + + CharBuffer withStatementBuffer(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/DefaultOutcome.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/DefaultOutcome.java new file mode 100644 index 00000000000..f0bc3e0de31 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/DefaultOutcome.java @@ -0,0 +1,7 @@ +package co.elastic.apm.plugin.spi; + +public enum DefaultOutcome implements Outcome { + SUCCESS, + FAILURE, + UNKNOWN +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Destination.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Destination.java new file mode 100644 index 00000000000..236b4d1a8cc --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Destination.java @@ -0,0 +1,23 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketAddress; + +public interface Destination { + + Destination withAddress(@Nullable CharSequence address); + + Destination withInetAddress(InetAddress address); + + Destination withPort(int port); + + Destination withAddressPort(@Nullable String addressPort); + + Destination withInetSocketAddress(InetSocketAddress remoteAddress); + + Destination withSocketAddress(SocketAddress socketAddress); + + Cloud getCloud(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ElasticContext.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ElasticContext.java new file mode 100644 index 00000000000..3fbf58958b5 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ElasticContext.java @@ -0,0 +1,36 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface ElasticContext> { + + T activate(); + + T deactivate(); + + Scope activateInScope(); + + @Nullable + AbstractSpan getSpan(); + + @Nullable + Transaction getTransaction(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ErrorCapture.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ErrorCapture.java new file mode 100644 index 00000000000..409008b815b --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ErrorCapture.java @@ -0,0 +1,4 @@ +package co.elastic.apm.plugin.spi; + +public interface ErrorCapture { +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Faas.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Faas.java new file mode 100644 index 00000000000..f103c00b99e --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Faas.java @@ -0,0 +1,16 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface Faas { + + Faas withColdStart(boolean coldStart); + + Faas withId(@Nullable String id); + + Faas withName(@Nullable String name); + + Faas withVersion(@Nullable String version); + + Faas withExecution(@Nullable String execution); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/GlobalTracer.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/GlobalTracer.java new file mode 100644 index 00000000000..71e598bc18e --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/GlobalTracer.java @@ -0,0 +1,174 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.util.Objects; + +public class GlobalTracer implements Tracer { + + private static final GlobalTracer INSTANCE = new GlobalTracer(); + private volatile Tracer tracer = NoopTracer.INSTANCE; + + private GlobalTracer() { + } + + public static Tracer get() { + return INSTANCE; + } + + @Nullable + public static T get(Class type) { + Tracer tracer = INSTANCE.tracer; + if (type.isInstance(tracer)) { + return type.cast(tracer); + } + return null; + } + + public static T require(Class type) { + return Objects.requireNonNull(get(type), "Registered tracer is not an instance of " + type.getName()); + } + + public static synchronized void init(Tracer tracer) { + if (!isNoop()) { + throw new IllegalStateException("Tracer is already initialized"); + } + INSTANCE.tracer = tracer; + } + + public static boolean isNoop() { + return INSTANCE.tracer == NoopTracer.INSTANCE; + } + + @Nullable + public Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader) { + return tracer.startRootTransaction(initiatingClassLoader); + } + + @Nullable + @Override + public Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader, long epochMicro) { + return tracer.startRootTransaction(initiatingClassLoader, epochMicro); + } + + @Nullable + public Transaction startChildTransaction(@Nullable C headerCarrier, TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader) { + return tracer.startChildTransaction(headerCarrier, textHeadersGetter, initiatingClassLoader); + } + + @Nullable + @Override + public Transaction startChildTransaction(@Nullable C headerCarrier, TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader, long epochMicros) { + return tracer.startChildTransaction(headerCarrier, textHeadersGetter, initiatingClassLoader, epochMicros); + } + + @Nullable + public Transaction startChildTransaction(@Nullable C headerCarrier, BinaryHeaderGetter binaryHeadersGetter, @Nullable ClassLoader initiatingClassLoader) { + return tracer.startChildTransaction(headerCarrier, binaryHeadersGetter, initiatingClassLoader); + } + + @Nullable + public Transaction currentTransaction() { + return tracer.currentTransaction(); + } + + @Nullable + @Override + public AbstractSpan getActive() { + return tracer.getActive(); + } + + @Nullable + @Override + public Span getActiveSpan() { + return tracer.getActiveSpan(); + } + + public void captureAndReportException(@Nullable Throwable e, ClassLoader initiatingClassLoader) { + tracer.captureAndReportException(e, initiatingClassLoader); + } + + @Nullable + public String captureAndReportException(long epochMicros, @Nullable Throwable e, @Nullable AbstractSpan parent) { + return tracer.captureAndReportException(epochMicros, e, parent); + } + + @Nullable + public ErrorCapture captureException(@Nullable Throwable e, @Nullable AbstractSpan parent, @Nullable ClassLoader initiatingClassLoader) { + return tracer.captureException(e, parent, initiatingClassLoader); + } + + @Nullable + @Override + public Span getActiveExitSpan() { + return tracer.getActiveExitSpan(); + } + + @Nullable + @Override + public Span createExitChildSpan() { + return tracer.createExitChildSpan(); + } + + @Override + public void endSpan(Span span) { + tracer.endSpan(span); + } + + @Override + public void endTransaction(Transaction transaction) { + tracer.endTransaction(transaction); + } + + @Override + public void endError(ErrorCapture errorCapture) { + tracer.endError(errorCapture); + } + + @Override + public T getConfig(Class configuration) { + return tracer.getConfig(configuration); + } + + @Override + public ObjectPoolFactory getObjectPoolFactory() { + return tracer.getObjectPoolFactory(); + } + + @Override + public boolean isRunning() { + return tracer.isRunning(); + } + + @Override + public void setServiceInfoForClassLoader(ClassLoader classLoader, ServiceInfo serviceInfo) { + tracer.setServiceInfoForClassLoader(classLoader, serviceInfo); + } + + @Override + public ServiceInfo getServiceInfoForClassLoader(ClassLoader classLoader) { + return tracer.getServiceInfoForClassLoader(classLoader); + } + + @Override + public ServiceInfo autoDetectedServiceName() { + return tracer.autoDetectedServiceName(); + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/HeaderChildContextCreator.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/HeaderChildContextCreator.java new file mode 100644 index 00000000000..4a31ddfc52c --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/HeaderChildContextCreator.java @@ -0,0 +1,7 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface HeaderChildContextCreator { + boolean asChildOf(TraceContext child, @Nullable C carrier, HeaderGetter headerGetter); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/HeaderGetter.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/HeaderGetter.java new file mode 100644 index 00000000000..04fac5c3719 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/HeaderGetter.java @@ -0,0 +1,33 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface HeaderGetter { + + @Nullable + T getFirstHeader(String headerName, C carrier); + + void forEach(String headerName, C carrier, S state, HeaderConsumer consumer); + + interface HeaderConsumer { + void accept(@Nullable T headerValue, S state); + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/HeaderRemover.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/HeaderRemover.java new file mode 100644 index 00000000000..8c302d5f129 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/HeaderRemover.java @@ -0,0 +1,24 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +public interface HeaderRemover { + + void remove(String headerName, C carrier); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/HeaderSetter.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/HeaderSetter.java new file mode 100644 index 00000000000..f56f7bfdd28 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/HeaderSetter.java @@ -0,0 +1,24 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +public interface HeaderSetter { + + void setHeader(String headerName, T headerValue, C carrier); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Http.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Http.java new file mode 100644 index 00000000000..943a183fb44 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Http.java @@ -0,0 +1,17 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface Http { + + Http withUrl(@Nullable String url); + + Http withMethod(String method); + + Http withStatusCode(int statusCode); + + CharSequence getUrl(); + + @Nullable + String getMethod(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Id.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Id.java new file mode 100644 index 00000000000..7de610830ef --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Id.java @@ -0,0 +1,7 @@ +package co.elastic.apm.plugin.spi; + +public interface Id { + boolean isEmpty(); + + void setToRandomValue(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Message.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Message.java new file mode 100644 index 00000000000..10ce40ad6c2 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Message.java @@ -0,0 +1,20 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface Message { + + Message withAge(long age); + + Message withBody(@Nullable String body); + + Message withRoutingKey(String routingKey); + + Message withQueue(@Nullable String queueName); + + Message addHeader(@Nullable String key, @Nullable String value); + + Message addHeader(@Nullable String key, @Nullable byte[] value); + + Message appendToBody(CharSequence bodyContent); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/NoopTracer.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/NoopTracer.java new file mode 100644 index 00000000000..d292dc0a28a --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/NoopTracer.java @@ -0,0 +1,128 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +class NoopTracer implements Tracer { + + static final Tracer INSTANCE = new NoopTracer(); + + private NoopTracer() { + } + + @Nullable + @Override + public Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader) { + return null; + } + + @Nullable + @Override + public Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader, long epochMicro) { + return null; + } + + @Nullable + @Override + public Transaction startChildTransaction(@Nullable C headerCarrier, TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader) { + return null; + } + + @Nullable + @Override + public Transaction startChildTransaction(@Nullable C headerCarrier, TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader, long epochMicros) { + return null; + } + + @Nullable + @Override + public Transaction startChildTransaction(@Nullable C headerCarrier, BinaryHeaderGetter binaryHeadersGetter, @Nullable ClassLoader initiatingClassLoader) { + return null; + } + + @Nullable + @Override + public Transaction currentTransaction() { + return null; + } + + @Nullable + @Override + public AbstractSpan getActive() { + return null; + } + + @Nullable + @Override + public Span getActiveSpan() { + return null; + } + + @Override + public void captureAndReportException(@Nullable Throwable e, ClassLoader initiatingClassLoader) { + } + + @Nullable + @Override + public String captureAndReportException(long epochMicros, @Nullable Throwable e, @Nullable AbstractSpan parent) { + return null; + } + + @Nullable + @Override + public ErrorCapture captureException(@Nullable Throwable e, @Nullable AbstractSpan parent, @Nullable ClassLoader initiatingClassLoader) { + return null; + } + + @Nullable + @Override + public Span getActiveExitSpan() { + return null; + } + + @Nullable + @Override + public Span createExitChildSpan() { + return null; + } + + @Override + public void endSpan(Span span) { + } + + @Override + public void endTransaction(Transaction transaction) { + } + + @Override + public void endError(ErrorCapture errorCapture) { + } + + @Override + public T getConfig(Class configuration) { + return null; + } + + @Override + public ObjectPoolFactory getObjectPoolFactory() { + return null; + } + + @Override + public boolean isRunning() { + return false; + } + + @Override + public void setServiceInfoForClassLoader(ClassLoader classLoader, ServiceInfo serviceInfo) { + } + + @Override + public ServiceInfo getServiceInfoForClassLoader(ClassLoader classLoader) { + return null; + } + + @Override + public ServiceInfo autoDetectedServiceName() { + return null; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ObjectPool.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ObjectPool.java new file mode 100644 index 00000000000..8e6159d1486 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ObjectPool.java @@ -0,0 +1,28 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +public interface ObjectPool { + + T createInstance(); + + void recycle(T obj); + + void clear(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ObjectPoolFactory.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ObjectPoolFactory.java new file mode 100644 index 00000000000..245c332ea4c --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ObjectPoolFactory.java @@ -0,0 +1,6 @@ +package co.elastic.apm.plugin.spi; + +public interface ObjectPoolFactory { + + ObjectPool createRecyclableObjectPool(int maxCapacity, Allocator allocator); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Outcome.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Outcome.java new file mode 100644 index 00000000000..71976521b40 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Outcome.java @@ -0,0 +1,24 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +public interface Outcome { + + String name(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/PotentiallyMultiValuedMap.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/PotentiallyMultiValuedMap.java new file mode 100644 index 00000000000..e63e9c7e84a --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/PotentiallyMultiValuedMap.java @@ -0,0 +1,50 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.util.List; + +public interface PotentiallyMultiValuedMap extends Recyclable { + void add(String key, String value); + + void set(String key, String... values); + + @Nullable + String getFirst(String key); + + @Nullable + Object get(String key); + + List getAll(String key); + + boolean isEmpty(); + + String getKey(int i); + + Object getValue(int i); + + int size(); + + void removeIgnoreCase(String key); + + void set(int index, String value); + + boolean containsIgnoreCase(String key); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Recyclable.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Recyclable.java new file mode 100644 index 00000000000..e26c6c33388 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Recyclable.java @@ -0,0 +1,6 @@ +package co.elastic.apm.plugin.spi; + +public interface Recyclable { + + void resetState(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Request.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Request.java new file mode 100644 index 00000000000..51e6cab00c6 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Request.java @@ -0,0 +1,37 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.nio.CharBuffer; +import java.util.Enumeration; + +public interface Request { + boolean hasContent(); + + Request withMethod(@Nullable String method); + + Socket getSocket(); + + Url getUrl(); + + PotentiallyMultiValuedMap getHeaders(); + + PotentiallyMultiValuedMap getCookies(); + + Request withHttpVersion(@Nullable String httpVersion); + + CharBuffer withBodyBuffer(); + + void redactBody(); + + Request addFormUrlEncodedParameters(String key, String[] values); + + Request addHeader(String headerName, @Nullable Enumeration headerValues); + + Request addCookie(String cookieName, String cookieValue); + + CharBuffer getBodyBuffer(); + + void endOfBufferInput(); + + void setRawBody(String rawBody); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Response.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Response.java new file mode 100644 index 00000000000..7eb26ba4ed1 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Response.java @@ -0,0 +1,17 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.util.Collection; + +public interface Response { + + PotentiallyMultiValuedMap getHeaders(); + + Response withFinished(boolean finished); + + Response withStatusCode(int statusCode); + + Response withHeadersSent(boolean headersSent); + + Response addHeader(String headerName, @Nullable Collection headerValues); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ResultUtil.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ResultUtil.java new file mode 100644 index 00000000000..a47b3f514de --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ResultUtil.java @@ -0,0 +1,58 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public class ResultUtil { + + @Nullable + public static String getResultByHttpStatus(int status) { + if (status >= 200 && status < 300) { + return "HTTP 2xx"; + } + if (status >= 300 && status < 400) { + return "HTTP 3xx"; + } + if (status >= 400 && status < 500) { + return "HTTP 4xx"; + } + if (status >= 500 && status < 600) { + return "HTTP 5xx"; + } + if (status >= 100 && status < 200) { + return "HTTP 1xx"; + } + return null; + } + + public static Outcome getOutcomeByHttpClientStatus(int status) { + if (status < 100 || status >= 600) { + return DefaultOutcome.FAILURE; + } + return status < 400 ? DefaultOutcome.SUCCESS : DefaultOutcome.FAILURE; + } + + public static Outcome getOutcomeByHttpServerStatus(int status) { + if (status < 100 || status >= 600) { + return DefaultOutcome.FAILURE; + } + return status < 500 ? DefaultOutcome.SUCCESS : DefaultOutcome.FAILURE; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Scope.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Scope.java new file mode 100644 index 00000000000..0b44fe59273 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Scope.java @@ -0,0 +1,25 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +public interface Scope extends AutoCloseable { + + @Override + void close(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ServiceInfo.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ServiceInfo.java new file mode 100644 index 00000000000..214f8486651 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ServiceInfo.java @@ -0,0 +1,141 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.util.Objects; +import java.util.jar.Attributes; +import java.util.jar.Manifest; + +public class ServiceInfo { + + private static final String DEFAULT_SERVICE_NAME = "unknown-java-service"; + private static final ServiceInfo EMPTY = new ServiceInfo(null, null); + + protected final String serviceName; + @Nullable + protected final String serviceVersion; + protected final boolean multiServiceContainer; + + public ServiceInfo(@Nullable String serviceName) { + this(serviceName, null); + } + + private ServiceInfo(@Nullable String serviceName, @Nullable String serviceVersion) { + this(serviceName, serviceVersion, false); + } + + protected ServiceInfo(@Nullable String serviceName, @Nullable String serviceVersion, boolean multiServiceContainer) { + this.multiServiceContainer = multiServiceContainer; + if (serviceName == null || serviceName.trim().isEmpty()) { + this.serviceName = DEFAULT_SERVICE_NAME; + } else { + this.serviceName = replaceDisallowedServiceNameChars(serviceName).trim(); + } + this.serviceVersion = serviceVersion; + } + + public static ServiceInfo empty() { + return EMPTY; + } + + public static ServiceInfo of(@Nullable String serviceName) { + return of(serviceName, null); + } + + public static ServiceInfo of(@Nullable String serviceName, @Nullable String serviceVersion) { + if ((serviceName == null || serviceName.isEmpty()) && + (serviceVersion == null || serviceVersion.isEmpty())) { + return empty(); + } + return new ServiceInfo(serviceName, serviceVersion); + } + + private static String replaceDisallowedServiceNameChars(String serviceName) { + return serviceName.replaceAll("[^a-zA-Z0-9 _-]", "-"); + } + + public static ServiceInfo fromManifest(@Nullable Manifest manifest) { + if (manifest == null) { + return ServiceInfo.empty(); + } + Attributes mainAttributes = manifest.getMainAttributes(); + return ServiceInfo.of( + mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_TITLE), + mainAttributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION)); + } + + public static ServiceInfo autoDetected() { + return null; // TODO + } + + public String getServiceName() { + return serviceName; + } + + @Nullable + public String getServiceVersion() { + return serviceVersion; + } + + /** + * Returns true if the service is a container service that can host multiple other applications. + * For example, an application server or servlet container. + * A standalone application that's built on embedded Tomcat, for example, would return {@code false}. + */ + public boolean isMultiServiceContainer() { + return multiServiceContainer; + } + + public ServiceInfo withFallback(ServiceInfo fallback) { + return ServiceInfo.of( + hasServiceName() ? serviceName : fallback.serviceName, + serviceVersion != null ? serviceVersion : fallback.serviceVersion); + } + + public boolean hasServiceName() { + return !serviceName.equals(DEFAULT_SERVICE_NAME); + } + + public boolean isEmpty() { + return !hasServiceName() && serviceVersion == null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ServiceInfo that = (ServiceInfo) o; + return multiServiceContainer == that.multiServiceContainer && serviceName.equals(that.serviceName) && Objects.equals(serviceVersion, that.serviceVersion); + } + + @Override + public int hashCode() { + return Objects.hash(serviceName, serviceVersion, multiServiceContainer); + } + + @Override + public String toString() { + return "ServiceInfo{" + + "serviceName='" + serviceName + '\'' + + ", serviceVersion='" + serviceVersion + '\'' + + ", multiServiceContainer=" + multiServiceContainer + + '}'; + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ServiceTarget.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ServiceTarget.java new file mode 100644 index 00000000000..5baa307d672 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/ServiceTarget.java @@ -0,0 +1,15 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface ServiceTarget { + ServiceTarget withType(@Nullable String type); + + ServiceTarget withName(@Nullable CharSequence name); + + ServiceTarget withUserName(@Nullable CharSequence name); + + ServiceTarget withHostPortName(@Nullable CharSequence host, int port); + + ServiceTarget withNameOnlyDestinationResource(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Socket.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Socket.java new file mode 100644 index 00000000000..81af77b1293 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Socket.java @@ -0,0 +1,8 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface Socket { + + Socket withRemoteAddress(@Nullable String remoteAddress); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Span.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Span.java new file mode 100644 index 00000000000..2822c004c7a --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Span.java @@ -0,0 +1,26 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.util.concurrent.TimeUnit; + +public interface Span> extends AbstractSpan { + + long MAX_LOG_INTERVAL_MICRO_SECS = TimeUnit.MINUTES.toMicros(5); + + SpanContext getContext(); + + @Nullable + String getSubtype(); + + boolean isExit(); + + @Nullable + String getAction(); + + T withAction(@Nullable String action); + + T withSubtype(@Nullable String subtype); + + @Deprecated + void setType(@Nullable String type, @Nullable String subtype, @Nullable String action); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/SpanContext.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/SpanContext.java new file mode 100644 index 00000000000..f41509fe601 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/SpanContext.java @@ -0,0 +1,12 @@ +package co.elastic.apm.plugin.spi; + +public interface SpanContext extends AbstractContext { + + ServiceTarget getServiceTarget(); + + Destination getDestination(); + + Db getDb(); + + Http getHttp(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TextHeaderGetter.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TextHeaderGetter.java new file mode 100644 index 00000000000..40481bc3ece --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TextHeaderGetter.java @@ -0,0 +1,4 @@ +package co.elastic.apm.plugin.spi; + +public interface TextHeaderGetter extends HeaderGetter { +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TextHeaderSetter.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TextHeaderSetter.java new file mode 100644 index 00000000000..b35c921001c --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TextHeaderSetter.java @@ -0,0 +1,22 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +public interface TextHeaderSetter extends HeaderSetter { +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TraceContext.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TraceContext.java new file mode 100644 index 00000000000..5863893795d --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TraceContext.java @@ -0,0 +1,32 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface TraceContext { + + String ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME = "elastic-apm-traceparent"; + String W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME = "traceparent"; + String TRACESTATE_HEADER_NAME = "tracestate"; + public static final int SERIALIZED_LENGTH = 42; + + String TRACE_PARENT_BINARY_HEADER_NAME = "elasticapmtraceparent"; + int BINARY_FORMAT_EXPECTED_LENGTH = 29; + + Id getTraceId(); + + Id getId(); + + Id getParentId(); + + Id getTransactionId(); + + void setServiceInfo(@Nullable String serviceName, @Nullable String serviceVersion); + + boolean asChildOf(byte[] parent); + + boolean asChildOf(String parent); + + void asChildOf(TraceContext parent); + + void addTraceState(String header); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TraceContextUtil.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TraceContextUtil.java new file mode 100644 index 00000000000..c10df38d653 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TraceContextUtil.java @@ -0,0 +1,145 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public class TraceContextUtil { + + private static final ChildContextCreator FROM_PARENT_CONTEXT = new ChildContextCreator() { + @Override + public boolean asChildOf(TraceContext child, TraceContext parent) { + child.asChildOf(parent); + return true; + } + }; + private static final ChildContextCreator> FROM_PARENT = new ChildContextCreator>() { + @Override + public boolean asChildOf(TraceContext child, AbstractSpan parent) { + child.asChildOf(parent.getTraceContext()); + return true; + } + }; + private static final HeaderGetter.HeaderConsumer TRACESTATE_HEADER_CONSUMER = new HeaderGetter.HeaderConsumer() { + @Override + public void accept(@Nullable String tracestateHeaderValue, TraceContext state) { + if (tracestateHeaderValue != null) { + state.addTraceState(tracestateHeaderValue); + } + } + }; + private static final HeaderChildContextCreator FROM_TRACE_CONTEXT_TEXT_HEADERS = + new HeaderChildContextCreator() { + @Override + public boolean asChildOf(TraceContext child, @Nullable Object carrier, HeaderGetter traceContextHeaderGetter) { + if (carrier == null) { + return false; + } + + boolean isValid = false; + String traceparent = traceContextHeaderGetter.getFirstHeader(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, carrier); + if (traceparent != null) { + isValid = child.asChildOf(traceparent); + } + + if (!isValid) { + // Look for the legacy Elastic traceparent header (in case this comes from an older agent) + traceparent = traceContextHeaderGetter.getFirstHeader(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, carrier); + if (traceparent != null) { + isValid = child.asChildOf(traceparent); + } + } + + if (isValid) { + // as per spec, the tracestate header can be multi-valued + traceContextHeaderGetter.forEach(TraceContext.TRACESTATE_HEADER_NAME, carrier, child, TRACESTATE_HEADER_CONSUMER); + } + + return isValid; + } + }; + private static final HeaderChildContextCreator FROM_TRACE_CONTEXT_BINARY_HEADERS = + new HeaderChildContextCreator() { + @Override + public boolean asChildOf(TraceContext child, @Nullable Object carrier, HeaderGetter traceContextHeaderGetter) { + if (carrier == null) { + return false; + } + byte[] traceparent = traceContextHeaderGetter.getFirstHeader(TraceContext.TRACE_PARENT_BINARY_HEADER_NAME, carrier); + if (traceparent != null) { + return child.asChildOf(traceparent); + } + return false; + } + }; + private static final ChildContextCreator FROM_ACTIVE = new ChildContextCreator() { + @Override + public boolean asChildOf(TraceContext child, Tracer tracer) { + final AbstractSpan active = tracer.getActive(); + if (active != null) { + return fromParent().asChildOf(child, active); + + } + return false; + } + }; + private static final ChildContextCreator AS_ROOT = new ChildContextCreator() { + @Override + public boolean asChildOf(TraceContext child, Object ignore) { + return false; + } + }; + + private TraceContextUtil() { + } + + @SuppressWarnings("unchecked") + public static HeaderChildContextCreator getFromTraceContextTextHeaders() { + return (HeaderChildContextCreator) FROM_TRACE_CONTEXT_TEXT_HEADERS; + } + + @SuppressWarnings("unchecked") + public static HeaderChildContextCreator getFromTraceContextBinaryHeaders() { + return (HeaderChildContextCreator) FROM_TRACE_CONTEXT_BINARY_HEADERS; + } + + public static ChildContextCreator fromActive() { + return FROM_ACTIVE; + } + + public static ChildContextCreator fromParentContext() { + return FROM_PARENT_CONTEXT; + } + + public static ChildContextCreator> fromParent() { + return FROM_PARENT; + } + + public static ChildContextCreator asRoot() { + return AS_ROOT; + } + + public static void copyTraceContextTextHeaders(S source, TextHeaderGetter headerGetter, D destination, TextHeaderSetter headerSetter) { + String w3cApmTraceParent = headerGetter.getFirstHeader(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, source); + if (w3cApmTraceParent != null) { + headerSetter.setHeader(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, w3cApmTraceParent, destination); + } + String elasticApmTraceParent = headerGetter.getFirstHeader(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, source); + if (elasticApmTraceParent != null) { + headerSetter.setHeader(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, elasticApmTraceParent, destination); + } + String tracestate = headerGetter.getFirstHeader(TraceContext.TRACESTATE_HEADER_NAME, source); + if (tracestate != null) { + headerSetter.setHeader(TraceContext.TRACESTATE_HEADER_NAME, tracestate, destination); + } + } + + public static boolean containsTraceContextTextHeaders(C carrier, TextHeaderGetter headerGetter) { + return headerGetter.getFirstHeader(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, carrier) != null; + } + + public static void removeTraceContextHeaders(C carrier, HeaderRemover headerRemover) { + headerRemover.remove(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, carrier); + headerRemover.remove(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, carrier); + headerRemover.remove(TraceContext.TRACESTATE_HEADER_NAME, carrier); + headerRemover.remove(TraceContext.TRACE_PARENT_BINARY_HEADER_NAME, carrier); + } +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Tracer.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Tracer.java new file mode 100644 index 00000000000..c91cb04402e --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Tracer.java @@ -0,0 +1,80 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface Tracer { + + @Nullable + Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader); + + @Nullable + Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader, long epochMicro); + + @Nullable + Transaction startChildTransaction(@Nullable C headerCarrier, TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader); + + @Nullable + Transaction startChildTransaction(@Nullable C headerCarrier, TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader, long epochMicros); + + @Nullable + Transaction startChildTransaction(@Nullable C headerCarrier, BinaryHeaderGetter binaryHeadersGetter, @Nullable ClassLoader initiatingClassLoader); + + @Nullable + Transaction currentTransaction(); + + @Nullable + AbstractSpan getActive(); + + @Nullable + Span getActiveSpan(); + + void captureAndReportException(@Nullable Throwable e, ClassLoader initiatingClassLoader); + + @Nullable + String captureAndReportException(long epochMicros, @Nullable Throwable e, @Nullable AbstractSpan parent); + + @Nullable + ErrorCapture captureException(@Nullable Throwable e, @Nullable AbstractSpan parent, @Nullable ClassLoader initiatingClassLoader); + + @Nullable + Span getActiveExitSpan(); + + @Nullable + Span createExitChildSpan(); + + void endSpan(Span span); + + void endTransaction(Transaction transaction); + + void endError(ErrorCapture errorCapture); + + T getConfig(Class configuration); + + ObjectPoolFactory getObjectPoolFactory(); + + boolean isRunning(); + + void setServiceInfoForClassLoader(ClassLoader classLoader, ServiceInfo serviceInfo); + + ServiceInfo getServiceInfoForClassLoader(ClassLoader classLoader); + + ServiceInfo autoDetectedServiceName(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Transaction.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Transaction.java new file mode 100644 index 00000000000..98fc2b5de38 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Transaction.java @@ -0,0 +1,38 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; + +public interface Transaction> extends AbstractSpan { + + String TYPE_REQUEST = "request"; + + TransactionContext getContext(); + + boolean isNoop(); + + void ignoreTransaction(); + + void addCustomContext(String key, String value); + + void addCustomContext(String key, Number value); + + void addCustomContext(String key, Boolean value); + + void setFrameworkName(@Nullable String frameworkName); + + void setUserFrameworkName(@Nullable String frameworkName); + + T captureException(@Nullable Throwable thrown); + + T withResult(@Nullable String result); + + T withResultIfUnset(@Nullable String result); + + String getType(); + + void setFrameworkVersion(@Nullable String frameworkVersion); + + Faas getFaas(); + + void setUser(String id, String email, String username, String domain); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TransactionContext.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TransactionContext.java new file mode 100644 index 00000000000..384c6786b78 --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/TransactionContext.java @@ -0,0 +1,12 @@ +package co.elastic.apm.plugin.spi; + +public interface TransactionContext extends AbstractContext { + + Request getRequest(); + + Response getResponse(); + + User getUser(); + + CloudOrigin getCloudOrigin(); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Url.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Url.java new file mode 100644 index 00000000000..406e71e295e --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/Url.java @@ -0,0 +1,21 @@ +package co.elastic.apm.plugin.spi; + +import javax.annotation.Nullable; +import java.net.URI; + +public interface Url { + + void fillFrom(URI uri); + + void fillFrom(@Nullable String scheme, @Nullable String serverName, int serverPort, @Nullable String requestURI, @Nullable String queryString); + + Url withProtocol(@Nullable String protocol); + + Url withHostname(@Nullable String hostname); + + Url withPort(int port); + + Url withPathname(@Nullable String pathname); + + Url withSearch(@Nullable String search); +} diff --git a/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/User.java b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/User.java new file mode 100644 index 00000000000..9d2dd7e6ecf --- /dev/null +++ b/apm-agent-plugin-spi/src/main/java/co/elastic/apm/plugin/spi/User.java @@ -0,0 +1,7 @@ +package co.elastic.apm.plugin.spi; + +public interface User { + String getUsername(); + + User withUsername(String userName); +} diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/src/main/java/co/elastic/apm/agent/httpclient/v3/HttpClient3Instrumentation.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/src/main/java/co/elastic/apm/agent/httpclient/v3/HttpClient3Instrumentation.java index b0614356d83..ecbab16d8d8 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/src/main/java/co/elastic/apm/agent/httpclient/v3/HttpClient3Instrumentation.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/src/main/java/co/elastic/apm/agent/httpclient/v3/HttpClient3Instrumentation.java @@ -20,10 +20,7 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.util.LoggerUtils; @@ -115,16 +112,16 @@ public static Object onEnter(@Advice.Argument(0) HttpMethod httpMethod, } } - Span span = HttpClientHelper.startHttpClientSpan(parent, httpMethod.getName(), uri, protocol, host, port); + Span span = HttpClientHelper.startHttpClientSpan(parent, httpMethod.getName(), uri, protocol, host, port); if (span != null) { span.activate(); } - if (!TraceContext.containsTraceContextTextHeaders(httpMethod, HttpClient3RequestHeaderAccessor.INSTANCE)) { + if (!TraceContextUtil.containsTraceContextTextHeaders(httpMethod, HttpClient3RequestHeaderAccessor.INSTANCE)) { if (span != null) { span.propagateTraceContext(httpMethod, HttpClient3RequestHeaderAccessor.INSTANCE); - } else if (!TraceContext.containsTraceContextTextHeaders(httpMethod, HttpClient3RequestHeaderAccessor.INSTANCE)) { + } else if (!TraceContextUtil.containsTraceContextTextHeaders(httpMethod, HttpClient3RequestHeaderAccessor.INSTANCE)) { // re-adds the header on redirects parent.propagateTraceContext(httpMethod, HttpClient3RequestHeaderAccessor.INSTANCE); } @@ -138,11 +135,11 @@ public static void onExit(@Advice.Thrown @Nullable Throwable thrown, @Advice.Argument(0) HttpMethod httpMethod, @Advice.Enter @Nullable Object enterSpan) { - if (!(enterSpan instanceof Span)) { + if (!(enterSpan instanceof Span)) { return; } - Span span = (Span) enterSpan; + Span span = (Span) enterSpan; StatusLine statusLine = httpMethod.getStatusLine(); if (null != statusLine) { @@ -150,7 +147,7 @@ public static void onExit(@Advice.Thrown @Nullable Throwable thrown, } if (thrown instanceof CircularRedirectException) { - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } span.captureException(thrown) diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/src/main/java/co/elastic/apm/agent/httpclient/v3/HttpClient3RequestHeaderAccessor.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/src/main/java/co/elastic/apm/agent/httpclient/v3/HttpClient3RequestHeaderAccessor.java index 0f02a8a94ae..748e24738cf 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/src/main/java/co/elastic/apm/agent/httpclient/v3/HttpClient3RequestHeaderAccessor.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/src/main/java/co/elastic/apm/agent/httpclient/v3/HttpClient3RequestHeaderAccessor.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.httpclient.v3; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpMethod; diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpAsyncClientInstrumentation.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpAsyncClientInstrumentation.java index 2cc40830873..12c8898b45d 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpAsyncClientInstrumentation.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpAsyncClientInstrumentation.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.httpclient.HttpClientHelper; import co.elastic.apm.agent.httpclient.v4.helper.ApacheHttpAsyncClientHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument; import net.bytebuddy.description.NamedElement; @@ -93,7 +93,7 @@ public static Object[] onBeforeExecute(@Advice.Argument(value = 0) HttpAsyncRequ if (parent == null) { return null; } - Span span = parent.createExitSpan(); + Span span = parent.createExitSpan(); HttpAsyncRequestProducer wrappedProducer = requestProducer; FutureCallback wrappedFutureCallback = futureCallback; boolean responseFutureWrapped = false; @@ -114,7 +114,7 @@ public static Object[] onBeforeExecute(@Advice.Argument(value = 0) HttpAsyncRequ @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void onAfterExecute(@Advice.Enter @Nullable Object[] enter, @Advice.Thrown @Nullable Throwable t) { - Span span = enter != null ? (Span) enter[3] : null; + Span span = enter != null ? (Span) enter[3] : null; if (span != null) { // Deactivate in this thread. Span will be ended and reported by the listener span.deactivate(); diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpAsyncClientRedirectInstrumentation.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpAsyncClientRedirectInstrumentation.java index aacfb1cdf24..95ba61c23ca 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpAsyncClientRedirectInstrumentation.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpAsyncClientRedirectInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.httpclient.v4; import co.elastic.apm.agent.httpclient.v4.helper.RequestHeaderAccessor; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.TraceContextUtil; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -49,8 +49,8 @@ public static void onAfterExecute(@Advice.Argument(value = 0) HttpRequest origin return; } // org.apache.http.HttpMessage#containsHeader implementations do not allocate iterator since 4.0.1 - if (TraceContext.containsTraceContextTextHeaders(original, RequestHeaderAccessor.INSTANCE) && !TraceContext.containsTraceContextTextHeaders(redirect, RequestHeaderAccessor.INSTANCE)) { - TraceContext.copyTraceContextTextHeaders(original, RequestHeaderAccessor.INSTANCE, redirect, RequestHeaderAccessor.INSTANCE); + if (TraceContextUtil.containsTraceContextTextHeaders(original, RequestHeaderAccessor.INSTANCE) && !TraceContextUtil.containsTraceContextTextHeaders(redirect, RequestHeaderAccessor.INSTANCE)) { + TraceContextUtil.copyTraceContextTextHeaders(original, RequestHeaderAccessor.INSTANCE, redirect, RequestHeaderAccessor.INSTANCE); } } } diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpClientInstrumentation.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpClientInstrumentation.java index 079b69b11c3..712c725507c 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpClientInstrumentation.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpClientInstrumentation.java @@ -20,10 +20,7 @@ import co.elastic.apm.agent.httpclient.HttpClientHelper; import co.elastic.apm.agent.httpclient.v4.helper.RequestHeaderAccessor; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.*; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -58,16 +55,16 @@ public static Object onBeforeExecute(@Advice.Argument(0) HttpRoute route, if (parent == null) { return null; } - Span span = HttpClientHelper.startHttpClientSpan(parent, request.getMethod(), request.getURI(), route.getTargetHost().getHostName()); + Span span = HttpClientHelper.startHttpClientSpan(parent, request.getMethod(), request.getURI(), route.getTargetHost().getHostName()); if (span != null) { span.activate(); } - if (!TraceContext.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { + if (!TraceContextUtil.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { if (span != null) { span.propagateTraceContext(request, RequestHeaderAccessor.INSTANCE); - } else if (!TraceContext.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { + } else if (!TraceContextUtil.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { // re-adds the header on redirects parent.propagateTraceContext(request, RequestHeaderAccessor.INSTANCE); } @@ -80,7 +77,7 @@ public static Object onBeforeExecute(@Advice.Argument(0) HttpRoute route, public static void onAfterExecute(@Advice.Return @Nullable CloseableHttpResponse response, @Advice.Enter @Nullable Object spanObj, @Advice.Thrown @Nullable Throwable t) { - Span span = (Span) spanObj; + Span span = (Span) spanObj; if (span == null) { return; } @@ -94,7 +91,7 @@ public static void onAfterExecute(@Advice.Return @Nullable CloseableHttpResponse // in case of circular redirect, we get an exception but status code won't be available without response // thus we have to deal with span outcome directly if (t instanceof CircularRedirectException) { - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } span.deactivate().end(); diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientInstrumentation.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientInstrumentation.java index 4f59480cc13..90e15eed55e 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientInstrumentation.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientInstrumentation.java @@ -20,10 +20,7 @@ import co.elastic.apm.agent.httpclient.HttpClientHelper; import co.elastic.apm.agent.httpclient.v4.helper.RequestHeaderAccessor; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.*; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -100,16 +97,16 @@ public static Object onBeforeExecute(@Advice.Argument(0) @Nullable HttpHost host } catch (URISyntaxException ignore) { } } - Span span = HttpClientHelper.startHttpClientSpan(parent, method, uri, hostName); + Span span = HttpClientHelper.startHttpClientSpan(parent, method, uri, hostName); if (span != null) { span.activate(); } - if (!TraceContext.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { + if (!TraceContextUtil.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { if (span != null) { span.propagateTraceContext(request, RequestHeaderAccessor.INSTANCE); - } else if (!TraceContext.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { + } else if (!TraceContextUtil.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { // re-adds the header on redirects parent.propagateTraceContext(request, RequestHeaderAccessor.INSTANCE); } @@ -122,7 +119,7 @@ public static Object onBeforeExecute(@Advice.Argument(0) @Nullable HttpHost host public static void onAfterExecute(@Advice.Return @Nullable HttpResponse response, @Advice.Enter @Nullable Object spanObj, @Advice.Thrown @Nullable Throwable t) { - Span span = (Span) spanObj; + Span span = (Span) spanObj; if (span == null) { return; } @@ -136,7 +133,7 @@ public static void onAfterExecute(@Advice.Return @Nullable HttpResponse response // in case of circular redirect, we get an exception but status code won't be available without response // thus we have to deal with span outcome directly if (t instanceof CircularRedirectException) { - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } span.deactivate().end(); diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/ApacheHttpAsyncClientHelper.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/ApacheHttpAsyncClientHelper.java index 39dd0b4b5cd..6d21c5b46a5 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/ApacheHttpAsyncClientHelper.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/ApacheHttpAsyncClientHelper.java @@ -18,12 +18,7 @@ */ package co.elastic.apm.agent.httpclient.v4.helper; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.objectpool.Allocator; -import co.elastic.apm.agent.objectpool.ObjectPool; -import co.elastic.apm.agent.objectpool.ObjectPoolFactory; +import co.elastic.apm.plugin.spi.*; import org.apache.http.concurrent.FutureCallback; import org.apache.http.nio.protocol.HttpAsyncRequestProducer; import org.apache.http.protocol.HttpContext; @@ -53,16 +48,17 @@ public HttpAsyncRequestProducerWrapper createInstance() { private class FutureCallbackWrapperAllocator implements Allocator> { @Override public FutureCallbackWrapper createInstance() { - return new FutureCallbackWrapper(ApacheHttpAsyncClientHelper.this); + return new FutureCallbackWrapper(ApacheHttpAsyncClientHelper.this); } } - public HttpAsyncRequestProducer wrapRequestProducer(HttpAsyncRequestProducer requestProducer, @Nullable Span span, + public HttpAsyncRequestProducer wrapRequestProducer(HttpAsyncRequestProducer requestProducer, @Nullable Span span, @Nullable AbstractSpan parent) { return requestProducerWrapperObjectPool.createInstance().with(requestProducer, span, parent); } - public FutureCallback wrapFutureCallback(FutureCallback futureCallback, HttpContext context, Span span) { + @SuppressWarnings("unchecked") + public FutureCallback wrapFutureCallback(FutureCallback futureCallback, HttpContext context, Span span) { return ((FutureCallbackWrapper) futureCallbackWrapperObjectPool.createInstance()).with(futureCallback, context, span); } diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/FutureCallbackWrapper.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/FutureCallbackWrapper.java index ab3bc52b5ca..1c4f16eb676 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/FutureCallbackWrapper.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/FutureCallbackWrapper.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.httpclient.v4.helper; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.DefaultOutcome; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.objectpool.Recyclable; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; @@ -35,13 +35,13 @@ class FutureCallbackWrapper implements FutureCallback, Recyclable { private FutureCallback delegate; @Nullable private HttpContext context; - private volatile Span span; + private volatile Span span; FutureCallbackWrapper(ApacheHttpAsyncClientHelper helper) { this.helper = helper; } - FutureCallbackWrapper with(@Nullable FutureCallback delegate, @Nullable HttpContext context, Span span) { + FutureCallbackWrapper with(@Nullable FutureCallback delegate, @Nullable HttpContext context, Span span) { this.delegate = delegate; this.context = context; // write to volatile field last @@ -87,7 +87,7 @@ public void cancelled() { private void finishSpan(@Nullable Exception e) { // start by reading the volatile field - final Span localSpan = span; + final Span localSpan = span; try { if (context != null) { Object responseObject = context.getAttribute(HttpCoreContext.HTTP_RESPONSE); @@ -101,7 +101,7 @@ private void finishSpan(@Nullable Exception e) { localSpan.captureException(e); if (e != null) { - localSpan.withOutcome(Outcome.FAILURE); + localSpan.withOutcome(DefaultOutcome.FAILURE); } } finally { localSpan.end(); diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/HttpAsyncRequestProducerWrapper.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/HttpAsyncRequestProducerWrapper.java index 6fd26c169b3..754e9158105 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/HttpAsyncRequestProducerWrapper.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/HttpAsyncRequestProducerWrapper.java @@ -19,10 +19,10 @@ package co.elastic.apm.agent.httpclient.v4.helper; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.plugin.spi.TraceContextUtil; import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; @@ -43,7 +43,7 @@ class HttpAsyncRequestProducerWrapper implements HttpAsyncRequestProducer, Recyc private AbstractSpan parent; @Nullable - private Span span; + private Span span; HttpAsyncRequestProducerWrapper(ApacheHttpAsyncClientHelper helper) { this.asyncClientHelper = helper; @@ -61,7 +61,7 @@ class HttpAsyncRequestProducerWrapper implements HttpAsyncRequestProducer, Recyc * @param parent the active span when this method is called * @return the {@link HttpAsyncRequestProducer} wrapper */ - public HttpAsyncRequestProducerWrapper with(HttpAsyncRequestProducer delegate, @Nullable Span span, + public HttpAsyncRequestProducerWrapper with(HttpAsyncRequestProducer delegate, @Nullable Span span, @Nullable AbstractSpan parent) { // Order is important due to visibility - write to delegate last on this (initiating) thread this.span = span; @@ -95,7 +95,7 @@ public HttpRequest generateRequest() throws IOException, HttpException { } } - if (!TraceContext.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { + if (!TraceContextUtil.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { if (span != null) { span.propagateTraceContext(request, RequestHeaderAccessor.INSTANCE); } else if (parent != null) { diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/RequestHeaderAccessor.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/RequestHeaderAccessor.java index e9ed30b0f56..f8477bb22b4 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/RequestHeaderAccessor.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/RequestHeaderAccessor.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.httpclient.v4.helper; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import org.apache.http.Header; import org.apache.http.HttpRequest; diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/AbstractSpanInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/AbstractSpanInstrumentation.java index ea2388148f1..005aadcecfd 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/AbstractSpanInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/AbstractSpanInstrumentation.java @@ -32,7 +32,7 @@ import javax.annotation.Nullable; import java.lang.invoke.MethodHandle; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_USER_SUPPLIED; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_USER_SUPPLIED; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.returns; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ApiScopeInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ApiScopeInstrumentation.java index 1a3c167bf99..c254d918779 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ApiScopeInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ApiScopeInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.pluginapi; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.AbstractSpan; 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/pluginapi/CaptureSpanInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureSpanInstrumentation.java index acd6ad0e2c2..faa7ada6120 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureSpanInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureSpanInstrumentation.java @@ -24,9 +24,9 @@ import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.DefaultOutcome; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -40,7 +40,6 @@ import java.util.Arrays; import java.util.Collection; -import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.isInAnyPackage; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.isProxy; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.overridesOrImplementsMethodThat; @@ -78,7 +77,7 @@ public static Object onMethodEnter( ) { final AbstractSpan parent = tracer.getActive(); if (parent != null) { - Span span = parent.createSpan() + Span span = parent.createSpan() .withName(spanName.isEmpty() ? signature : spanName) .activate(); span.setType(type, subtype, action); @@ -95,10 +94,10 @@ public static Object onMethodEnter( @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void onMethodExit(@Advice.Enter @Nullable Object span, @Advice.Thrown @Nullable Throwable t) { - if (span instanceof Span) { - ((Span) span) + if (span instanceof Span) { + ((Span) span) .captureException(t) - .withOutcome(t != null ? Outcome.FAILURE : Outcome.SUCCESS) + .withOutcome(t != null ? DefaultOutcome.FAILURE : DefaultOutcome.SUCCESS) .deactivate() .end(); } diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureTransactionInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureTransactionInstrumentation.java index 8f2e9cdeff3..cd84b9d23cb 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureTransactionInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureTransactionInstrumentation.java @@ -24,8 +24,8 @@ import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.DefaultOutcome; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.PrivilegedActionUtils; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; @@ -44,8 +44,8 @@ import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.isInAnyPackage; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.isProxy; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.overridesOrImplementsMethodThat; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_METHOD_SIGNATURE; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_USER_SUPPLIED; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_METHOD_SIGNATURE; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_USER_SUPPLIED; import static co.elastic.apm.agent.pluginapi.ElasticApmApiInstrumentation.PUBLIC_API_INSTRUMENTATION_GROUP; import static co.elastic.apm.agent.pluginapi.Utils.FRAMEWORK_NAME; import static net.bytebuddy.matcher.ElementMatchers.declaresMethod; @@ -74,7 +74,7 @@ public static Object onMethodEnter(@Advice.Origin Class clazz, @AnnotationValueExtractor(annotationClassName = "co.elastic.apm.api.CaptureTransaction", method = "type") String type) { final Object active = tracer.getActive(); if (active == null) { - Transaction transaction = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(clazz)); + Transaction transaction = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(clazz)); if (transaction != null) { if (transactionName.isEmpty()) { transaction.withName(signature, PRIO_METHOD_SIGNATURE); @@ -95,10 +95,10 @@ public static Object onMethodEnter(@Advice.Origin Class clazz, @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void onMethodExit(@Advice.Enter @Nullable Object transaction, @Advice.Thrown @Nullable Throwable t) { - if (transaction instanceof Transaction) { - ((Transaction) transaction) + if (transaction instanceof Transaction) { + ((Transaction) transaction) .captureException(t) - .withOutcome(t != null ? Outcome.FAILURE : Outcome.SUCCESS) + .withOutcome(t != null ? DefaultOutcome.FAILURE : DefaultOutcome.SUCCESS) .deactivate() .end(); } diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ElasticApmApiInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ElasticApmApiInstrumentation.java index c7cb07f4be3..cadd5db137f 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ElasticApmApiInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ElasticApmApiInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.pluginapi; import co.elastic.apm.agent.configuration.ServiceInfo; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.PrivilegedActionUtils; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeaderExtractorBridge.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeaderExtractorBridge.java index fb86e718e2f..6fc9b6c3de8 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeaderExtractorBridge.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeaderExtractorBridge.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.pluginapi; -import co.elastic.apm.agent.impl.transaction.AbstractHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.AbstractHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeaderInjectorBridge.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeaderInjectorBridge.java index 251341c8a70..78402a0fa8c 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeaderInjectorBridge.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeaderInjectorBridge.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.pluginapi; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeadersExtractorBridge.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeadersExtractorBridge.java index 2948febeed5..0b534d45923 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeadersExtractorBridge.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeadersExtractorBridge.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.pluginapi; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/LegacySpanInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/LegacySpanInstrumentation.java index f2833632c10..e1b71b2e73e 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/LegacySpanInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/LegacySpanInstrumentation.java @@ -28,7 +28,7 @@ import javax.annotation.Nullable; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_USER_SUPPLIED; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_USER_SUPPLIED; import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.not; diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TracedInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TracedInstrumentation.java index 03a822a18c4..5152ed05b08 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TracedInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TracedInstrumentation.java @@ -22,12 +22,8 @@ import co.elastic.apm.agent.bci.bytebuddy.AnnotationValueOffsetMappingFactory; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.util.PrivilegedActionUtils; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; @@ -41,8 +37,8 @@ import java.util.Collection; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.*; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_METHOD_SIGNATURE; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_USER_SUPPLIED; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_METHOD_SIGNATURE; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_USER_SUPPLIED; import static co.elastic.apm.agent.pluginapi.ElasticApmApiInstrumentation.PUBLIC_API_INSTRUMENTATION_GROUP; import static co.elastic.apm.agent.pluginapi.Utils.FRAMEWORK_NAME; import static net.bytebuddy.matcher.ElementMatchers.*; @@ -75,7 +71,7 @@ public static Object onMethodEnter( final AbstractSpan parent = tracer.getActive(); if (parent != null) { - Span span = parent.createSpan() + Span span = parent.createSpan() .withType(type.isEmpty() ? "app" : type) .withSubtype(subtype) .withAction(action) @@ -86,7 +82,7 @@ public static Object onMethodEnter( return span.activate(); } - Transaction transaction = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(clazz)); + Transaction transaction = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(clazz)); if (transaction == null) { return null; } @@ -112,7 +108,7 @@ public static void onMethodExit(@Advice.Enter @Nullable Object abstractSpan, if (abstractSpan instanceof AbstractSpan) { ((AbstractSpan) abstractSpan) .captureException(t) - .withOutcome(t != null ? Outcome.FAILURE : Outcome.SUCCESS) + .withOutcome(t != null ? DefaultOutcome.FAILURE : DefaultOutcome.SUCCESS) .deactivate() .end(); } diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TransactionInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TransactionInstrumentation.java index 766cf743ebe..9f3384feb1b 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TransactionInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TransactionInstrumentation.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.pluginapi; import co.elastic.apm.agent.configuration.ServiceInfo; -import co.elastic.apm.agent.impl.transaction.Id; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Id; +import co.elastic.apm.plugin.spi.TraceContext; +import co.elastic.apm.plugin.spi.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -62,8 +62,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setFrameworkName(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction, @Advice.Argument(0) String frameworkName) { - if (transaction instanceof Transaction) { - ((Transaction) transaction).setUserFrameworkName(frameworkName); + if (transaction instanceof Transaction) { + ((Transaction) transaction).setUserFrameworkName(frameworkName); } } } @@ -78,8 +78,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setUser(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction, @Advice.Argument(0) String id, @Advice.Argument(1) String email, @Advice.Argument(2) String username, @Advice.Argument(value = 3, optional = true) String domain) { - if (transaction instanceof Transaction) { - ((Transaction) transaction).setUser(id, email, username, domain); + if (transaction instanceof Transaction) { + ((Transaction) transaction).setUser(id, email, username, domain); } } } @@ -96,8 +96,8 @@ public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static String ensureParentId(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction, @Advice.Return @Nullable String returnValue) { - if (transaction instanceof Transaction) { - final TraceContext traceContext = ((Transaction) transaction).getTraceContext(); + if (transaction instanceof Transaction) { + final TraceContext traceContext = ((Transaction) transaction).getTraceContext(); Id parentId = traceContext.getParentId(); if (parentId.isEmpty()) { parentId.setToRandomValue(); @@ -118,8 +118,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setResult(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction, @Advice.Argument(0) String result) { - if (transaction instanceof Transaction) { - ((Transaction) transaction).withResult(result); + if (transaction instanceof Transaction) { + ((Transaction) transaction).withResult(result); } } } @@ -135,8 +135,8 @@ public static class AdviceClass { public static void addCustomContext(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transactionObj, @Advice.Argument(0) String key, @Advice.Argument(1) @Nullable Object value) { - if (value != null && transactionObj instanceof Transaction) { - Transaction transaction = (Transaction) transactionObj; + if (value != null && transactionObj instanceof Transaction) { + Transaction transaction = (Transaction) transactionObj; if (value instanceof String) { transaction.addCustomContext(key, (String) value); } else if (value instanceof Number) { @@ -158,8 +158,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setServiceInfo(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction, @Advice.Argument(0) String serviceName, @Advice.Argument(1) String serviceVersion) { - if (transaction instanceof Transaction) { - ((Transaction) transaction).getTraceContext().setServiceInfo(serviceName, serviceVersion); + if (transaction instanceof Transaction) { + ((Transaction) transaction).getTraceContext().setServiceInfo(serviceName, serviceVersion); } } } @@ -174,10 +174,10 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void useServiceInfoForClassLoader(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction, @Advice.Argument(0) ClassLoader classLoader) { - if (transaction instanceof Transaction) { + if (transaction instanceof Transaction) { ServiceInfo serviceInfo = tracer.getServiceInfoForClassLoader(classLoader); if (serviceInfo != null) { - ((Transaction) transaction).getTraceContext().setServiceInfo(serviceInfo.getServiceName(), serviceInfo.getServiceVersion()); + ((Transaction) transaction).getTraceContext().setServiceInfo(serviceInfo.getServiceName(), serviceInfo.getServiceVersion()); } } } 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 bd7ca07b3d3..6577f9c4471 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 @@ -21,10 +21,7 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.sdk.DynamicTransformer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; @@ -55,7 +52,7 @@ public abstract class AbstractAsyncHttpClientInstrumentation extends TracerAware public static class Helper { - static final WeakMap, Span> handlerSpanMap = WeakConcurrentProviderImpl.createWeakSpanMap(); + static final WeakMap, Span> handlerSpanMap = WeakConcurrentProviderImpl.createWeakSpanMap(); public static final List> ASYNC_HANDLER_INSTRUMENTATIONS = Arrays.>asList( AsyncHandlerOnCompletedInstrumentation.class, @@ -65,8 +62,8 @@ public static class Helper { @Nullable - static Span removeAndActivateSpan(AsyncHandler asyncHandler) { - Span span = handlerSpanMap.remove(asyncHandler); + static Span removeAndActivateSpan(AsyncHandler asyncHandler) { + Span span = handlerSpanMap.remove(asyncHandler); if (span != null) { span.activate(); } @@ -74,8 +71,8 @@ static Span removeAndActivateSpan(AsyncHandler asyncHandler) { } @Nullable - static Span getAndActivateSpan(AsyncHandler asyncHandler) { - Span span = handlerSpanMap.get(asyncHandler); + static Span getAndActivateSpan(AsyncHandler asyncHandler) { + Span span = handlerSpanMap.get(asyncHandler); if (span != null) { span.activate(); } @@ -108,7 +105,7 @@ public static Object onBeforeExecute(@Advice.Argument(value = 0) Request request DynamicTransformer.ensureInstrumented(asyncHandler.getClass(), Helper.ASYNC_HANDLER_INSTRUMENTATIONS); Uri uri = request.getUri(); - Span span = HttpClientHelper.startHttpClientSpan(parent, request.getMethod(), uri.toUrl(), uri.getScheme(), uri.getHost(), uri.getPort()); + Span span = HttpClientHelper.startHttpClientSpan(parent, request.getMethod(), uri.toUrl(), uri.getScheme(), uri.getHost(), uri.getPort()); if (span != null) { span.activate(); @@ -127,7 +124,7 @@ public static void onAfterExecute(@Advice.Enter @Nullable Object spanObj, if (spanObj == null) { return; } - Span span = (Span) spanObj; + Span span = (Span) spanObj; span.deactivate(); if (t != null) { Helper.handlerSpanMap.remove(asyncHandler); @@ -174,7 +171,7 @@ public ElementMatcher getMethodMatcher() { public static class AsyncHandlerOnCompletedInstrumentation extends AbstractAsyncHandlerInstrumentation { - public AsyncHandlerOnCompletedInstrumentation(Tracer tracer) { + public AsyncHandlerOnCompletedInstrumentation() { super(named("onCompleted").and(takesArguments(0))); } @@ -187,7 +184,7 @@ public static Object onMethodEnter(@Advice.This AsyncHandler asyncHandler) { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void onMethodExit(@Nullable @Advice.Enter Object spanObj) { - Span span = (Span) spanObj; + Span span = (Span) spanObj; if (span != null) { span.end(); span.deactivate(); @@ -198,7 +195,7 @@ public static void onMethodExit(@Nullable @Advice.Enter Object spanObj) { public static class AsyncHandlerOnThrowableInstrumentation extends AbstractAsyncHandlerInstrumentation { - public AsyncHandlerOnThrowableInstrumentation(Tracer tracer) { + public AsyncHandlerOnThrowableInstrumentation() { super(named("onThrowable").and(takesArguments(Throwable.class))); } @@ -211,10 +208,10 @@ public static Object onMethodEnter(@Advice.This AsyncHandler asyncHandler) { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void onMethodExit(@Nullable @Advice.Enter Object spanObj, @Advice.Argument(0) Throwable t) { - Span span = (Span) spanObj; + Span span = (Span) spanObj; if (span != null) { if (t instanceof MaxRedirectException) { - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } span.captureException(t).end(); span.deactivate(); @@ -225,7 +222,7 @@ public static void onMethodExit(@Nullable @Advice.Enter Object spanObj, @Advice. public static class AsyncHandlerOnStatusReceivedInstrumentation extends AbstractAsyncHandlerInstrumentation { - public AsyncHandlerOnStatusReceivedInstrumentation(Tracer tracer) { + public AsyncHandlerOnStatusReceivedInstrumentation() { super(named("onStatusReceived").and(takesArgument(0, named("org.asynchttpclient.HttpResponseStatus")))); } @@ -238,7 +235,7 @@ public static Object onMethodEnter(@Advice.This AsyncHandler asyncHandler) { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void onMethodExit(@Nullable @Advice.Enter Object spanObj, @Advice.Argument(0) HttpResponseStatus status) { - Span span = (Span) spanObj; + Span span = (Span) spanObj; if (span != null) { span.getContext().getHttp().withStatusCode(status.getStatusCode()); span.deactivate(); @@ -249,7 +246,7 @@ public static void onMethodExit(@Nullable @Advice.Enter Object spanObj, @Advice. public static class StreamedAsyncHandlerOnStreamInstrumentation extends AbstractAsyncHandlerInstrumentation { - public StreamedAsyncHandlerOnStreamInstrumentation(Tracer tracer) { + public StreamedAsyncHandlerOnStreamInstrumentation() { super(named("onStream").and(takesArgument(0, named("org.reactivestreams.Publisher")))); } @@ -262,7 +259,7 @@ public static Object onMethodEnter(@Advice.This AsyncHandler asyncHandler) { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void onMethodExit(@Nullable @Advice.Enter Object spanObj) { - Span span = (Span) spanObj; + Span span = (Span) spanObj; if (span != null) { span.deactivate(); } diff --git a/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/RequestHeaderSetter.java b/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/RequestHeaderSetter.java index 522c3875055..437d0a32d81 100644 --- a/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/RequestHeaderSetter.java +++ b/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/RequestHeaderSetter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.asynchttpclient; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import org.asynchttpclient.Request; class RequestHeaderSetter implements TextHeaderSetter { diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/AmazonHttpClientInstrumentation.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/AmazonHttpClientInstrumentation.java index 9d47c9ec0cc..0ab178ba3dc 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/AmazonHttpClientInstrumentation.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/AmazonHttpClientInstrumentation.java @@ -24,8 +24,8 @@ import co.elastic.apm.agent.awssdk.v1.helper.S3Helper; import co.elastic.apm.agent.awssdk.v1.helper.SQSHelper; import co.elastic.apm.agent.awssdk.v1.helper.SdkV1DataSource; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.DefaultOutcome; +import co.elastic.apm.plugin.spi.Span; import com.amazonaws.Request; import com.amazonaws.handlers.HandlerContextKey; import com.amazonaws.http.ExecutionContext; @@ -76,7 +76,7 @@ public static Object enterInvoke(@Advice.Argument(value = 0) Request request, return null; } - Span span = helper.startSpan(request, request.getEndpoint(), executionContext); + Span span = helper.startSpan(request, request.getEndpoint(), executionContext); if (span != null) { span.activate(); @@ -90,14 +90,14 @@ public static Object enterInvoke(@Advice.Argument(value = 0) Request request, @Advice.OnMethodExit(suppress = Throwable.class, inline = false, onThrowable = Throwable.class) public static void exitInvoke(@Nullable @Advice.Enter Object spanObj, @Nullable @Advice.Thrown Throwable thrown) { - if (spanObj instanceof Span) { - Span span = (Span) spanObj; + if (spanObj instanceof Span) { + Span span = (Span) spanObj; span.deactivate(); if (thrown != null) { span.captureException(thrown); - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } else { - span.withOutcome(Outcome.SUCCESS); + span.withOutcome(DefaultOutcome.SUCCESS); } span.end(); diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/SQSMessageDispatchingInstrumentation.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/SQSMessageDispatchingInstrumentation.java index a32c139647a..4c5e4359ff9 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/SQSMessageDispatchingInstrumentation.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/SQSMessageDispatchingInstrumentation.java @@ -21,8 +21,8 @@ import co.elastic.apm.agent.awssdk.common.AbstractAwsSdkInstrumentation; import co.elastic.apm.agent.awssdk.v1.helper.SQSHelper; import co.elastic.apm.agent.awssdk.v1.helper.SdkV1DataSource; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.DefaultOutcome; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.sdk.state.CallDepth; import com.amazonaws.AmazonWebServiceRequest; import com.amazonaws.services.sqs.model.ReceiveMessageRequest; @@ -49,14 +49,14 @@ public ElementMatcher getTypeMatcher() { } protected static void endSpan(@Nullable Object spanObj, @Nullable Throwable thrown) { - if (spanObj instanceof Span) { - Span span = (Span) spanObj; + if (spanObj instanceof Span) { + Span span = (Span) spanObj; span.deactivate(); if (thrown != null) { span.captureException(thrown); - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } else { - span.withOutcome(Outcome.SUCCESS); + span.withOutcome(DefaultOutcome.SUCCESS); } span.end(); } @@ -91,7 +91,7 @@ public static Object enterSendMessage(@Advice.Argument(value = 0) AmazonWebServi return null; } - Span span = SQSHelper.getInstance().createSpan(queueName); + Span span = SQSHelper.getInstance().createSpan(queueName); if (span != null) { SQSHelper.getInstance().propagateContext(span, request); @@ -123,7 +123,7 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object enterReceiveMessage(@Advice.Argument(value = 0) ReceiveMessageRequest receiveMessageRequest) { String queueName = SdkV1DataSource.getInstance().getQueueNameFromQueueUrl(receiveMessageRequest.getQueueUrl()); - Span span = SQSHelper.getInstance().createSpan(queueName); + Span span = SQSHelper.getInstance().createSpan(queueName); if (span != null) { span.activate(); @@ -141,8 +141,8 @@ public static ReceiveMessageResult exitReceiveMessage(@Nullable @Advice.Enter Ob @Advice.Argument(value = 0) ReceiveMessageRequest receiveMessageRequest, @Advice.Return ReceiveMessageResult result, @Nullable @Advice.Thrown Throwable thrown) { - if (spanObj instanceof Span) { - SQSHelper.getInstance().handleReceivedMessages((Span) spanObj, receiveMessageRequest.getQueueUrl(), result.getMessages()); + if (spanObj instanceof Span) { + SQSHelper.getInstance().handleReceivedMessages((Span) spanObj, receiveMessageRequest.getQueueUrl(), result.getMessages()); } endSpan(spanObj, thrown); diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/DynamoDbHelper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/DynamoDbHelper.java index d7fa48bd2f8..7cbfe0f9acc 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/DynamoDbHelper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/DynamoDbHelper.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.awssdk.v1.helper; import co.elastic.apm.agent.awssdk.common.AbstractDynamoDBInstrumentationHelper; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Span; import com.amazonaws.AmazonWebServiceRequest; import com.amazonaws.Request; import com.amazonaws.http.ExecutionContext; @@ -43,10 +43,10 @@ public DynamoDbHelper(Tracer tracer) { @Nullable @Override - public Span startSpan(Request request, URI httpURI, ExecutionContext context) { + public Span startSpan(Request request, URI httpURI, ExecutionContext context) { AmazonWebServiceRequest amazonRequest = request.getOriginalRequest(); - Span span = super.startSpan(request, httpURI, context); + Span span = super.startSpan(request, httpURI, context); if (span != null) { span.withSync(!isRequestAsync(amazonRequest)); } diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/S3Helper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/S3Helper.java index c44d5a8968d..62b3b499aa5 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/S3Helper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/S3Helper.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.awssdk.v1.helper; import co.elastic.apm.agent.awssdk.common.AbstractS3InstrumentationHelper; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; import com.amazonaws.Request; import com.amazonaws.http.ExecutionContext; diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/SQSHelper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/SQSHelper.java index 53856d4817f..b11ac54bbcc 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/SQSHelper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/SQSHelper.java @@ -21,11 +21,11 @@ import co.elastic.apm.agent.awssdk.common.AbstractSQSInstrumentationHelper; import co.elastic.apm.agent.awssdk.v1.helper.sqs.wrapper.ReceiveMessageResultWrapper; import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Span; +import co.elastic.apm.plugin.spi.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TraceContext; import co.elastic.apm.agent.common.util.WildcardMatcher; import com.amazonaws.AmazonWebServiceRequest; import com.amazonaws.Request; @@ -57,7 +57,7 @@ protected SQSHelper(Tracer tracer) { } - public void propagateContext(Span span, AmazonWebServiceRequest request) { + public void propagateContext(Span span, AmazonWebServiceRequest request) { if (request instanceof SendMessageRequest) { SendMessageRequest sendMessageRequest = (SendMessageRequest) request; span.propagateTraceContext(sendMessageRequest.getMessageAttributes(), this); @@ -127,7 +127,7 @@ protected boolean isReceiveMessageRequest(Request request) { } @Override - protected void setMessageContext(@Nullable Message sqsMessage, @Nullable String queueName, co.elastic.apm.agent.impl.context.Message message) { + protected void setMessageContext(@Nullable Message sqsMessage, @Nullable String queueName, co.elastic.apm.plugin.spi.Message message) { if (queueName != null) { message.withQueue(queueName); } @@ -164,15 +164,15 @@ protected void setMessageContext(@Nullable Message sqsMessage, @Nullable String */ @Nullable @Override - public Span startSpan(Request request, URI httpURI, ExecutionContext context) { + public Span startSpan(Request request, URI httpURI, ExecutionContext context) { if (isAlreadyActive(request)) { - Span activeSpan = tracer.getActiveExitSpan(); + Span activeSpan = tracer.getActiveExitSpan(); if (activeSpan != null && SQS_TYPE.equals(activeSpan.getSubtype())) { enrichSpan(activeSpan, request, request.getEndpoint(), context); activeSpan.withSync(isRequestSync(request.getOriginalRequest())); } } else { - Span span = super.startSpan(request, request.getEndpoint(), context); + Span span = super.startSpan(request, request.getEndpoint(), context); if (span != null) { span.withSync(isRequestSync(request.getOriginalRequest())); return span; diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/sqs/wrapper/MessageIteratorWrapper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/sqs/wrapper/MessageIteratorWrapper.java index 3b260f6eb4f..799de9e35c3 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/sqs/wrapper/MessageIteratorWrapper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/sqs/wrapper/MessageIteratorWrapper.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.awssdk.common.AbstractMessageIteratorWrapper; import co.elastic.apm.agent.awssdk.v1.helper.SQSHelper; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import com.amazonaws.services.sqs.model.Message; import java.util.Iterator; diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/sqs/wrapper/MessageListWrapper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/sqs/wrapper/MessageListWrapper.java index f50ac61c279..8cc5b8b576c 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/sqs/wrapper/MessageListWrapper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/sqs/wrapper/MessageListWrapper.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.awssdk.common.AbstractMessageListWrapper; import co.elastic.apm.agent.awssdk.v1.helper.SQSHelper; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import com.amazonaws.services.sqs.model.Message; import java.util.Iterator; diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/sqs/wrapper/ReceiveMessageResultWrapper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/sqs/wrapper/ReceiveMessageResultWrapper.java index 013a0cf43c3..bb58826a16d 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/sqs/wrapper/ReceiveMessageResultWrapper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/sqs/wrapper/ReceiveMessageResultWrapper.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.awssdk.v1.helper.sqs.wrapper; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import com.amazonaws.services.sqs.model.Message; import com.amazonaws.services.sqs.model.ReceiveMessageResult; diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/BaseAsyncClientHandlerInstrumentation.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/BaseAsyncClientHandlerInstrumentation.java index 1d7910d2733..a7429109d80 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/BaseAsyncClientHandlerInstrumentation.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/BaseAsyncClientHandlerInstrumentation.java @@ -22,7 +22,7 @@ import co.elastic.apm.agent.awssdk.v2.helper.S3Helper; import co.elastic.apm.agent.awssdk.v2.helper.SQSHelper; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -75,7 +75,7 @@ public static TransformingAsyncResponseHandler enterDoExecute(@Advice.Argumen String awsService = executionContext.executionAttributes().getAttribute(AwsSignerExecutionAttribute.SERVICE_NAME); SdkRequest sdkRequest = clientExecutionParams.getInput(); URI uri = clientConfiguration.option(SdkClientOption.ENDPOINT); - Span span = null; + Span span = null; if ("S3".equalsIgnoreCase(awsService)) { span = S3Helper.getInstance().startSpan(sdkRequest, uri, executionContext); } else if ("DynamoDb".equalsIgnoreCase(awsService)) { diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/BaseSyncClientHandlerInstrumentation.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/BaseSyncClientHandlerInstrumentation.java index 8e89e832863..fe411211c5a 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/BaseSyncClientHandlerInstrumentation.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/BaseSyncClientHandlerInstrumentation.java @@ -24,8 +24,8 @@ import co.elastic.apm.agent.awssdk.v2.helper.sqs.wrapper.MessageListWrapper; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.common.JvmRuntimeInfo; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.DefaultOutcome; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -84,7 +84,7 @@ public static Object enterDoExecute(@Advice.Argument(value = 0) ClientExecutionP String awsService = executionContext.executionAttributes().getAttribute(AwsSignerExecutionAttribute.SERVICE_NAME); SdkRequest sdkRequest = clientExecutionParams.getInput(); URI uri = clientConfiguration.option(SdkClientOption.ENDPOINT); - Span span = null; + Span span = null; if ("S3".equalsIgnoreCase(awsService)) { span = S3Helper.getInstance().startSpan(sdkRequest, uri, executionContext); } else if ("DynamoDb".equalsIgnoreCase(awsService)) { @@ -110,8 +110,8 @@ public static void exitDoExecute(@Advice.Argument(value = 0) ClientExecutionPara @Advice.This Object thiz) { String awsService = executionContext.executionAttributes().getAttribute(AwsSignerExecutionAttribute.SERVICE_NAME); SdkRequest sdkRequest = clientExecutionParams.getInput(); - if (spanObj instanceof Span) { - Span span = (Span) spanObj; + if (spanObj instanceof Span) { + Span span = (Span) spanObj; span.deactivate(); if (thrown != null) { if (JVM_RUNTIME_INFO.isCoretto() && JVM_RUNTIME_INFO.getMajorVersion() > 16) { @@ -119,9 +119,9 @@ public static void exitDoExecute(@Advice.Argument(value = 0) ClientExecutionPara } else { span.captureException(thrown); } - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } else { - span.withOutcome(Outcome.SUCCESS); + span.withOutcome(DefaultOutcome.SUCCESS); } if ("Sqs".equalsIgnoreCase(awsService) && sdkResponse instanceof SdkResponse) { diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/ResponseHandlerWrapper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/ResponseHandlerWrapper.java index 61fd0eee57e..fa1c2b66361 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/ResponseHandlerWrapper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/ResponseHandlerWrapper.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.awssdk.v2.helper.SQSHelper; import co.elastic.apm.agent.awssdk.v2.helper.sqs.wrapper.MessageListWrapper; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.DefaultOutcome; +import co.elastic.apm.plugin.spi.Span; import org.reactivestreams.Publisher; import software.amazon.awssdk.core.Response; import software.amazon.awssdk.core.SdkRequest; @@ -37,11 +37,11 @@ public class ResponseHandlerWrapper implements TransformingAsyncResponseHandl private final TransformingAsyncResponseHandler> delegate; @Nullable - private final Span span; + private final Span span; private final SdkRequest sdkRequest; private final String awsService; - public ResponseHandlerWrapper(String awsService, TransformingAsyncResponseHandler> delegate, SdkRequest request, @Nullable Span span) { + public ResponseHandlerWrapper(String awsService, TransformingAsyncResponseHandler> delegate, SdkRequest request, @Nullable Span span) { this.awsService = awsService; this.delegate = delegate; this.span = span; @@ -56,12 +56,12 @@ public CompletableFuture> prepare() { if (span != null) { if (t != null) { span.captureException(t); - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } else if (r.exception() != null) { span.captureException(r.exception()); - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } else { - span.withOutcome(Outcome.SUCCESS); + span.withOutcome(DefaultOutcome.SUCCESS); } if ("Sqs".equalsIgnoreCase(awsService) && response instanceof SdkResponse) { @@ -94,7 +94,7 @@ public void onStream(Publisher publisher) { public void onError(Throwable throwable) { if (span != null && !span.isFinished()) { span.captureException(throwable); - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } delegate.onError(throwable); diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/DynamoDbHelper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/DynamoDbHelper.java index 214577487d0..54a67028969 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/DynamoDbHelper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/DynamoDbHelper.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.awssdk.v2.helper; import co.elastic.apm.agent.awssdk.common.AbstractDynamoDBInstrumentationHelper; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; import software.amazon.awssdk.core.SdkRequest; import software.amazon.awssdk.core.http.ExecutionContext; diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/S3Helper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/S3Helper.java index f805761f048..bcce8b60241 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/S3Helper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/S3Helper.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.awssdk.v2.helper; import co.elastic.apm.agent.awssdk.common.AbstractS3InstrumentationHelper; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; import software.amazon.awssdk.core.SdkRequest; import software.amazon.awssdk.core.http.ExecutionContext; diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/SQSHelper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/SQSHelper.java index 917a3bb0e17..6ad1e36f332 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/SQSHelper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/SQSHelper.java @@ -19,11 +19,11 @@ package co.elastic.apm.agent.awssdk.v2.helper; import co.elastic.apm.agent.awssdk.common.AbstractSQSInstrumentationHelper; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Span; +import co.elastic.apm.plugin.spi.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TraceContext; import software.amazon.awssdk.core.SdkRequest; import software.amazon.awssdk.core.SdkResponse; import software.amazon.awssdk.core.client.handler.ClientExecutionParams; @@ -57,7 +57,7 @@ public SQSHelper(Tracer tracer) { super(tracer, SdkV2DataSource.getInstance()); } - private SdkRequest propagateContext(Span span, SdkRequest sdkRequest) { + private SdkRequest propagateContext(Span span, SdkRequest sdkRequest) { if (sdkRequest instanceof SendMessageRequest) { SendMessageRequest sendMessageRequest = (SendMessageRequest) sdkRequest; Map attributesMap = new HashMap<>(sendMessageRequest.messageAttributes()); @@ -119,7 +119,7 @@ protected boolean isReceiveMessageRequest(SdkRequest request) { return request instanceof ReceiveMessageRequest; } - public void modifyRequestObject(@Nullable Span span, ClientExecutionParams clientExecutionParams, ExecutionContext executionContext) { + public void modifyRequestObject(@Nullable Span span, ClientExecutionParams clientExecutionParams, ExecutionContext executionContext) { SdkRequest sdkRequest = clientExecutionParams.getInput(); SdkRequest newRequestObj = null; if (span != null && clientExecutionParams.getOperationName().startsWith("SendMessage")) { @@ -179,7 +179,7 @@ public void forEach(String headerName, Message message, S state, HeaderConsu } } - public void handleReceivedMessages(Span span, @Nullable SdkRequest sdkRequest, @Nullable SdkResponse sdkResponse) { + public void handleReceivedMessages(Span span, @Nullable SdkRequest sdkRequest, @Nullable SdkResponse sdkResponse) { if (sdkResponse instanceof ReceiveMessageResponse && sdkRequest instanceof ReceiveMessageRequest) { SQSHelper.getInstance().handleReceivedMessages(span, ((ReceiveMessageRequest) sdkRequest).queueUrl(), ((ReceiveMessageResponse) sdkResponse).messages()); } diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/sqs/wrapper/MessageIteratorWrapper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/sqs/wrapper/MessageIteratorWrapper.java index 735535eff9c..8e0568d9fa2 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/sqs/wrapper/MessageIteratorWrapper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/sqs/wrapper/MessageIteratorWrapper.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.awssdk.common.AbstractMessageIteratorWrapper; import co.elastic.apm.agent.awssdk.v2.helper.SQSHelper; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import software.amazon.awssdk.services.sqs.model.Message; import java.util.Iterator; diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/sqs/wrapper/MessageListWrapper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/sqs/wrapper/MessageListWrapper.java index 84073604557..cdc27247cc2 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/sqs/wrapper/MessageListWrapper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/sqs/wrapper/MessageListWrapper.java @@ -24,7 +24,7 @@ import co.elastic.apm.agent.awssdk.v2.helper.SdkV2DataSource; import co.elastic.apm.agent.configuration.MessagingConfiguration; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.sdk.state.CallDepth; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractAwsSdkInstrumentationHelper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractAwsSdkInstrumentationHelper.java index daafdbba2a9..61fe6dfbb8c 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractAwsSdkInstrumentationHelper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractAwsSdkInstrumentationHelper.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.awssdk.common; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Span; import javax.annotation.Nullable; import java.net.URI; @@ -38,9 +38,9 @@ public Tracer getTracer() { } @Nullable - public abstract Span startSpan(R request, URI httpURI, C context); + public abstract Span startSpan(R request, URI httpURI, C context); - protected void setDestinationContext(Span span, @Nullable URI uri, R sdkRequest, C context, String type, @Nullable String name) { + protected void setDestinationContext(Span span, @Nullable URI uri, R sdkRequest, C context, String type, @Nullable String name) { if (uri != null) { span.getContext().getDestination() .withAddress(uri.getHost()) diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractDynamoDBInstrumentationHelper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractDynamoDBInstrumentationHelper.java index 45fc1768840..76f52b9959a 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractDynamoDBInstrumentationHelper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractDynamoDBInstrumentationHelper.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.awssdk.common; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import javax.annotation.Nullable; import java.net.URI; @@ -32,7 +32,7 @@ protected AbstractDynamoDBInstrumentationHelper(Tracer tracer, IAwsSdkDataSource super(tracer, awsSdkDataSource); } - public void enrichSpan(Span span, R sdkRequest, URI httpURI, C context) { + public void enrichSpan(Span span, R sdkRequest, URI httpURI, C context) { String operationName = awsSdkDataSource.getOperationName(sdkRequest, context); String region = awsSdkDataSource.getRegion(sdkRequest, context); String tableName = awsSdkDataSource.getFieldValue(IAwsSdkDataSource.TABLE_NAME_FIELD, sdkRequest); @@ -62,8 +62,8 @@ public void enrichSpan(Span span, R sdkRequest, URI httpURI, C context) { } @Nullable - public Span startSpan(R sdkRequest, URI httpURI, C context) { - Span span = tracer.createExitChildSpan(); + public Span startSpan(R sdkRequest, URI httpURI, C context) { + Span span = tracer.createExitChildSpan(); if (span == null) { return null; } diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractMessageIteratorWrapper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractMessageIteratorWrapper.java index ef905721a66..f63ef9c3a83 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractMessageIteratorWrapper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractMessageIteratorWrapper.java @@ -19,10 +19,10 @@ package co.elastic.apm.agent.awssdk.common; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Span; +import co.elastic.apm.plugin.spi.TextHeaderGetter; +import co.elastic.apm.plugin.spi.Transaction; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,8 +62,8 @@ public boolean hasNext() { } @Nullable - public Transaction endCurrentTransaction() { - Transaction transaction = null; + public Transaction endCurrentTransaction() { + Transaction transaction = null; try { transaction = tracer.currentTransaction(); if (transaction != null && MESSAGING_TYPE.equals(transaction.getType())) { @@ -77,7 +77,7 @@ public Transaction endCurrentTransaction() { } public void endMessageProcessingSpan() { - Span span = tracer.getActiveSpan(); + Span span = tracer.getActiveSpan(); if (span != null && span.getType() != null && span.getType().equals(MESSAGING_TYPE) @@ -89,7 +89,7 @@ public void endMessageProcessingSpan() { @Override public Message next() { - Transaction currentTransaction = endCurrentTransaction(); + Transaction currentTransaction = endCurrentTransaction(); Message sqsMessage = delegate.next(); if (currentTransaction == null) { sqsInstrumentationHelper.startTransactionOnMessage(sqsMessage, queueName, textHeaderGetter); diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractMessageListWrapper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractMessageListWrapper.java index 4386cbd4cd4..4633ff85972 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractMessageListWrapper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractMessageListWrapper.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.awssdk.common; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import java.util.Collection; import java.util.List; diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractS3InstrumentationHelper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractS3InstrumentationHelper.java index ee79deb71a5..719262e5f99 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractS3InstrumentationHelper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractS3InstrumentationHelper.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.awssdk.common; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import javax.annotation.Nullable; import java.net.URI; @@ -34,8 +34,8 @@ protected AbstractS3InstrumentationHelper(Tracer tracer, IAwsSdkDataSource @Nullable - public Span startSpan(R request, URI httpURI, C context) { - Span span = tracer.createExitChildSpan(); + public Span startSpan(R request, URI httpURI, C context) { + Span span = tracer.createExitChildSpan(); if (span == null) { return null; } diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractSQSInstrumentationHelper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractSQSInstrumentationHelper.java index 2038764d58f..7cfea9a01ca 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractSQSInstrumentationHelper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/main/java/co/elastic/apm/agent/awssdk/common/AbstractSQSInstrumentationHelper.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.context.Message; -import co.elastic.apm.agent.impl.transaction.*; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Message; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.util.PrivilegedActionUtils; @@ -80,11 +80,11 @@ protected AbstractSQSInstrumentationHelper(Tracer tracer, IAwsSdkDataSource createSpan(@Nullable String queueName) { if (WildcardMatcher.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), queueName)) { return null; } - Span span = tracer.createExitChildSpan(); + Span span = tracer.createExitChildSpan(); if (span != null) { span.withType(MESSAGING_TYPE) .withSubtype(SQS_TYPE); @@ -92,7 +92,7 @@ public Span createSpan(@Nullable String queueName) { return span; } - public void enrichSpan(Span span, R request, URI httpURI, C context) { + public void enrichSpan(Span span, R request, URI httpURI, C context) { String operationName = awsSdkDataSource.getOperationName(request, context); String queueName = awsSdkDataSource.getFieldValue(IAwsSdkDataSource.QUEUE_NAME_FIELD, request); @@ -129,11 +129,11 @@ public void enrichSpan(Span span, R request, URI httpURI, C context) { } @Nullable - public Span startSpan(R request, URI httpURI, C context) { + public Span startSpan(R request, URI httpURI, C context) { AbstractSpan activeSpan = tracer.getActive(); - if (isReceiveMessageRequest(request) && messagingConfiguration.shouldEndMessagingTransactionOnPoll() && activeSpan instanceof Transaction) { - Transaction transaction = (Transaction) activeSpan; + if (isReceiveMessageRequest(request) && messagingConfiguration.shouldEndMessagingTransactionOnPoll() && activeSpan instanceof Transaction) { + Transaction transaction = (Transaction) activeSpan; if (MESSAGING_TYPE.equals(transaction.getType())) { transaction.deactivate().end(); return null; @@ -142,7 +142,7 @@ public Span startSpan(R request, URI httpURI, C context) { String queueName = awsSdkDataSource.getFieldValue(IAwsSdkDataSource.QUEUE_NAME_FIELD, request); - Span span = createSpan(queueName); + Span span = createSpan(queueName); if (span != null) { enrichSpan(span, request, httpURI, context); } @@ -153,7 +153,7 @@ public Span startSpan(R request, URI httpURI, C context) { public void startTransactionOnMessage(MessageT sqsMessage, String queueName, TextHeaderGetter headerGetter) { try { if (!WildcardMatcher.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), queueName)) { - Transaction transaction = tracer.startChildTransaction(sqsMessage, headerGetter, PrivilegedActionUtils.getClassLoader(AbstractSQSInstrumentationHelper.class)); + Transaction transaction = tracer.startChildTransaction(sqsMessage, headerGetter, PrivilegedActionUtils.getClassLoader(AbstractSQSInstrumentationHelper.class)); if (transaction != null) { transaction.withType(MESSAGING_TYPE).withName("SQS RECEIVE from " + queueName).activate(); transaction.setFrameworkName(FRAMEWORK_NAME); @@ -168,9 +168,9 @@ public void startTransactionOnMessage(MessageT sqsMessage, String queueName, Tex } } - private void addSpanLink(Span span, MessageT sqsMessage, TextHeaderGetter headerGetter) { + private void addSpanLink(Span span, MessageT sqsMessage, TextHeaderGetter headerGetter) { span.addSpanLink( - TraceContext.getFromTraceContextTextHeaders(), + TraceContextUtil.getFromTraceContextTextHeaders(), headerGetter, sqsMessage ); @@ -205,7 +205,7 @@ protected void setMessageContext(@Nullable MessageT sqsMessage, @Nullable String } } - public void handleReceivedMessages(Span span, String queueUrl, @Nullable List messages) { + public void handleReceivedMessages(Span span, String queueUrl, @Nullable List messages) { String queueName = awsSdkDataSource.getQueueNameFromQueueUrl(queueUrl); MessageT singleMessage = null; if (messages != null) { diff --git a/apm-agent-plugins/apm-cassandra/apm-cassandra-core-plugin/src/main/java/co/elastic/apm/agent/cassandra/CassandraHelper.java b/apm-agent-plugins/apm-cassandra/apm-cassandra-core-plugin/src/main/java/co/elastic/apm/agent/cassandra/CassandraHelper.java index fdd67b271ce..95194166b19 100644 --- a/apm-agent-plugins/apm-cassandra/apm-cassandra-core-plugin/src/main/java/co/elastic/apm/agent/cassandra/CassandraHelper.java +++ b/apm-agent-plugins/apm-cassandra/apm-cassandra-core-plugin/src/main/java/co/elastic/apm/agent/cassandra/CassandraHelper.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.cassandra; import co.elastic.apm.agent.db.signature.SignatureParser; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import javax.annotation.Nullable; @@ -35,8 +35,8 @@ public CassandraHelper(Tracer tracer) { } @Nullable - public Span startCassandraSpan(@Nullable String query, boolean preparedStatement, @Nullable String keyspace) { - Span span = tracer.createExitChildSpan(); + public Span startCassandraSpan(@Nullable String query, boolean preparedStatement, @Nullable String keyspace) { + Span span = tracer.createExitChildSpan(); if (span == null) { return null; } diff --git a/apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/src/main/java/co/elastic/apm/agent/cassandra3/Cassandra3Instrumentation.java b/apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/src/main/java/co/elastic/apm/agent/cassandra3/Cassandra3Instrumentation.java index fe439060e99..e1f0f313047 100644 --- a/apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/src/main/java/co/elastic/apm/agent/cassandra3/Cassandra3Instrumentation.java +++ b/apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/src/main/java/co/elastic/apm/agent/cassandra3/Cassandra3Instrumentation.java @@ -21,9 +21,8 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers; import co.elastic.apm.agent.cassandra.CassandraHelper; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.context.Destination; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Span; import com.datastax.driver.core.BoundStatement; import com.datastax.driver.core.Host; import com.datastax.driver.core.ResultSet; @@ -111,10 +110,10 @@ private static String getQuery(Statement statement) { public static void onExit(@Advice.Thrown @Nullable Throwable thrown, @Advice.Return ResultSetFuture result, @Nullable @Advice.Enter Object spanObj) { - if (!(spanObj instanceof Span)) { + if (!(spanObj instanceof Span)) { return; } - final Span span = (Span) spanObj; + final Span span = (Span) spanObj; span.captureException(thrown).deactivate(); Futures.addCallback(result, new FutureCallback() { @Override @@ -137,7 +136,7 @@ public void onFailure(Throwable t) { } private interface DestinationAddressSetter { - void setDestination(Span span, Host host); + void setDestination(Span span, Host host); class Resolver { @@ -164,14 +163,14 @@ static DestinationAddressSetter get() { } /** - * References the method {@link Destination#withSocketAddress(java.net.SocketAddress)} that has been introduced in 2.0.2 + * References the method {@link co.elastic.apm.plugin.spi.Destination#withSocketAddress(java.net.SocketAddress)} that has been introduced in 2.0.2 * We must not reference this class directly to avoid it being loaded which may cause a linkage error. */ enum WithSocketAddress implements DestinationAddressSetter { INSTANCE; @Override - public void setDestination(Span span, Host host) { + public void setDestination(Span span, Host host) { span.getContext().getDestination().withSocketAddress(host.getSocketAddress()); } } @@ -180,7 +179,7 @@ enum WithInetAddress implements DestinationAddressSetter { INSTANCE; @Override - public void setDestination(Span span, Host host) { + public void setDestination(Span span, Host host) { span.getContext().getDestination().withInetAddress(host.getAddress()); } } diff --git a/apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/src/main/java/co/elastic/apm/agent/cassandra4/Cassandra4Instrumentation.java b/apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/src/main/java/co/elastic/apm/agent/cassandra4/Cassandra4Instrumentation.java index 9ae0a5c88cc..a8332f0d381 100644 --- a/apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/src/main/java/co/elastic/apm/agent/cassandra4/Cassandra4Instrumentation.java +++ b/apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/src/main/java/co/elastic/apm/agent/cassandra4/Cassandra4Instrumentation.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.cassandra.CassandraHelper; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Span; import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.cql.AsyncResultSet; import com.datastax.oss.driver.api.core.cql.BoundStatement; @@ -117,10 +117,10 @@ private static String getQuery(Request request) { public static void onExit(@Advice.Thrown @Nullable Throwable thrown, @Advice.Return Object result, @Nullable @Advice.Enter Object spanObj) { - if (!(spanObj instanceof Span)) { + if (!(spanObj instanceof Span)) { return; } - Span span = (Span) spanObj; + Span span = (Span) spanObj; span.captureException(thrown).deactivate(); if (result instanceof ResultSet) { setDestination(span, ((ResultSet) result).getExecutionInfo()); @@ -137,7 +137,7 @@ public static void onExit(@Advice.Thrown @Nullable Throwable thrown, } } - private static void setDestination(Span span, ExecutionInfo info) { + private static void setDestination(Span span, ExecutionInfo info) { Node coordinator = info.getCoordinator(); if (coordinator != null) { span.getContext().getDestination().withSocketAddress(coordinator.getEndPoint().resolve()); diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaCallbackHolder.java b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaCallbackHolder.java index 264a72a1480..f58dd570b3d 100644 --- a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaCallbackHolder.java +++ b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaCallbackHolder.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.dubbo; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.AbstractSpan; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import com.alibaba.dubbo.remoting.exchange.ResponseCallback; diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaResponseCallbackInstrumentation.java b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaResponseCallbackInstrumentation.java index 2a73afc86a5..ebd3c149be0 100644 --- a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaResponseCallbackInstrumentation.java +++ b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/AlibabaResponseCallbackInstrumentation.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.dubbo; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.DefaultOutcome; import com.alibaba.dubbo.remoting.exchange.ResponseCallback; import com.alibaba.dubbo.rpc.Result; import net.bytebuddy.asm.Advice; @@ -78,7 +78,7 @@ public static void onExit(@Advice.Thrown @Nullable Throwable thrown, } span.captureException(thrown) .captureException(resultException) - .withOutcome(thrown != null || resultException != null ? Outcome.FAILURE : Outcome.SUCCESS) + .withOutcome(thrown != null || resultException != null ? DefaultOutcome.FAILURE : DefaultOutcome.SUCCESS) .deactivate() .end(); } @@ -116,7 +116,7 @@ public static void onExit(@Advice.Thrown @Nullable Throwable thrown, } span.captureException(thrown) .captureException(caught) - .withOutcome(caught != null || thrown != null ? Outcome.FAILURE : Outcome.SUCCESS) + .withOutcome(caught != null || thrown != null ? DefaultOutcome.FAILURE : DefaultOutcome.SUCCESS) .deactivate() .end(); } 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 9c86a8bd1d3..8a481295299 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 @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.dubbo; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.AbstractSpan; import co.elastic.apm.agent.sdk.DynamicTransformer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import com.alibaba.dubbo.remoting.exchange.ResponseCallback; diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/AlibabaMonitorFilterAdvice.java b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/AlibabaMonitorFilterAdvice.java index c451979ef16..861bbf82523 100644 --- a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/AlibabaMonitorFilterAdvice.java +++ b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/AlibabaMonitorFilterAdvice.java @@ -20,12 +20,7 @@ import co.elastic.apm.agent.dubbo.helper.AlibabaDubboTextMapPropagator; import co.elastic.apm.agent.dubbo.helper.DubboTraceHelper; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.util.PrivilegedActionUtils; import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Result; @@ -46,7 +41,7 @@ public static Object onEnterFilterInvoke(@Advice.Argument(1) Invocation invocati // for consumer side, just create span, more information will be collected in provider side AbstractSpan active = tracer.getActive(); if (context.isConsumerSide() && active != null) { - Span span = DubboTraceHelper.createConsumerSpan(tracer, invocation.getInvoker().getInterface(), + Span span = DubboTraceHelper.createConsumerSpan(tracer, invocation.getInvoker().getInterface(), invocation.getMethodName(), context.getRemoteAddress()); if (span != null) { span.propagateTraceContext(context, AlibabaDubboTextMapPropagator.INSTANCE); @@ -54,7 +49,7 @@ public static Object onEnterFilterInvoke(@Advice.Argument(1) Invocation invocati } } else if (context.isProviderSide() && active == null) { // for provider side - Transaction transaction = tracer.startChildTransaction(context, AlibabaDubboTextMapPropagator.INSTANCE, PrivilegedActionUtils.getClassLoader(Invocation.class)); + Transaction transaction = tracer.startChildTransaction(context, AlibabaDubboTextMapPropagator.INSTANCE, PrivilegedActionUtils.getClassLoader(Invocation.class)); if (transaction != null) { transaction.activate(); DubboTraceHelper.fillTransaction(transaction, invocation.getInvoker().getInterface(), invocation.getMethodName()); @@ -81,7 +76,7 @@ public static void onExitFilterInvoke(@Advice.Argument(1) Invocation invocation, span .captureException(t) .captureException(resultException) - .withOutcome(t != null || resultException != null ? Outcome.FAILURE : Outcome.SUCCESS) + .withOutcome(t != null || resultException != null ? DefaultOutcome.FAILURE : DefaultOutcome.SUCCESS) .deactivate(); if (!(RpcContext.getContext().getFuture() instanceof FutureAdapter)) { diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/ApacheMonitorFilterAdvice.java b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/ApacheMonitorFilterAdvice.java index 14051bc2143..bdfa1f113ca 100644 --- a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/ApacheMonitorFilterAdvice.java +++ b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/advice/ApacheMonitorFilterAdvice.java @@ -20,12 +20,7 @@ import co.elastic.apm.agent.dubbo.helper.ApacheDubboTextMapPropagator; import co.elastic.apm.agent.dubbo.helper.DubboTraceHelper; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.util.PrivilegedActionUtils; import net.bytebuddy.asm.Advice; import org.apache.dubbo.rpc.AsyncRpcResult; @@ -47,7 +42,7 @@ public static Object onEnterFilterInvoke(@Advice.Argument(1) Invocation invocati AbstractSpan active = tracer.getActive(); // for consumer side, just create span, more information will be collected in provider side if (context.isConsumerSide() && active != null) { - Span span = DubboTraceHelper.createConsumerSpan(tracer, invocation.getInvoker().getInterface(), + Span span = DubboTraceHelper.createConsumerSpan(tracer, invocation.getInvoker().getInterface(), invocation.getMethodName(), context.getRemoteAddress()); if (span != null) { span.propagateTraceContext(context, ApacheDubboTextMapPropagator.INSTANCE); @@ -55,7 +50,7 @@ public static Object onEnterFilterInvoke(@Advice.Argument(1) Invocation invocati } } else if (context.isProviderSide() && active == null) { // for provider side - Transaction transaction = tracer.startChildTransaction(context, ApacheDubboTextMapPropagator.INSTANCE, PrivilegedActionUtils.getClassLoader(Invocation.class)); + Transaction transaction = tracer.startChildTransaction(context, ApacheDubboTextMapPropagator.INSTANCE, PrivilegedActionUtils.getClassLoader(Invocation.class)); if (transaction != null) { transaction.activate(); DubboTraceHelper.fillTransaction(transaction, invocation.getInvoker().getInterface(), invocation.getMethodName()); @@ -104,7 +99,7 @@ public void accept(@Nullable Result result, @Nullable Throwable t) { span.captureException(t) .captureException(resultException) - .withOutcome(t != null || resultException != null ? Outcome.FAILURE : Outcome.SUCCESS); + .withOutcome(t != null || resultException != null ? DefaultOutcome.FAILURE : DefaultOutcome.SUCCESS); } finally { span.end(); } diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/AlibabaDubboTextMapPropagator.java b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/AlibabaDubboTextMapPropagator.java index 3f62bc36a34..c8e75f04f9d 100644 --- a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/AlibabaDubboTextMapPropagator.java +++ b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/AlibabaDubboTextMapPropagator.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.dubbo.helper; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import com.alibaba.dubbo.rpc.RpcContext; import javax.annotation.Nullable; diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/ApacheDubboTextMapPropagator.java b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/ApacheDubboTextMapPropagator.java index 40428337406..de84a37fc80 100644 --- a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/ApacheDubboTextMapPropagator.java +++ b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/ApacheDubboTextMapPropagator.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.dubbo.helper; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import org.apache.dubbo.rpc.RpcContext; import javax.annotation.Nullable; diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/DubboTraceHelper.java b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/DubboTraceHelper.java index 9787f9fe303..eb02e9db7b6 100644 --- a/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/DubboTraceHelper.java +++ b/apm-agent-plugins/apm-dubbo-plugin/src/main/java/co/elastic/apm/agent/dubbo/helper/DubboTraceHelper.java @@ -18,11 +18,7 @@ */ package co.elastic.apm.agent.dubbo.helper; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.context.Destination; -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.plugin.spi.*; import javax.annotation.Nullable; import java.net.InetSocketAddress; @@ -34,12 +30,12 @@ public class DubboTraceHelper { public static final String SPAN_KEY = "_elastic_apm_span"; @Nullable - public static Span createConsumerSpan(Tracer tracer, Class apiClass, String methodName, InetSocketAddress remoteAddress) { + public static Span createConsumerSpan(Tracer tracer, Class apiClass, String methodName, InetSocketAddress remoteAddress) { AbstractSpan traceContext = tracer.getActive(); if (traceContext == null) { return null; } - Span span = traceContext.createExitSpan(); + Span span = traceContext.createExitSpan(); if (span == null) { return null; } @@ -59,7 +55,7 @@ public static Span createConsumerSpan(Tracer tracer, Class apiClass, String m return span.activate(); } - public static void fillTransaction(Transaction transaction, Class apiClass, String methodName) { + public static void fillTransaction(Transaction transaction, Class apiClass, String methodName) { transaction.updateName(apiClass, methodName); transaction.withType(Transaction.TYPE_REQUEST); } diff --git a/apm-agent-plugins/apm-ecs-logging-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/Log4j2ServiceNameInstrumentation.java b/apm-agent-plugins/apm-ecs-logging-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/Log4j2ServiceNameInstrumentation.java index 3c999803926..d8a079a5fc3 100644 --- a/apm-agent-plugins/apm-ecs-logging-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/Log4j2ServiceNameInstrumentation.java +++ b/apm-agent-plugins/apm-ecs-logging-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/Log4j2ServiceNameInstrumentation.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.ecs_logging; import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.ServiceInfo; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.ServiceInfo; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.logging.log4j2.EcsLayout; import net.bytebuddy.asm.Advice; diff --git a/apm-agent-plugins/apm-ecs-logging-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/Log4j2ServiceVersionInstrumentation.java b/apm-agent-plugins/apm-ecs-logging-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/Log4j2ServiceVersionInstrumentation.java index bb19d0fd9a0..a0b6e6c35ee 100644 --- a/apm-agent-plugins/apm-ecs-logging-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/Log4j2ServiceVersionInstrumentation.java +++ b/apm-agent-plugins/apm-ecs-logging-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/Log4j2ServiceVersionInstrumentation.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.ecs_logging; import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.ServiceInfo; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.ServiceInfo; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.logging.log4j2.EcsLayout; import net.bytebuddy.asm.Advice; 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/esrestclient/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/esrestclient/v5_6/ElasticsearchClientAsyncInstrumentation.java index 10b9b54fa5c..2805b8e0f6e 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/esrestclient/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/esrestclient/v5_6/ElasticsearchClientAsyncInstrumentation.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentation; import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentationHelper; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument; import net.bytebuddy.description.method.MethodDescription; @@ -75,7 +75,7 @@ public static Object[] onBeforeExecute(@Advice.Argument(0) String method, @Advice.Argument(3) @Nullable HttpEntity entity, @Advice.Argument(5) ResponseListener responseListener) { - Span span = helper.createClientSpan(method, endpoint, entity); + Span span = helper.createClientSpan(method, endpoint, entity); if (span != null) { Object[] ret = new Object[2]; ret[0] = span; @@ -89,7 +89,7 @@ public static Object[] onBeforeExecute(@Advice.Argument(0) String method, public static void onAfterExecute(@Advice.Thrown @Nullable Throwable t, @Advice.Enter @Nullable Object[] entryArgs) { if (entryArgs != null) { - final Span span = (Span) entryArgs[0]; + final Span span = (Span) entryArgs[0]; if (span != null) { // Deactivate in this thread. Span will be ended and reported by the listener span.deactivate(); diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/esrestclient/v5_6/ElasticsearchClientSyncInstrumentation.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/esrestclient/v5_6/ElasticsearchClientSyncInstrumentation.java index 3e9dc348625..158d04a0b3a 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/esrestclient/v5_6/ElasticsearchClientSyncInstrumentation.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/main/java/co/elastic/apm/agent/esrestclient/v5_6/ElasticsearchClientSyncInstrumentation.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentation; import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentationHelper; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -54,7 +54,7 @@ public static Object onBeforeExecute(@Advice.Argument(0) String method, public static void onAfterExecute(@Advice.Return @Nullable Response response, @Advice.Enter @Nullable Object spanObj, @Advice.Thrown @Nullable Throwable t) { - Span span = (Span) spanObj; + Span span = (Span) spanObj; if (span != null) { try { helper.finishClientSpan(response, span, t); diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/esrestclient/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/esrestclient/v6_4/ElasticsearchClientAsyncInstrumentation.java index ecefa86231e..139146e03c4 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/esrestclient/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/esrestclient/v6_4/ElasticsearchClientAsyncInstrumentation.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentation; import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentationHelper; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument; import net.bytebuddy.description.method.MethodDescription; @@ -66,7 +66,7 @@ public static class ElasticsearchRestClientAsyncAdvice { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object[] onBeforeExecute(@Advice.Argument(0) Request request, @Advice.Argument(1) ResponseListener responseListener) { - Span span = helper.createClientSpan(request.getMethod(), request.getEndpoint(), request.getEntity()); + Span span = helper.createClientSpan(request.getMethod(), request.getEndpoint(), request.getEntity()); if (span != null) { Object[] ret = new Object[2]; ret[0] = span; @@ -80,7 +80,7 @@ public static Object[] onBeforeExecute(@Advice.Argument(0) Request request, public static void onAfterExecute(@Advice.Thrown @Nullable Throwable t, @Advice.Enter @Nullable Object[] entryArgs) { if (entryArgs != null) { - final Span span = (Span) entryArgs[0]; + final Span span = (Span) entryArgs[0]; if (span != null) { // Deactivate in this thread. Span will be ended and reported by the listener span.deactivate(); diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/esrestclient/v6_4/ElasticsearchClientSyncInstrumentation.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/esrestclient/v6_4/ElasticsearchClientSyncInstrumentation.java index b87ec3f5c3f..e44a57a2e21 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/esrestclient/v6_4/ElasticsearchClientSyncInstrumentation.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/main/java/co/elastic/apm/agent/esrestclient/v6_4/ElasticsearchClientSyncInstrumentation.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentation; import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentationHelper; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -67,7 +67,7 @@ public static Object onBeforeExecute(@Advice.Argument(0) Request request) { public static void onAfterExecute(@Advice.Return @Nullable Response response, @Advice.Enter @Nullable Object spanObj, @Advice.Thrown @Nullable Throwable t) { - Span span = (Span) spanObj; + Span span = (Span) spanObj; if (span != null) { try { helper.finishClientSpan(response, span, t); diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-7_x/src/main/java/co/elastic/apm/agent/esrestclient/v7_x/RestClientInstrumentation.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-7_x/src/main/java/co/elastic/apm/agent/esrestclient/v7_x/RestClientInstrumentation.java index 36e7125be24..463a72f2fda 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-7_x/src/main/java/co/elastic/apm/agent/esrestclient/v7_x/RestClientInstrumentation.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-7_x/src/main/java/co/elastic/apm/agent/esrestclient/v7_x/RestClientInstrumentation.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentation; import co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentationHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.AbstractSpan; import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument; import net.bytebuddy.description.method.MethodDescription; diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelper.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelper.java index a6fe28df96a..2a5fc8f37d2 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelper.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelper.java @@ -19,13 +19,7 @@ package co.elastic.apm.agent.esrestclient; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.objectpool.Allocator; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.util.IOUtils; @@ -79,13 +73,13 @@ public ResponseListenerWrapper createInstance() { } @Nullable - public Span createClientSpan(String method, String endpoint, @Nullable HttpEntity httpEntity) { + public Span createClientSpan(String method, String endpoint, @Nullable HttpEntity httpEntity) { final AbstractSpan activeSpan = tracer.getActive(); if (activeSpan == null) { return null; } - Span span = activeSpan.createExitSpan(); + Span span = activeSpan.createExitSpan(); // Don't record nested spans. In 5.x clients the instrumented sync method is calling the instrumented async method if (span == null) { @@ -120,7 +114,7 @@ public Span createClientSpan(String method, String endpoint, @Nullable HttpEntit return span; } - public void finishClientSpan(@Nullable Response response, Span span, @Nullable Throwable t) { + public void finishClientSpan(@Nullable Response response, Span span, @Nullable Throwable t) { try { String url = null; int statusCode = -1; @@ -146,7 +140,7 @@ public void finishClientSpan(@Nullable Response response, Span span, @Nullable T statusCode = esre.getResponse().getStatusLine().getStatusCode(); } else if (t instanceof CancellationException) { // We can't tell whether a cancelled search is related to a failure or not - span.withOutcome(Outcome.UNKNOWN); + span.withOutcome(DefaultOutcome.UNKNOWN); } span.captureException(t); } @@ -162,7 +156,7 @@ public void finishClientSpan(@Nullable Response response, Span span, @Nullable T } } - public ResponseListener wrapClientResponseListener(ResponseListener listener, Span span) { + public ResponseListener wrapClientResponseListener(ResponseListener listener, Span span) { return responseListenerObjectPool.createInstance().withClientSpan(listener, span); } diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ResponseListenerWrapper.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ResponseListenerWrapper.java index de31f44fb32..608a38c3498 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ResponseListenerWrapper.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/main/java/co/elastic/apm/agent/esrestclient/ResponseListenerWrapper.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.esrestclient; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.objectpool.Recyclable; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseListener; @@ -49,7 +49,7 @@ public class ResponseListenerWrapper implements ResponseListener, Recyclable { this.tracer = tracer; } - ResponseListenerWrapper withClientSpan(ResponseListener delegate, Span span) { + ResponseListenerWrapper withClientSpan(ResponseListener delegate, Span span) { // Order is important due to visibility - write to span last on this (initiating) thread this.delegate = delegate; this.isClientSpan = true; @@ -144,8 +144,8 @@ private void onFailureContextPropagation(Exception exception) { private void finishClientSpan(@Nullable Response response, @Nullable Throwable throwable) { // First read volatile span to ensure visibility on executing thread AbstractSpan localSpan = context; - if (localSpan instanceof Span) { - helper.finishClientSpan(response, (Span) localSpan, throwable); + if (localSpan instanceof Span) { + helper.finishClientSpan(response, (Span) localSpan, throwable); } } diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/test/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelperTest.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/test/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelperTest.java index 04c7d6b1dd2..df8ca9e6a85 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/test/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelperTest.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/test/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelperTest.java @@ -56,7 +56,7 @@ void after(){ @Test void testCreateSpan() { - Span span = helper.createClientSpan("GET", "/_test", null); + Span span = (Span) helper.createClientSpan("GET", "/_test", null); assertThat(span).isNotNull(); assertThat(tracer.getActive()).isEqualTo(span); @@ -81,7 +81,7 @@ void testCreateSpan() { @Test void testCreateSpanWithClusterName() { - Span span = helper.createClientSpan("GET", "/_test", null); + Span span = (Span) helper.createClientSpan("GET", "/_test", null); assertThat(span).isNotNull(); assertThat(tracer.getActive()).isEqualTo(span); @@ -121,7 +121,7 @@ private static Response mockResponse(Map headers) { @Test void testNonSampledSpan() { TransactionTest.setRecorded(false, transaction); - Span esSpan = helper.createClientSpan("SEARCH", "/test", null); + Span esSpan = (Span) helper.createClientSpan("SEARCH", "/test", null); assertThat(esSpan).isNotNull(); try { assertThat(esSpan.isSampled()).isFalse(); diff --git a/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/FinagleExceptionSourceFilterInstrumentation.java b/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/FinagleExceptionSourceFilterInstrumentation.java index bf28a6ab93a..fc4fec63c7d 100644 --- a/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/FinagleExceptionSourceFilterInstrumentation.java +++ b/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/FinagleExceptionSourceFilterInstrumentation.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import com.twitter.finagle.http.Request; @@ -91,7 +91,7 @@ public static class ExceptionSourceFilterAdvice { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void onBeforeExecute(@Nullable @Advice.Argument(0) Object serviceArg, @Nullable @Advice.FieldValue(SERVICE_NAME_FIELD) String serviceName) { if (serviceArg instanceof Request) { - Span spanToEnhance = FinaglePayloadSizeFilterInstrumentation.PayloadSizeFilterAdvice + Span spanToEnhance = FinaglePayloadSizeFilterInstrumentation.PayloadSizeFilterAdvice .getAndRemoveSpanWithUnknownHostForRequest((Request) serviceArg); if (spanToEnhance != null && serviceName != null && !serviceName.isEmpty()) { updateSpanHostname(spanToEnhance, serviceName); @@ -100,7 +100,7 @@ public static void onBeforeExecute(@Nullable @Advice.Argument(0) Object serviceA } } - private static void updateSpanHostname(Span spanToEnhance, String serviceName) { + private static void updateSpanHostname(Span spanToEnhance, String serviceName) { CharSequence currentUriStr = spanToEnhance.getContext().getHttp().getUrl(); String method = spanToEnhance.getContext().getHttp().getMethod(); if (currentUriStr.length() == 0 || method == null || method.isEmpty()) { diff --git a/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/FinaglePayloadSizeFilterInstrumentation.java b/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/FinaglePayloadSizeFilterInstrumentation.java index f4eaeae510e..ff3555e0f9d 100644 --- a/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/FinaglePayloadSizeFilterInstrumentation.java +++ b/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/FinaglePayloadSizeFilterInstrumentation.java @@ -22,13 +22,13 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.finaglehttpclient.helper.RequestHeaderAccessor; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; +import co.elastic.apm.plugin.spi.TraceContextUtil; import com.twitter.finagle.http.Request; import com.twitter.finagle.http.Response; import com.twitter.finagle.tracing.Trace; @@ -92,7 +92,7 @@ public String getAdviceClassName() { public static class PayloadSizeFilterAdvice { - private static final WeakMap inflightSpansWithUnknownHost = WeakConcurrent.buildMap(); + private static final WeakMap> inflightSpansWithUnknownHost = WeakConcurrent.buildMap(); /** * The PayloadSizeFilterAdvice is executed both for server and client requests. @@ -109,7 +109,7 @@ public static class PayloadSizeFilterAdvice { } @Nullable - public static Span getAndRemoveSpanWithUnknownHostForRequest(Request forRequest) { + public static Span getAndRemoveSpanWithUnknownHostForRequest(Request forRequest) { return inflightSpansWithUnknownHost.remove(forRequest); } @@ -140,7 +140,7 @@ public static Object onBeforeExecute(@Nullable @Advice.Argument(0) Request reque } URI uri = resolveURI(request, host); - Span span = HttpClientHelper.startHttpClientSpan(parent, request.method().name(), uri, null); + Span span = HttpClientHelper.startHttpClientSpan(parent, request.method().name(), uri, null); if (span != null) { span.activate(); @@ -149,10 +149,10 @@ public static Object onBeforeExecute(@Nullable @Advice.Argument(0) Request reque } } - if (!TraceContext.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { + if (!TraceContextUtil.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { if (span != null) { span.propagateTraceContext(request, RequestHeaderAccessor.INSTANCE); - } else if (!TraceContext.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { + } else if (!TraceContextUtil.containsTraceContextTextHeaders(request, RequestHeaderAccessor.INSTANCE)) { // adds headers of potential parent exit-spans parent.propagateTraceContext(request, RequestHeaderAccessor.INSTANCE); } @@ -185,7 +185,7 @@ public static void onExit( if (spanObj == null) { return; } - final Span span = (Span) spanObj; + final Span span = (Span) spanObj; span.deactivate(); if (thrown != null) { span.captureException(thrown); @@ -210,7 +210,7 @@ public void onFailure(Throwable cause) { } } - private static void endSpanForRequest(@Nullable Request request, Span span) { + private static void endSpanForRequest(@Nullable Request request, Span span) { if (request != null) { // should always be true because otherwise no span is created inflightSpansWithUnknownHost.remove(request); } diff --git a/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/helper/RequestHeaderAccessor.java b/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/helper/RequestHeaderAccessor.java index 19e2741c6dd..7b8eb97aed5 100644 --- a/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/helper/RequestHeaderAccessor.java +++ b/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/helper/RequestHeaderAccessor.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.finaglehttpclient.helper; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import com.twitter.finagle.http.Request; import scala.Option; import scala.collection.Iterator; diff --git a/apm-agent-plugins/apm-grails-plugin/src/main/java/co/elastic/apm/agent/grails/GrailsTransactionNameInstrumentation.java b/apm-agent-plugins/apm-grails-plugin/src/main/java/co/elastic/apm/agent/grails/GrailsTransactionNameInstrumentation.java index 17f9d897089..fa3058ab488 100644 --- a/apm-agent-plugins/apm-grails-plugin/src/main/java/co/elastic/apm/agent/grails/GrailsTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-grails-plugin/src/main/java/co/elastic/apm/agent/grails/GrailsTransactionNameInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.grails; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.TransactionNameUtils; import grails.core.GrailsControllerClass; import net.bytebuddy.asm.Advice; @@ -32,7 +32,7 @@ import java.util.Collections; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; import static grails.core.GrailsControllerClass.INDEX_ACTION; import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; import static net.bytebuddy.matcher.ElementMatchers.isInterface; @@ -82,7 +82,7 @@ public static class HandlerAdapterAdvice { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setTransactionName(@Advice.Argument(2) Object handler) { - final Transaction transaction = tracer.currentTransaction(); + final Transaction transaction = tracer.currentTransaction(); if (transaction == null) { return; } diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ChannelInstrumentation.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ChannelInstrumentation.java index 13a4bd22053..899aa03553e 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ChannelInstrumentation.java +++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ChannelInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.grpc; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.sdk.DynamicTransformer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import io.grpc.CallOptions; @@ -92,7 +92,7 @@ public static void onExit(@Advice.Return @Nullable ClientCall clientCall, if (clientCall != null) { DynamicTransformer.ensureInstrumented(clientCall.getClass(), CLIENT_CALL_INSTRUMENTATION); } - GrpcHelper.getInstance().onClientCallCreationExit(clientCall, (Span) span); + GrpcHelper.getInstance().onClientCallCreationExit(clientCall, (Span) span); } } } 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 e70062c967c..10809797137 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 @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.grpc; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.sdk.DynamicTransformer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import io.grpc.ClientCall; @@ -96,7 +96,7 @@ public static void onExit(@Advice.Argument(0) ClientCall.Listener listener, @Advice.Thrown @Nullable Throwable thrown, @Advice.Enter @Nullable Object span) { - GrpcHelper.getInstance().clientCallStartExit((Span) span, listener, thrown); + GrpcHelper.getInstance().clientCallStartExit((Span) span, listener, thrown); } } } diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ClientCallListenerInstrumentation.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ClientCallListenerInstrumentation.java index f6eecaea683..d4894b78da8 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ClientCallListenerInstrumentation.java +++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ClientCallListenerInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.grpc; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.sdk.DynamicTransformer; import io.grpc.ClientCall; import io.grpc.Metadata; @@ -74,7 +74,7 @@ public static void onExit(@Advice.This ClientCall.Listener listener, @Advice.Thrown @Nullable Throwable thrown, @Advice.Enter @Nullable Object span) { - GrpcHelper.getInstance().exitClientListenerMethod(thrown, listener, (Span) span, status); + GrpcHelper.getInstance().exitClientListenerMethod(thrown, listener, (Span) span, status); } } } @@ -115,7 +115,7 @@ public static void onExit(@Advice.This ClientCall.Listener listener, @Advice.Thrown @Nullable Throwable thrown, @Advice.Enter @Nullable Object span) { - GrpcHelper.getInstance().exitClientListenerMethod(thrown, listener, (Span) span, null); + GrpcHelper.getInstance().exitClientListenerMethod(thrown, listener, (Span) span, null); } } } diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/GrpcHelper.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/GrpcHelper.java index f4090f6e624..0c655c73f54 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/GrpcHelper.java +++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/GrpcHelper.java @@ -19,17 +19,7 @@ package co.elastic.apm.agent.grpc; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.context.Destination; -import co.elastic.apm.agent.impl.transaction.AbstractHeaderGetter; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import io.grpc.CallOptions; @@ -50,6 +40,8 @@ public class GrpcHelper { private static final String FRAMEWORK_NAME = "gRPC"; + private static final Tracer tracer = GlobalTracer.get(); + private static final GrpcHelper INSTANCE = new GrpcHelper(); public static GrpcHelper getInstance() { @@ -59,27 +51,27 @@ public static GrpcHelper getInstance() { /** * Map of all in-flight {@link Span} with {@link ClientCall} instance as key. */ - private final WeakMap, Span> clientCallSpans; + private final WeakMap, Span> clientCallSpans; /** * Map of all in-flight {@link Span} with {@link ClientCall} instance as key. */ - private final WeakMap, Span> delayedClientCallSpans; + private final WeakMap, Span> delayedClientCallSpans; /** * Map of all in-flight {@link Span} with {@link ClientCall.Listener} instance as key. */ - private final WeakMap, Span> clientCallListenerSpans; + private final WeakMap, Span> clientCallListenerSpans; /** * Map of all in-flight {@link Transaction} with {@link ServerCall.Listener} instance as key. */ - private final WeakMap, Transaction> serverListenerTransactions; + private final WeakMap, Transaction> serverListenerTransactions; /** * Map of all in-flight {@link Transaction} with {@link ServerCall} instance as key. */ - private final WeakMap, Transaction> serverCallTransactions; + private final WeakMap, Transaction> serverCallTransactions; /** * gRPC header cache used to minimize allocations @@ -115,7 +107,7 @@ public GrpcHelper() { * @return transaction, or {@literal null} if none has been created */ @Nullable - public Transaction startTransaction(Tracer tracer, ClassLoader cl, ServerCall serverCall, Metadata headers) { + public Transaction startTransaction(Tracer tracer, ClassLoader cl, ServerCall serverCall, Metadata headers) { MethodDescriptor methodDescriptor = serverCall.getMethodDescriptor(); // ignore non-unary method calls for now @@ -129,7 +121,7 @@ public Transaction startTransaction(Tracer tracer, ClassLoader cl, ServerCall transaction = tracer.startChildTransaction(headers, headerGetter, cl); if (transaction == null) { return null; } @@ -149,7 +141,7 @@ public Transaction startTransaction(Tracer tracer, ClassLoader cl, ServerCall serverCall, ServerCall.Listener listener, Transaction transaction) { + public void registerTransaction(ServerCall serverCall, ServerCall.Listener listener, Transaction transaction) { serverCallTransactions.put(serverCall, transaction); serverListenerTransactions.put(listener, transaction); transaction.deactivate(); @@ -164,7 +156,7 @@ public void registerTransaction(ServerCall serverCall, ServerCall.Listener * @param serverCall server call */ public void exitServerCall(Status status, @Nullable Throwable thrown, ServerCall serverCall) { - Transaction transaction = serverCallTransactions.remove(serverCall); + Transaction transaction = serverCallTransactions.remove(serverCall); if (transaction != null) { // there are multiple ways to terminate transaction, which aren't mutually exclusive @@ -172,7 +164,7 @@ public void exitServerCall(Status status, @Nullable Throwable thrown, ServerCall // 1. thrown exception within any of ServerCall.Listener methods // 2. ServerCall.onClose, which might falsely report 'OK' status after a thrown listener exception. // in this case we just have to ignore the reported status if already set - if (Outcome.UNKNOWN == transaction.getOutcome()) { + if (transaction.getOutcome().name().equals(DefaultOutcome.UNKNOWN.name())) { transaction.withOutcome(toServerOutcome(status)) .withResultIfUnset(status.getCode().name()); // keep outcome and result consistent } @@ -186,15 +178,15 @@ public void exitServerCall(Status status, @Nullable Throwable thrown, ServerCall public static Outcome toClientOutcome(@Nullable Status status) { if (status == null || !status.isOk()) { - return Outcome.FAILURE; + return DefaultOutcome.FAILURE; } else { - return Outcome.SUCCESS; + return DefaultOutcome.SUCCESS; } } public static Outcome toServerOutcome(@Nullable Status status) { if (status == null) { - return Outcome.FAILURE; + return DefaultOutcome.FAILURE; } switch (status.getCode()) { case UNKNOWN: @@ -205,9 +197,9 @@ public static Outcome toServerOutcome(@Nullable Status status) { case INTERNAL: case UNAVAILABLE: case DATA_LOSS: - return Outcome.FAILURE; + return DefaultOutcome.FAILURE; default: - return Outcome.SUCCESS; + return DefaultOutcome.SUCCESS; } } @@ -218,8 +210,8 @@ public static Outcome toServerOutcome(@Nullable Status status) { * @return transaction, or {@literal null} if there is none */ @Nullable - public Transaction enterServerListenerMethod(ServerCall.Listener listener) { - Transaction transaction = serverListenerTransactions.get(listener); + public Transaction enterServerListenerMethod(ServerCall.Listener listener) { + Transaction transaction = serverListenerTransactions.get(listener); if (transaction != null) { transaction.activate(); } @@ -236,7 +228,7 @@ public Transaction enterServerListenerMethod(ServerCall.Listener listener) { */ public void exitServerListenerMethod(@Nullable Throwable thrown, ServerCall.Listener listener, - @Nullable Transaction transaction, + @Nullable Transaction transaction, @Nullable Status terminateStatus) { if (transaction == null) { @@ -258,7 +250,7 @@ public void exitServerListenerMethod(@Nullable Throwable thrown, terminateStatus = Status.fromThrowable(thrown); setTerminateStatus = true; - } else if (transaction.getOutcome() == Outcome.UNKNOWN) { + } else if (transaction.getOutcome().name().equals(DefaultOutcome.UNKNOWN.name())) { setTerminateStatus = true; } @@ -285,7 +277,7 @@ public void exitServerListenerMethod(@Nullable Throwable thrown, * @return client call span (activated) or {@literal null} if not within an exit span. */ @Nullable - public Span onClientCallCreationEntry(@Nullable AbstractSpan parent, + public Span onClientCallCreationEntry(@Nullable AbstractSpan parent, @Nullable MethodDescriptor method, @Nullable String authority) { @@ -298,7 +290,7 @@ public Span onClientCallCreationEntry(@Nullable AbstractSpan parent, return null; } - Span span = parent.createExitSpan(); + Span span = parent.createExitSpan(); if (span == null) { // as it's an external call, we only need a single span for nested calls return null; @@ -328,12 +320,12 @@ public Span onClientCallCreationEntry(@Nullable AbstractSpan parent, * @param clientCall client call * @param spanFromEntry span created at {@link #onClientCallCreationEntry(AbstractSpan, MethodDescriptor, String)} */ - public void onClientCallCreationExit(@Nullable ClientCall clientCall, @Nullable Span spanFromEntry) { + public void onClientCallCreationExit(@Nullable ClientCall clientCall, @Nullable Span spanFromEntry) { if (clientCall != null) { - Span spanToMap = spanFromEntry; + Span spanToMap = spanFromEntry; if (spanToMap == null) { // handling nested newCall() invocations - we still want to map the client call to the same span - Span tmp = GlobalTracer.get().getActiveSpan(); + Span tmp = tracer.getActiveSpan(); if (tmp != null && tmp.getSubtype() != null && tmp.getSubtype().equals(GRPC) && tmp.isExit()) { spanToMap = tmp; } @@ -385,7 +377,7 @@ private boolean isDelayedClientCall(ClientCall clientCall) { public void replaceClientCallRegistration(ClientCall placeholderClientCall, ClientCall realClientCall) { // we cannot remove yet, because the span could have been ended already through ClientCall#start(), in which case // it will be recycled ahead of time due to reference decrement when removed from the map - Span spanOfPlaceholder = delayedClientCallSpans.get(placeholderClientCall); + Span spanOfPlaceholder = delayedClientCallSpans.get(placeholderClientCall); if (spanOfPlaceholder == null) { return; } @@ -393,7 +385,7 @@ public void replaceClientCallRegistration(ClientCall placeholderClientCall try { // we cannot remove yet, because the span could have been ended already, in which case // it will be recycled ahead of time due to reference decrement when removed from the map - Span spanOfRealClientCall = clientCallSpans.get(realClientCall); + Span spanOfRealClientCall = clientCallSpans.get(realClientCall); boolean mapPlaceholderSpanToRealClientCall = false; if (spanOfRealClientCall == null) { mapPlaceholderSpanToRealClientCall = true; @@ -432,20 +424,20 @@ public void replaceClientCallRegistration(ClientCall placeholderClientCall * @return span, or {@literal null is there is none} */ @Nullable - public Span clientCallStartEnter(ClientCall clientCall, - ClientCall.Listener listener, - Metadata headers) { + public Span clientCallStartEnter(ClientCall clientCall, + ClientCall.Listener listener, + Metadata headers) { // span should already have been registered // no other lookup by client call is required, thus removing entry - Span span = clientCallSpans.remove(clientCall); + Span span = clientCallSpans.remove(clientCall); if (span == null) { return null; } clientCallListenerSpans.put(listener, span); - if (!TraceContext.containsTraceContextTextHeaders(headers, headerGetter)) { + if (!TraceContextUtil.containsTraceContextTextHeaders(headers, headerGetter)) { span.propagateTraceContext(headers, headerSetter); } @@ -459,7 +451,7 @@ public Span clientCallStartEnter(ClientCall clientCall, * @param listener client call listener * @param thrown thrown exception */ - public void clientCallStartExit(@Nullable Span spanFromEntry, ClientCall.Listener listener, @Nullable Throwable thrown) { + public void clientCallStartExit(@Nullable Span spanFromEntry, ClientCall.Listener listener, @Nullable Throwable thrown) { if (spanFromEntry != null) { spanFromEntry.deactivate(); } @@ -467,16 +459,16 @@ public void clientCallStartExit(@Nullable Span spanFromEntry, ClientCall.Listene // when there is an exception, we have to end span and perform some cleanup clientCallListenerSpans.remove(listener); if (spanFromEntry != null) { - spanFromEntry.withOutcome(Outcome.FAILURE) + spanFromEntry.withOutcome(DefaultOutcome.FAILURE) .end(); } } } public void cancelCall(ClientCall clientCall, @Nullable Throwable cause) { - WeakMap, Span> clientCallMap = (isDelayedClientCall(clientCall)) ? delayedClientCallSpans : clientCallSpans; + WeakMap, Span> clientCallMap = (isDelayedClientCall(clientCall)) ? delayedClientCallSpans : clientCallSpans; // we can't remove yet, in order to avoid reference decrement prematurely - Span span = clientCallMap.get(clientCall); + Span span = clientCallMap.get(clientCall); if (span != null) { if (!span.isFinished()) { span @@ -495,14 +487,14 @@ public void cancelCall(ClientCall clientCall, @Nullable Throwable cause) { * @return active span or {@literal null} if there is none */ @Nullable - public Span enterClientListenerMethod(ClientCall.Listener listener) { - Span span = clientCallListenerSpans.get(listener); + public Span enterClientListenerMethod(ClientCall.Listener listener) { + Span span = clientCallListenerSpans.get(listener); if (span != null) { if (span.isFinished()) { // the span may have already been ended by another listener on a different thread/stack clientCallListenerSpans.remove(listener); span = null; - } else if (span == GlobalTracer.get().getActiveSpan()) { + } else if (span == tracer.getActiveSpan()) { // avoid duplicated activation and invocation on nested listener method calls span = null; } else { @@ -522,7 +514,7 @@ public Span enterClientListenerMethod(ClientCall.Listener listener) { */ public void exitClientListenerMethod(@Nullable Throwable thrown, ClientCall.Listener listener, - @Nullable Span span, + @Nullable Span span, @Nullable Status onCloseStatus) { boolean lastCall = onCloseStatus != null || thrown != null; diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ServerCallHandlerInstrumentation.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ServerCallHandlerInstrumentation.java index b5a4d728a15..6233cdb0d9b 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ServerCallHandlerInstrumentation.java +++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ServerCallHandlerInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.grpc; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.DynamicTransformer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.util.PrivilegedActionUtils; @@ -94,10 +94,10 @@ public static void onExit(@Advice.Thrown @Nullable Throwable thrown, @Advice.Return @Nullable ServerCall.Listener listener, @Advice.Enter @Nullable Object enterTransaction) { - if (!(enterTransaction instanceof Transaction)) { + if (!(enterTransaction instanceof Transaction)) { return; } - Transaction transaction = (Transaction) enterTransaction; + Transaction transaction = (Transaction) enterTransaction; if (thrown != null) { // terminate transaction in case of exception as it won't be stored transaction.deactivate().end(); diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ServerCallListenerInstrumentation.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ServerCallListenerInstrumentation.java index 1bbb671cf5a..d693e6d45ef 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ServerCallListenerInstrumentation.java +++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/ServerCallListenerInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.grpc; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.DynamicTransformer; import io.grpc.ServerCall; import io.grpc.Status; @@ -92,8 +92,8 @@ public static void onExit(@Advice.Thrown @Nullable Throwable thrown, @Advice.This ServerCall.Listener listener, @Advice.Enter @Nullable Object transaction) { - if (transaction instanceof Transaction) { - GrpcHelper.getInstance().exitServerListenerMethod(thrown, listener, (Transaction) transaction, null); + if (transaction instanceof Transaction) { + GrpcHelper.getInstance().exitServerListenerMethod(thrown, listener, (Transaction) transaction, null); } } } @@ -128,7 +128,7 @@ public static void onExit(@Advice.Thrown @Nullable Throwable thrown, @Advice.Enter @Nullable Object transaction) { if (transaction instanceof Transaction) { - GrpcHelper.getInstance().exitServerListenerMethod(thrown, listener, (Transaction) transaction, Status.CANCELLED); + GrpcHelper.getInstance().exitServerListenerMethod(thrown, listener, (Transaction) transaction, Status.CANCELLED); } } } @@ -163,7 +163,7 @@ public static void onExit(@Advice.Thrown @Nullable Throwable thrown, @Advice.Enter @Nullable Object transaction) { if (transaction instanceof Transaction) { - GrpcHelper.getInstance().exitServerListenerMethod(thrown, listener, (Transaction) transaction, Status.OK); + GrpcHelper.getInstance().exitServerListenerMethod(thrown, listener, (Transaction) transaction, Status.OK); } } } diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/specs/OutcomeGrpcStepsDefinitions.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/specs/OutcomeGrpcStepsDefinitions.java index 275fca7d9fb..cc35545f2de 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/specs/OutcomeGrpcStepsDefinitions.java +++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/specs/OutcomeGrpcStepsDefinitions.java @@ -38,15 +38,15 @@ public void grpcSpan(String grpcStatus) { state.startRootTransactionIfRequired(); state.startSpan() - .withName(String.format("gRPC span %s", grpcStatus)) - .withOutcome(getOutcome(grpcStatus, GrpcHelper::toClientOutcome)); + .withName(String.format("gRPC span %s", grpcStatus)); + // TODO Rafael .withOutcome(getOutcome(grpcStatus, GrpcHelper::toClientOutcome)); } @Given("a gRPC call is received that returns {string}") public void grpcTransaction(String grpcStatus) { state.startTransaction() - .withName(String.format("gRPC transaction %s", grpcStatus)) - .withOutcome(getOutcome(grpcStatus, GrpcHelper::toServerOutcome)); + .withName(String.format("gRPC transaction %s", grpcStatus)); + // TODO Rafael .withOutcome(getOutcome(grpcStatus, GrpcHelper::toServerOutcome)); } private static Outcome getOutcome(String grpcStatus, Function mapFunction) { diff --git a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-5_x/src/main/java/co/elastic/apm/agent/hibernatesearch/v5/HibernateSearch5Instrumentation.java b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-5_x/src/main/java/co/elastic/apm/agent/hibernatesearch/v5/HibernateSearch5Instrumentation.java index 2358c4bbb4d..045c7ab0e7c 100644 --- a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-5_x/src/main/java/co/elastic/apm/agent/hibernatesearch/v5/HibernateSearch5Instrumentation.java +++ b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-5_x/src/main/java/co/elastic/apm/agent/hibernatesearch/v5/HibernateSearch5Instrumentation.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.hibernatesearch.HibernateSearchConstants; import co.elastic.apm.agent.hibernatesearch.HibernateSearchHelper; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -90,8 +90,8 @@ public static Object onBeforeExecute(@Advice.This FullTextQueryImpl query, public static void onAfterExecute(@Advice.Enter @Nullable Object span, @Advice.Thrown Throwable t) { - if (span instanceof Span) { - ((Span) span).captureException(t) + if (span instanceof Span) { + ((Span) span).captureException(t) .deactivate() .end(); } diff --git a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-6_x/src/main/java/co/elastic/apm/agent/hibernatesearch/HibernateSearch6Instrumentation.java b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-6_x/src/main/java/co/elastic/apm/agent/hibernatesearch/HibernateSearch6Instrumentation.java index 0cf1875c80e..29880d93adb 100644 --- a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-6_x/src/main/java/co/elastic/apm/agent/hibernatesearch/HibernateSearch6Instrumentation.java +++ b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-6_x/src/main/java/co/elastic/apm/agent/hibernatesearch/HibernateSearch6Instrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.hibernatesearch; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -87,8 +87,8 @@ public static Object onBeforeExecute(@Advice.This SearchQuery query, public static void onAfterExecute(@Advice.Enter @Nullable Object span, @Advice.Thrown @Nullable Throwable t) { - if (span instanceof Span) { - ((Span) span).captureException(t) + if (span instanceof Span) { + ((Span) span).captureException(t) .deactivate() .end(); } diff --git a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/src/main/java/co/elastic/apm/agent/hibernatesearch/HibernateSearchHelper.java b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/src/main/java/co/elastic/apm/agent/hibernatesearch/HibernateSearchHelper.java index f33d869788f..a3d7bdfaa15 100644 --- a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/src/main/java/co/elastic/apm/agent/hibernatesearch/HibernateSearchHelper.java +++ b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/src/main/java/co/elastic/apm/agent/hibernatesearch/HibernateSearchHelper.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.hibernatesearch; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; public final class HibernateSearchHelper { @@ -28,17 +28,17 @@ private HibernateSearchHelper() { } - public static Span createAndActivateSpan(final Tracer tracer, final String methodName, + public static Span createAndActivateSpan(final Tracer tracer, final String methodName, final String query) { AbstractSpan active = tracer.getActive(); // avoid creating the same span twice for example, when an instrumented API is wrapped - if (active == null || active instanceof Span && HibernateSearchConstants.HIBERNATE_SEARCH_ORM_TYPE - .equals(((Span) active).getSubtype())) { + if (active == null || active instanceof Span && HibernateSearchConstants.HIBERNATE_SEARCH_ORM_TYPE + .equals(((Span) active).getSubtype())) { return null; } - Span span = active.createSpan().activate(); + Span span = active.createSpan().activate(); span.withType(HibernateSearchConstants.HIBERNATE_SEARCH_ORM_SPAN_TYPE) .withSubtype(HibernateSearchConstants.HIBERNATE_SEARCH_ORM_TYPE) diff --git a/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/HttpClientHelper.java b/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/HttpClientHelper.java index 6560e044d07..1e3e2fd7a2a 100644 --- a/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/HttpClientHelper.java +++ b/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/HttpClientHelper.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.httpclient; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -34,7 +34,7 @@ public class HttpClientHelper { public static final String HTTP_SUBTYPE = "http"; @Nullable - public static Span startHttpClientSpan(AbstractSpan parent, String method, @Nullable URI uri, @Nullable CharSequence hostName) { + public static Span startHttpClientSpan(AbstractSpan parent, String method, @Nullable URI uri, @Nullable CharSequence hostName) { String uriString = null; String scheme = null; int port = -1; @@ -50,9 +50,9 @@ public static Span startHttpClientSpan(AbstractSpan parent, String method, @N } @Nullable - public static Span startHttpClientSpan(AbstractSpan parent, String method, @Nullable String uri, + public static Span startHttpClientSpan(AbstractSpan parent, String method, @Nullable String uri, @Nullable String scheme, @Nullable CharSequence hostName, int port) { - Span span = parent.createExitSpan(); + Span span = parent.createExitSpan(); if (span != null) { updateHttpSpanNameAndContext(span, method, uri, scheme, hostName, port); } @@ -62,7 +62,7 @@ public static Span startHttpClientSpan(AbstractSpan parent, String method, @N return span; } - public static void updateHttpSpanNameAndContext(Span span, String method, @Nullable String uri, String scheme, CharSequence hostName, int port) { + public static void updateHttpSpanNameAndContext(Span span, String method, @Nullable String uri, String scheme, CharSequence hostName, int port) { span.withType(EXTERNAL_TYPE) .withSubtype(HTTP_SUBTYPE) .withName(method).appendToName(" ").appendToName(hostName != null ? hostName : "unknown host"); @@ -74,7 +74,7 @@ public static void updateHttpSpanNameAndContext(Span span, String method, @Nulla setDestinationServiceDetails(span, scheme, hostName, port); } - public static void setDestinationServiceDetails(Span span, @Nullable String scheme, @Nullable CharSequence host, int port) { + public static void setDestinationServiceDetails(Span span, @Nullable String scheme, @Nullable CharSequence host, int port) { if (scheme == null || host == null || host.length() == 0) { return; } diff --git a/apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/AbstractHttpClientInstrumentationTest.java b/apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/AbstractHttpClientInstrumentationTest.java index 933bcce865f..bd426ec72a4 100644 --- a/apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/AbstractHttpClientInstrumentationTest.java +++ b/apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/AbstractHttpClientInstrumentationTest.java @@ -20,16 +20,11 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.converter.TimeDuration; import co.elastic.apm.agent.impl.TextHeaderMapAccessor; import co.elastic.apm.agent.impl.context.Destination; import co.elastic.apm.agent.impl.context.Http; import co.elastic.apm.agent.impl.context.web.ResultUtil; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.*; import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.http.HttpHeader; @@ -329,7 +324,7 @@ private void verifyTraceContextHeaders(Span span, String path) { ); assertThat(headerCount.get()).isEqualTo(1); headerMap.forEach((key, value) -> assertThat(request.getHeader(key)).isEqualTo(value)); - Transaction transaction = tracer.startChildTransaction(request, new HeaderAccessor(), AbstractHttpClientInstrumentationTest.class.getClassLoader()); + Transaction transaction = tracer.startChildTransaction(request, HeaderAccessor.INSTANCE, AbstractHttpClientInstrumentationTest.class.getClassLoader()); assertThat(transaction).isNotNull(); assertThat(transaction.getTraceContext().getTraceId()).isEqualTo(span.getTraceContext().getTraceId()); assertThat(transaction.getTraceContext().getParentId()).isEqualTo(span.getTraceContext().getId()); @@ -349,9 +344,9 @@ private List findLoggedRequests(String path) { return loggedRequests.get(); } - private static class HeaderAccessor implements TextHeaderGetter { + private static class HeaderAccessor implements co.elastic.apm.plugin.spi.TextHeaderGetter { - static final HeaderAccessor INSTANCE = new HeaderAccessor(); + static final TextHeaderGetter INSTANCE = new TextHeaderGetterBridge<>(new HeaderAccessor()); @Nullable @Override diff --git a/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/BaseServerEndpointInstrumentation.java b/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/BaseServerEndpointInstrumentation.java index d85a408fdd4..6aabc300d5b 100644 --- a/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/BaseServerEndpointInstrumentation.java +++ b/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/BaseServerEndpointInstrumentation.java @@ -19,10 +19,10 @@ package co.elastic.apm.agent.websocket; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.DefaultOutcome; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -36,7 +36,7 @@ import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.isInAnyPackage; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.isProxy; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; import static net.bytebuddy.matcher.ElementMatchers.isBootstrapClassLoader; import static net.bytebuddy.matcher.ElementMatchers.isInterface; @@ -83,9 +83,9 @@ protected static class BaseAdvice { @Nullable protected static Object startTransactionOrSetTransactionName(String signature, String frameworkName, @Nullable String frameworkVersion) { - Transaction currentTransaction = tracer.currentTransaction(); + Transaction currentTransaction = tracer.currentTransaction(); if (currentTransaction == null) { - Transaction rootTransaction = tracer.startRootTransaction(Thread.currentThread().getContextClassLoader()); + Transaction rootTransaction = tracer.startRootTransaction(Thread.currentThread().getContextClassLoader()); if (rootTransaction != null) { setTransactionTypeAndName(rootTransaction, signature, frameworkName, frameworkVersion); return rootTransaction.activate(); @@ -102,17 +102,17 @@ protected static void endTransaction(@Nullable Object transactionOrNull, @Advice return; } - Transaction transaction = (Transaction) transactionOrNull; + Transaction transaction = (Transaction) transactionOrNull; try { if (t != null) { - transaction.captureException(t).withOutcome(Outcome.FAILURE); + transaction.captureException(t).withOutcome(DefaultOutcome.FAILURE); } } finally { transaction.deactivate().end(); } } - private static void setTransactionTypeAndName(Transaction transaction, String signature, String frameworkName, @Nullable String frameworkVersion) { + private static void setTransactionTypeAndName(Transaction transaction, String signature, String frameworkName, @Nullable String frameworkVersion) { transaction.withType(Transaction.TYPE_REQUEST); transaction.withName(signature, PRIO_HIGH_LEVEL_FRAMEWORK, false); transaction.setFrameworkName(frameworkName); diff --git a/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/JakartaServerEndpointInstrumentation.java b/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/JakartaServerEndpointInstrumentation.java index 5d51b59d42f..2b468d2e657 100644 --- a/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/JakartaServerEndpointInstrumentation.java +++ b/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/JakartaServerEndpointInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.websocket; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.util.VersionUtils; import jakarta.websocket.server.ServerEndpoint; import net.bytebuddy.asm.Advice; diff --git a/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/JavaxServerEndpointInstrumentation.java b/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/JavaxServerEndpointInstrumentation.java index 40ac2f9f026..c0cc2cf27fb 100644 --- a/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/JavaxServerEndpointInstrumentation.java +++ b/apm-agent-plugins/apm-jakarta-websocket-plugin/src/main/java/co/elastic/apm/agent/websocket/JavaxServerEndpointInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.websocket; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.util.VersionUtils; import net.bytebuddy.asm.Advice; 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 6518cfd2fa9..1f9d496a88e 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 @@ -20,8 +20,8 @@ import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; import co.elastic.apm.agent.common.ThreadUtils; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.AbstractSpan; import co.elastic.apm.agent.sdk.DynamicTransformer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.sdk.state.GlobalState; 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 f61791e668e..80575b189d1 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 @@ -19,7 +19,7 @@ package co.elastic.apm.agent.concurrent; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.AbstractSpan; import co.elastic.apm.agent.sdk.DynamicTransformer; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; diff --git a/apm-agent-plugins/apm-java-ldap-plugin/src/main/java/co/elastic/apm/agent/java_ldap/LdapClientAdvice.java b/apm-agent-plugins/apm-java-ldap-plugin/src/main/java/co/elastic/apm/agent/java_ldap/LdapClientAdvice.java index 0240061aa40..cfb86808c49 100644 --- a/apm-agent-plugins/apm-java-ldap-plugin/src/main/java/co/elastic/apm/agent/java_ldap/LdapClientAdvice.java +++ b/apm-agent-plugins/apm-java-ldap-plugin/src/main/java/co/elastic/apm/agent/java_ldap/LdapClientAdvice.java @@ -18,13 +18,9 @@ */ package co.elastic.apm.agent.java_ldap; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import com.sun.jndi.ldap.Connection; -import com.sun.jndi.ldap.LdapResult; +import co.elastic.apm.plugin.spi.*; +// TODO Rafael import com.sun.jndi.ldap.Connection; +// TODO Rafael import com.sun.jndi.ldap.LdapResult; import net.bytebuddy.asm.Advice; import net.bytebuddy.implementation.bytecode.assign.Assigner; @@ -35,13 +31,13 @@ public class LdapClientAdvice { private static final Tracer tracer = GlobalTracer.get(); @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) - public static Object onEnter(@Advice.Origin("#m") String methodName, @Advice.FieldValue(value = "conn", typing = Assigner.Typing.DYNAMIC) Connection connection) { + public static Object onEnter(@Advice.Origin("#m") String methodName, @Advice.FieldValue(value = "conn", typing = Assigner.Typing.DYNAMIC) Void connection) { AbstractSpan parent = tracer.getActive(); if (parent == null) { return null; } - Span span = parent.createExitSpan(); + Span span = parent.createExitSpan(); if (span == null) { return null; } @@ -51,20 +47,20 @@ public static Object onEnter(@Advice.Origin("#m") String methodName, @Advice.Fie .withSubtype("ldap"); if (connection != null) { - span.getContext().getDestination().withAddress(connection.host).withPort(connection.port); - span.getContext().getServiceTarget().withType("ldap").withHostPortName(connection.host, connection.port); + //span.getContext().getDestination().withAddress(connection.host).withPort(connection.port); + //span.getContext().getServiceTarget().withType("ldap").withHostPortName(connection.host, connection.port); } return span.activate(); } @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) - public static void onExit(@Advice.Enter @Nullable Object spanObj, @Nullable @Advice.Return LdapResult ldapResult, @Nullable @Advice.Thrown Throwable t) { - Span span = (Span) spanObj; + public static void onExit(@Advice.Enter @Nullable Object spanObj, @Nullable @Advice.Return Void ldapResult, @Nullable @Advice.Thrown Throwable t) { + Span span = (Span) spanObj; if (span != null) { - span.withOutcome((ldapResult != null && ldapResult.status == 0 /* LDAP_SUCCESS */) ? Outcome.SUCCESS : Outcome.FAILURE) - .captureException(t) - .deactivate().end(); + //span.withOutcome((ldapResult != null && ldapResult.status == 0 /* LDAP_SUCCESS */) ? DefaultOutcome.SUCCESS : DefaultOutcome.FAILURE) +// .captureException(t) + // .deactivate().end(); } } } diff --git a/apm-agent-plugins/apm-javalin-plugin/src/main/java/co/elastic/apm/agent/javalin/JavalinInstrumentation.java b/apm-agent-plugins/apm-javalin-plugin/src/main/java/co/elastic/apm/agent/javalin/JavalinInstrumentation.java index 073e4ee064b..6b274018f9f 100644 --- a/apm-agent-plugins/apm-javalin-plugin/src/main/java/co/elastic/apm/agent/javalin/JavalinInstrumentation.java +++ b/apm-agent-plugins/apm-javalin-plugin/src/main/java/co/elastic/apm/agent/javalin/JavalinInstrumentation.java @@ -19,11 +19,11 @@ package co.elastic.apm.agent.javalin; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.GlobalTracer; +import co.elastic.apm.plugin.spi.GlobalTracer; import co.elastic.apm.agent.impl.context.web.WebConfiguration; -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.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.TransactionNameUtils; import co.elastic.apm.agent.util.VersionUtils; import io.javalin.http.Context; @@ -45,7 +45,7 @@ import java.util.concurrent.CompletableFuture; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; import static net.bytebuddy.matcher.ElementMatchers.isInterface; import static net.bytebuddy.matcher.ElementMatchers.named; @@ -137,7 +137,7 @@ public static Object setSpanAndTransactionName(@Advice.This Handler handler, return null; } - final Transaction transaction = tracer.currentTransaction(); + final Transaction transaction = tracer.currentTransaction(); if (transaction == null) { return null; } @@ -183,7 +183,7 @@ public static void onAfterExecute(@Advice.Enter @Nullable Object spanObj, @Advice.Argument(0) Context ctx, @Advice.Thrown @Nullable Throwable t) { if (spanObj != null) { - final Span span = (Span) spanObj; + final Span span = (Span) spanObj; span.deactivate(); final CompletableFuture responseFuture = ctx.resultFuture(); diff --git a/apm-agent-plugins/apm-javalin-plugin/src/main/java/co/elastic/apm/agent/javalin/JavalinRenderInstrumentation.java b/apm-agent-plugins/apm-javalin-plugin/src/main/java/co/elastic/apm/agent/javalin/JavalinRenderInstrumentation.java index 34938a38fb3..e0cd352b604 100644 --- a/apm-agent-plugins/apm-javalin-plugin/src/main/java/co/elastic/apm/agent/javalin/JavalinRenderInstrumentation.java +++ b/apm-agent-plugins/apm-javalin-plugin/src/main/java/co/elastic/apm/agent/javalin/JavalinRenderInstrumentation.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.javalin; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -89,7 +89,7 @@ public static Object setSpanName(@Advice.Argument(0) String template) { public static void onAfterExecute(@Advice.Enter @Nullable Object spanObj, @Advice.Thrown @Nullable Throwable t) { if (spanObj != null) { - final Span span = (Span) spanObj; + final Span span = (Span) spanObj; span.deactivate(); span.captureException(t); span.end(); diff --git a/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JakartaeeJaxRsTransactionNameInstrumentation.java b/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JakartaeeJaxRsTransactionNameInstrumentation.java index 3cf822a10ec..c77735947bc 100644 --- a/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JakartaeeJaxRsTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JakartaeeJaxRsTransactionNameInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.jaxrs; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.util.VersionUtils; import net.bytebuddy.asm.Advice; diff --git a/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JavaxJaxRsTransactionNameInstrumentation.java b/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JavaxJaxRsTransactionNameInstrumentation.java index 33248197520..9ea9f0dd710 100644 --- a/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JavaxJaxRsTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JavaxJaxRsTransactionNameInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.jaxrs; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.util.VersionUtils; import net.bytebuddy.asm.Advice; diff --git a/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsOffsetMappingFactory.java b/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsOffsetMappingFactory.java index 14c7c8fb389..e9a53fa7c43 100644 --- a/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsOffsetMappingFactory.java +++ b/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsOffsetMappingFactory.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.jaxrs; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.annotation.AnnotationDescription; import net.bytebuddy.description.annotation.AnnotationSource; diff --git a/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentation.java b/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentation.java index b49ec5cb934..254a27d0f17 100644 --- a/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-jaxrs-plugin/src/main/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentation.java @@ -19,10 +19,10 @@ package co.elastic.apm.agent.jaxrs; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -38,7 +38,7 @@ import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.isInAnyPackage; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.isProxy; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.overridesOrImplementsMethodThat; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; import static net.bytebuddy.matcher.ElementMatchers.isBootstrapClassLoader; @@ -125,7 +125,7 @@ static class BaseAdvice { .isUseJaxRsPathForTransactionName(); protected static void setTransactionName(String signature, @Nullable String pathAnnotationValue, @Nullable String frameworkVersion) { - final Transaction transaction = TracerAwareInstrumentation.tracer.currentTransaction(); + final Transaction transaction = TracerAwareInstrumentation.tracer.currentTransaction(); if (transaction != null) { String transactionName = signature; if (useAnnotationValueForTransactionName) { diff --git a/apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/JaxWsTransactionNameInstrumentation.java b/apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/JaxWsTransactionNameInstrumentation.java index 6986f7504a7..eed00caf083 100644 --- a/apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/JaxWsTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/JaxWsTransactionNameInstrumentation.java @@ -20,9 +20,9 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory.SimpleMethodSignature; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -37,7 +37,7 @@ import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.isInAnyPackage; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.isProxy; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.overridesOrImplementsMethodThat; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; import static net.bytebuddy.matcher.ElementMatchers.isBootstrapClassLoader; import static net.bytebuddy.matcher.ElementMatchers.isDeclaredBy; @@ -59,7 +59,7 @@ public JaxWsTransactionNameInstrumentation(Tracer tracer) { public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setTransactionName(@SimpleMethodSignature String signature) { - final Transaction transaction = tracer.currentTransaction(); + final Transaction transaction = tracer.currentTransaction(); if (transaction != null) { transaction.withName(signature, PRIO_HIGH_LEVEL_FRAMEWORK, false); transaction.setFrameworkName(FRAMEWORK_NAME); diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/StatementInstrumentation.java b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/StatementInstrumentation.java index 28d1fa242e0..6432f0dff1b 100644 --- a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/StatementInstrumentation.java +++ b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/StatementInstrumentation.java @@ -18,8 +18,7 @@ */ package co.elastic.apm.agent.jdbc; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.jdbc.helper.JdbcHelper; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; @@ -82,7 +81,7 @@ public ElementMatcher getMethodMatcher() { @SuppressWarnings("DuplicatedCode") public static class ExecuteWithQueryInstrumentation extends StatementInstrumentation { - public ExecuteWithQueryInstrumentation(Tracer tracer) { + public ExecuteWithQueryInstrumentation() { super( named("execute").or(named("executeQuery")) .and(takesArgument(0, String.class)) @@ -108,7 +107,7 @@ public static void onAfterExecute(@Advice.This Statement statement, return; } - ((Span) span).captureException(t) + ((Span) span).captureException(t) .deactivate() .end(); @@ -131,7 +130,7 @@ public static void onAfterExecute(@Advice.This Statement statement, */ public static class ExecuteUpdateWithQueryInstrumentation extends StatementInstrumentation { - public ExecuteUpdateWithQueryInstrumentation(Tracer tracer) { + public ExecuteUpdateWithQueryInstrumentation() { super( named("executeUpdate").or(named("executeLargeUpdate")) .and(takesArgument(0, String.class)) @@ -157,12 +156,12 @@ public static void onAfterExecute(@Advice.Enter @Nullable Object span, } if (t == null) { - ((Span) span).getContext() + ((Span) span).getContext() .getDb() .withAffectedRowsCount(returnValue); } - ((Span) span).captureException(t) + ((Span) span).captureException(t) .deactivate() .end(); } @@ -174,7 +173,7 @@ public static void onAfterExecute(@Advice.Enter @Nullable Object span, */ public static class AddBatchInstrumentation extends StatementInstrumentation { - public AddBatchInstrumentation(Tracer tracer) { + public AddBatchInstrumentation() { super( nameStartsWith("addBatch") .and(takesArgument(0, String.class)) @@ -200,7 +199,7 @@ public static void storeSql(@Advice.This Statement statement, @Advice.Argument(0 * */ public static class ExecuteBatchInstrumentation extends StatementInstrumentation { - public ExecuteBatchInstrumentation(Tracer tracer) { + public ExecuteBatchInstrumentation() { super( named("executeBatch").or(named("executeLargeBatch")) .and(takesArguments(0)) @@ -224,10 +223,10 @@ public static Object onBeforeExecute(@Advice.This Statement statement) { public static void onAfterExecute(@Advice.Enter @Nullable Object spanObj, @Advice.Thrown @Nullable Throwable t, @Advice.Return @Nullable Object returnValue) { - if (!(spanObj instanceof Span)) { + if (!(spanObj instanceof Span)) { return; } - Span span = (Span) spanObj; + Span span = (Span) spanObj; // for 'executeBatch' and 'executeLargeBatch', we have to compute the sum as Statement.getUpdateCount() // does not seem to return the sum of all elements. As we can use instanceof to check return type @@ -265,7 +264,7 @@ public static void onAfterExecute(@Advice.Enter @Nullable Object spanObj, * */ public static class ExecuteUpdateNoQueryInstrumentation extends StatementInstrumentation { - public ExecuteUpdateNoQueryInstrumentation(Tracer tracer) { + public ExecuteUpdateNoQueryInstrumentation() { super( named("executeUpdate").or(named("executeLargeUpdate")) .and(takesArguments(0)) @@ -293,12 +292,12 @@ public static void onAfterExecute(@Advice.Enter @Nullable Object span, } if (t == null) { - ((Span) span).getContext() + ((Span) span).getContext() .getDb() .withAffectedRowsCount(returnValue); } - ((Span) span).captureException(t) + ((Span) span).captureException(t) .deactivate() .end(); } @@ -313,7 +312,7 @@ public static void onAfterExecute(@Advice.Enter @Nullable Object span, * */ public static class ExecutePreparedStatementInstrumentation extends StatementInstrumentation { - public ExecutePreparedStatementInstrumentation(Tracer tracer) { + public ExecutePreparedStatementInstrumentation() { super( named("execute").or(named("executeQuery")) .and(takesArguments(0)) @@ -340,7 +339,7 @@ public static void onAfterExecute(@Advice.This Statement statement, return; } - ((Span) span).captureException(t) + ((Span) span).captureException(t) .deactivate() .end(); } @@ -355,7 +354,7 @@ public static void onAfterExecute(@Advice.This Statement statement, */ public static class CloseStatementInstrumentation extends StatementInstrumentation { - public CloseStatementInstrumentation(Tracer tracer) { + public CloseStatementInstrumentation() { super( named("close") .and(takesArguments(0)) 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 3283b035449..833d297ab2f 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 @@ -20,8 +20,8 @@ import co.elastic.apm.agent.db.signature.Scanner; import co.elastic.apm.agent.db.signature.SignatureParser; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.jdbc.JdbcFilter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -81,12 +81,12 @@ public String retrieveSqlForStatement(Object statement) { @Nullable - public Span createJdbcSpan(@Nullable String sql, Object statement, @Nullable AbstractSpan parent, boolean preparedStatement) { + public Span createJdbcSpan(@Nullable String sql, Object statement, @Nullable AbstractSpan parent, boolean preparedStatement) { if (!(statement instanceof Statement) || sql == null || isAlreadyMonitored(parent) || parent == null) { return null; } - Span span = parent.createExitSpan(); + Span span = parent.createExitSpan(); if (span == null) { return null; } else { @@ -141,10 +141,10 @@ public Span createJdbcSpan(@Nullable String sql, Object statement, @Nullable Abs * we only record each JDBC call once. */ private boolean isAlreadyMonitored(@Nullable AbstractSpan parent) { - if (!(parent instanceof Span)) { + if (!(parent instanceof Span)) { return false; } - Span parentSpan = (Span) parent; + Span parentSpan = (Span) parent; // a db span can't be the child of another db span // this means the span has already been created for this db call return parentSpan.getType() != null && parentSpan.getType().equals(DB_SPAN_TYPE); diff --git a/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientAdvice.java b/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientAdvice.java index a8629418cfe..d1abe35dd4a 100644 --- a/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientAdvice.java +++ b/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientAdvice.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.httpclient; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import javax.annotation.Nullable; @@ -36,8 +36,8 @@ public static Object onBeforeExecute(@Advice.Argument(value = 0) HttpRequest htt public static void onAfterExecute(@Advice.Return @Nullable HttpResponse response, @Advice.Enter @Nullable Object spanObj, @Advice.Thrown @Nullable Throwable t) { - if (spanObj instanceof Span) { - final Span span = (Span) spanObj; + if (spanObj instanceof Span) { + final Span span = (Span) spanObj; if (response != null) { int statusCode = response.statusCode(); span.getContext().getHttp().withStatusCode(statusCode); diff --git a/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientAdviceHelper.java b/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientAdviceHelper.java index abdfa7f46be..cb6675dabdc 100644 --- a/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientAdviceHelper.java +++ b/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientAdviceHelper.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.httpclient; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import javax.annotation.Nullable; import java.net.URI; @@ -32,14 +32,14 @@ public class HttpClientAdviceHelper { private static final Tracer tracer = GlobalTracer.get(); @Nullable - public static Span startSpan(HttpRequest httpRequest) { + public static Span startSpan(HttpRequest httpRequest) { final AbstractSpan parent = tracer.getActive(); if (parent == null) { return null; } URI uri = httpRequest.uri(); - Span span = HttpClientHelper.startHttpClientSpan(parent, httpRequest.method(), uri, uri.getHost()); + Span span = HttpClientHelper.startHttpClientSpan(parent, httpRequest.method(), uri, uri.getHost()); if (span != null) { span.activate(); } diff --git a/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientAsyncAdvice.java b/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientAsyncAdvice.java index 831d6f07f21..9019fe89e26 100644 --- a/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientAsyncAdvice.java +++ b/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientAsyncAdvice.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.httpclient; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import javax.annotation.Nullable; @@ -37,8 +37,8 @@ public static Object onBeforeExecute(@Advice.Argument(value = 0) HttpRequest htt public static void onAfterExecute(@Advice.Return @Nullable CompletableFuture> completableFuture, @Advice.Enter @Nullable Object spanObj, @Advice.Thrown @Nullable Throwable t) { - if (spanObj instanceof Span) { - final Span span = (Span) spanObj; + if (spanObj instanceof Span) { + final Span span = (Span) spanObj; span.deactivate(); if (completableFuture == null) { span.captureException(t) diff --git a/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientRequestPropertyAccessor.java b/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientRequestPropertyAccessor.java index 5eee00194a2..29a0bce6e37 100644 --- a/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientRequestPropertyAccessor.java +++ b/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpClientRequestPropertyAccessor.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.httpclient; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import java.util.Collections; import java.util.List; diff --git a/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpRequestHeadersAdvice.java b/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpRequestHeadersAdvice.java index ebae9e54eb2..c91643093ae 100644 --- a/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpRequestHeadersAdvice.java +++ b/apm-agent-plugins/apm-jdk-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/HttpRequestHeadersAdvice.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.httpclient; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import javax.annotation.Nullable; @@ -37,7 +37,7 @@ public class HttpRequestHeadersAdvice { @Advice.AssignReturned.ToReturned @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static HttpHeaders onAfterExecute(@Advice.Return @Nullable final HttpHeaders httpHeaders) { - Span span = tracer.getActiveSpan(); + Span span = tracer.getActiveSpan(); if (span == null || httpHeaders == null) { // in case of thrown exception return value might be null return httpHeaders; } diff --git a/apm-agent-plugins/apm-jdk-httpserver-plugin/src/main/java/co/elastic/apm/agent/httpserver/HeadersHeaderGetter.java b/apm-agent-plugins/apm-jdk-httpserver-plugin/src/main/java/co/elastic/apm/agent/httpserver/HeadersHeaderGetter.java index 0902635b6d1..87ec58d0223 100644 --- a/apm-agent-plugins/apm-jdk-httpserver-plugin/src/main/java/co/elastic/apm/agent/httpserver/HeadersHeaderGetter.java +++ b/apm-agent-plugins/apm-jdk-httpserver-plugin/src/main/java/co/elastic/apm/agent/httpserver/HeadersHeaderGetter.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.httpserver; -import co.elastic.apm.agent.impl.transaction.AbstractHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.AbstractHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import com.sun.net.httpserver.Headers; import javax.annotation.Nullable; diff --git a/apm-agent-plugins/apm-jdk-httpserver-plugin/src/main/java/co/elastic/apm/agent/httpserver/HttpHandlerAdvice.java b/apm-agent-plugins/apm-jdk-httpserver-plugin/src/main/java/co/elastic/apm/agent/httpserver/HttpHandlerAdvice.java index 1e26f7398be..16fdd04eba1 100644 --- a/apm-agent-plugins/apm-jdk-httpserver-plugin/src/main/java/co/elastic/apm/agent/httpserver/HttpHandlerAdvice.java +++ b/apm-agent-plugins/apm-jdk-httpserver-plugin/src/main/java/co/elastic/apm/agent/httpserver/HttpHandlerAdvice.java @@ -19,14 +19,8 @@ package co.elastic.apm.agent.httpserver; import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.context.web.ResultUtil; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.impl.context.web.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.util.TransactionNameUtils; import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.HttpExchange; @@ -61,7 +55,7 @@ public static Object onEnterHandle(@Advice.Argument(0) HttpExchange exchange) { return null; } - Transaction transaction = tracer.startChildTransaction(exchange.getRequestHeaders(), HeadersHeaderGetter.INSTANCE, Thread.currentThread().getContextClassLoader()); + Transaction transaction = tracer.startChildTransaction(exchange.getRequestHeaders(), HeadersHeaderGetter.INSTANCE, Thread.currentThread().getContextClassLoader()); if (transaction == null) { return null; } @@ -132,7 +126,7 @@ public static void onExitHandle(@Advice.Argument(0) HttpExchange exchange, @Advi return; } - Transaction transaction = (Transaction) transactionOrNull; + Transaction transaction = (Transaction) transactionOrNull; transaction .withResultIfUnset(ResultUtil.getResultByHttpStatus(exchange.getResponseCode())) .captureException(t); diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/BaseJmsInstrumentation.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/BaseJmsInstrumentation.java index de8bb910865..63d10be7d35 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/BaseJmsInstrumentation.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/BaseJmsInstrumentation.java @@ -21,8 +21,8 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; import net.bytebuddy.matcher.ElementMatcher; import java.util.Collection; diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java index d0927d081a2..ca25a4cae05 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java @@ -20,11 +20,7 @@ import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -96,7 +92,7 @@ public JmsInstrumentationHelper(Tracer tracer) { @SuppressWarnings("Duplicates") @Nullable - public Span startJmsSendSpan(Destination destination, Message message) { + public Span startJmsSendSpan(Destination destination, Message message) { final AbstractSpan activeSpan = tracer.getActive(); if (activeSpan == null) { @@ -113,7 +109,7 @@ public Span startJmsSendSpan(Destination destination, Message message) { return null; } - Span span = activeSpan.createExitSpan(); + Span span = activeSpan.createExitSpan(); if (span == null) { return null; @@ -143,16 +139,16 @@ public Span startJmsSendSpan(Destination destination, Message message) { } @Nullable - public Transaction startJmsTransaction(Message parentMessage, Class instrumentedClass) { - Transaction transaction = tracer.startChildTransaction(parentMessage, JmsMessagePropertyAccessor.instance(), PrivilegedActionUtils.getClassLoader(instrumentedClass)); + public Transaction startJmsTransaction(Message parentMessage, Class instrumentedClass) { + Transaction transaction = tracer.startChildTransaction(parentMessage, JmsMessagePropertyAccessor.instance(), PrivilegedActionUtils.getClassLoader(instrumentedClass)); if (transaction != null) { transaction.setFrameworkName(FRAMEWORK_NAME); } return transaction; } - public void makeChildOf(Transaction childTransaction, Message parentMessage) { - TraceContext.getFromTraceContextTextHeaders().asChildOf(childTransaction.getTraceContext(), parentMessage, JmsMessagePropertyAccessor.instance()); + public void makeChildOf(Transaction childTransaction, Message parentMessage) { + TraceContextUtil.getFromTraceContextTextHeaders().asChildOf(childTransaction.getTraceContext(), parentMessage, JmsMessagePropertyAccessor.instance()); } @Nullable @@ -244,7 +240,7 @@ public void addMessageDetails(@Nullable Message message, AbstractSpan span) { return; } try { - co.elastic.apm.agent.impl.context.Message messageContext = span.getContext().getMessage(); + co.elastic.apm.plugin.spi.Message messageContext = span.getContext().getMessage(); // Currently only capturing body of TextMessages. The javax.jms.Message#getBody() API is since 2.0, so, // if we are supporting JMS 1.1, it makes no sense to rely on isAssignableFrom. @@ -258,7 +254,7 @@ public void addMessageDetails(@Nullable Message message, AbstractSpan span) { messageContext.addHeader(JMS_EXPIRATION_HEADER, String.valueOf(message.getJMSExpiration())); messageContext.addHeader(JMS_TIMESTAMP_HEADER, String.valueOf(message.getJMSTimestamp())); - Enumeration properties = message.getPropertyNames(); + Enumeration properties = message.getPropertyNames(); if (properties != null) { while (properties.hasMoreElements()) { String propertyName = String.valueOf(properties.nextElement()); diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageConsumerInstrumentation.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageConsumerInstrumentation.java index c18fe4a168f..3106c0bc6c1 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageConsumerInstrumentation.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageConsumerInstrumentation.java @@ -19,10 +19,10 @@ package co.elastic.apm.agent.jms; import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; +import co.elastic.apm.plugin.spi.TraceContextUtil; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.PrivilegedActionUtils; import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument; @@ -97,8 +97,8 @@ public static Object beforeReceive(@Advice.Origin Class clazz, if (parent == null) { createPollingTransaction = true; } else { - if (parent instanceof Transaction) { - Transaction transaction = (Transaction) parent; + if (parent instanceof Transaction) { + Transaction transaction = (Transaction) parent; if (MESSAGE_POLLING.equals(transaction.getType())) { // Avoid duplications for nested calls return null; @@ -111,8 +111,8 @@ public static Object beforeReceive(@Advice.Origin Class clazz, } else { createPollingSpan = true; } - } else if (parent instanceof Span) { - Span parentSpan = (Span) parent; + } else if (parent instanceof Span) { + Span parentSpan = (Span) parent; if (MESSAGING_TYPE.equals(parentSpan.getType()) && "receive".equals(parentSpan.getAction())) { // Avoid duplication for nested calls return null; @@ -132,7 +132,7 @@ public static Object beforeReceive(@Advice.Origin Class clazz, } else if (createPollingTransaction) { createdSpan = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(clazz)); if (createdSpan != null) { - ((Transaction) createdSpan).withType(MESSAGE_POLLING); + ((Transaction) createdSpan).withType(MESSAGE_POLLING); } } @@ -166,8 +166,8 @@ public static void afterReceive(@Advice.Origin Class clazz, logger.error("Failed to retrieve meta info from Message", e); } - if (abstractSpan instanceof Transaction) { - Transaction transaction = (Transaction) abstractSpan; + if (abstractSpan instanceof Transaction) { + Transaction transaction = (Transaction) abstractSpan; if (discard) { transaction.ignoreTransaction(); } else { @@ -177,14 +177,14 @@ public static void afterReceive(@Advice.Origin Class clazz, } } else if (abstractSpan != null) { abstractSpan.addSpanLink( - TraceContext.getFromTraceContextTextHeaders(), + TraceContextUtil.getFromTraceContextTextHeaders(), JmsMessagePropertyAccessor.instance(), message ); } - } else if (abstractSpan instanceof Transaction) { + } else if (abstractSpan instanceof Transaction) { // Do not report polling transactions if not yielding messages - ((Transaction) abstractSpan).ignoreTransaction(); + ((Transaction) abstractSpan).ignoreTransaction(); addDetails = false; } @@ -210,7 +210,7 @@ public static void afterReceive(@Advice.Origin Class clazz, && messagingConfiguration.getMessagePollingTransactionStrategy() != MessagingConfiguration.JmsStrategy.POLLING && !"receiveNoWait".equals(methodName)) { - Transaction messageHandlingTransaction = helper.startJmsTransaction(message, clazz); + Transaction messageHandlingTransaction = helper.startJmsTransaction(message, clazz); if (messageHandlingTransaction != null) { messageHandlingTransaction.withType(MESSAGE_HANDLING) .withName(RECEIVE_NAME_PREFIX); diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageListenerInstrumentation.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageListenerInstrumentation.java index 2ba130b5d63..ad78a9722df 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageListenerInstrumentation.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageListenerInstrumentation.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.jms; import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import net.bytebuddy.asm.Advice; @@ -123,7 +123,7 @@ public static Object beforeOnMessage(@Advice.Argument(0) @Nullable final Message } // Create a transaction - even if running on same JVM as the sender - Transaction transaction = helper.startJmsTransaction(message, clazz); + Transaction transaction = helper.startJmsTransaction(message, clazz); if (transaction != null) { transaction.withType(MESSAGING_TYPE) .withName(RECEIVE_NAME_PREFIX); @@ -143,8 +143,8 @@ public static Object beforeOnMessage(@Advice.Argument(0) @Nullable final Message @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false) public static void afterOnMessage(@Advice.Enter @Nullable final Object transactionObj, @Advice.Thrown final Throwable throwable) { - if (transactionObj instanceof Transaction) { - Transaction transaction = (Transaction) transactionObj; + if (transactionObj instanceof Transaction) { + Transaction transaction = (Transaction) transactionObj; transaction.captureException(throwable); transaction.deactivate().end(); } diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageProducerInstrumentation.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageProducerInstrumentation.java index cfa8f3fec4d..1fadff1a87f 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageProducerInstrumentation.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessageProducerInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.jms; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -96,8 +96,8 @@ public static Object beforeSend(@Advice.Argument(0) final Message message, public static void afterSend(@Advice.Enter @Nullable final Object spanObj, @Advice.Thrown final Throwable throwable) { - if (spanObj instanceof Span) { - Span span = (Span) spanObj; + if (spanObj instanceof Span) { + Span span = (Span) spanObj; span.captureException(throwable); span.deactivate().end(); } @@ -133,8 +133,8 @@ public static Object startSpan(@Advice.Argument(0) final Destination destination public static void endSpan(@Advice.Enter @Nullable final Object spanObj, @Advice.Thrown final Throwable throwable) { - if (spanObj instanceof Span) { - Span span = (Span) spanObj; + if (spanObj instanceof Span) { + Span span = (Span) spanObj; span.captureException(throwable); span.deactivate().end(); } diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessagePropertyAccessor.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessagePropertyAccessor.java index ee0b5c6ea9d..7ff873d47f6 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessagePropertyAccessor.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsMessagePropertyAccessor.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.jms; -import co.elastic.apm.agent.impl.transaction.AbstractHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.AbstractHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TraceContext; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; diff --git a/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleExecuteInstrumentation.java b/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleExecuteInstrumentation.java index 43e2d2248f4..bf1a243584c 100644 --- a/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleExecuteInstrumentation.java +++ b/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleExecuteInstrumentation.java @@ -18,15 +18,15 @@ */ package co.elastic.apm.agent.jsf; -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.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; +import co.elastic.apm.plugin.spi.Transaction; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import javax.annotation.Nullable; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; @@ -50,13 +50,13 @@ protected static Object createAndActivateSpan(boolean withExternalContext, @Null if (parent == null) { return null; } - if (parent instanceof Span) { - Span parentSpan = (Span) parent; + if (parent instanceof Span) { + Span parentSpan = (Span) parent; if (SPAN_SUBTYPE.equals(parentSpan.getSubtype()) && SPAN_ACTION.equals(parentSpan.getAction())) { return null; } } - Transaction transaction = tracer.currentTransaction(); + Transaction transaction = tracer.currentTransaction(); if (transaction != null) { try { if (withExternalContext) { @@ -70,7 +70,7 @@ protected static Object createAndActivateSpan(boolean withExternalContext, @Null // do nothing- rely on the default servlet name logic } } - Span span = parent.createSpan() + Span span = parent.createSpan() .withType(SPAN_TYPE) .withSubtype(SPAN_SUBTYPE) .withAction(SPAN_ACTION) @@ -80,8 +80,8 @@ protected static Object createAndActivateSpan(boolean withExternalContext, @Null } protected static void endAndDeactivateSpan(@Nullable Object span, @Nullable Throwable t) { - if (span instanceof Span) { - ((Span) span).captureException(t).deactivate().end(); + if (span instanceof Span) { + ((Span) span).captureException(t).deactivate().end(); } } } diff --git a/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleRenderInstrumentation.java b/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleRenderInstrumentation.java index 5522e51e5f8..5dffa5c01e7 100644 --- a/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleRenderInstrumentation.java +++ b/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleRenderInstrumentation.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.jsf; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -66,13 +66,13 @@ public static Object createRenderSpan() { if (parent == null) { return null; } - if (parent instanceof Span) { - Span parentSpan = (Span) parent; + if (parent instanceof Span) { + Span parentSpan = (Span) parent; if (SPAN_SUBTYPE.equals(parentSpan.getSubtype()) && SPAN_ACTION.equals(parentSpan.getAction())) { return null; } } - Span span = parent.createSpan() + Span span = parent.createSpan() .withType(SPAN_TYPE) .withSubtype(SPAN_SUBTYPE) .withAction(SPAN_ACTION) @@ -85,8 +85,8 @@ public static Object createRenderSpan() { public static void endRenderSpan(@Advice.Enter @Nullable Object span, @Advice.Thrown @Nullable Throwable t) { - if (span instanceof Span) { - ((Span) span).captureException(t).deactivate().end(); + if (span instanceof Span) { + ((Span) span).captureException(t).deactivate().end(); } } } diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaConsumerInstrumentation.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaConsumerInstrumentation.java index 9c20b36f071..5461451e6c8 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaConsumerInstrumentation.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaConsumerInstrumentation.java @@ -19,10 +19,10 @@ package co.elastic.apm.agent.kafka; import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.GlobalTracer; -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.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; +import co.elastic.apm.plugin.spi.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -68,15 +68,15 @@ public static void pollStart() { return; } - if (messagingConfiguration.shouldEndMessagingTransactionOnPoll() && activeSpan instanceof Transaction) { - Transaction transaction = (Transaction) activeSpan; + if (messagingConfiguration.shouldEndMessagingTransactionOnPoll() && activeSpan instanceof Transaction) { + Transaction transaction = (Transaction) activeSpan; if ("messaging".equals(transaction.getType())) { transaction.deactivate().end(); return; } } - Span span = activeSpan.createExitSpan(); + Span span = activeSpan.createExitSpan(); if (span == null) { return; } @@ -111,7 +111,7 @@ public static class KafkaPollExitAdvice { @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false) public static void pollEnd(@Advice.Thrown final Throwable throwable) { - Span span = tracer.getActiveSpan(); + Span span = tracer.getActiveSpan(); if (span != null && "kafka".equals(span.getSubtype()) && "poll".equals(span.getAction()) 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 68843736119..e6e6dbadc84 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 @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.kafka; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.kafka.helper.KafkaInstrumentationHelper; import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument; @@ -70,7 +70,7 @@ public static class KafkaProducerAdvice { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Callback beforeSend(@Advice.Argument(0) final ProducerRecord record, @Advice.Argument(1) @Nullable Callback callback) { - Span span = helper.onSendStart(record); + Span span = helper.onSendStart(record); if (span == null) { return callback; } @@ -82,7 +82,7 @@ public static Callback beforeSend(@Advice.Argument(0) final ProducerRecord public static void afterSend(@Advice.Argument(0) final ProducerRecord record, @Advice.This final KafkaProducer thiz, @Advice.Thrown final Throwable throwable) { - final Span span = tracer.getActiveExitSpan(); + final Span span = tracer.getActiveExitSpan(); if (span != null) { helper.onSendEnd(span, record, thiz, throwable); } diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/CallbackWrapper.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/CallbackWrapper.java index 9e4ddaff9cf..0d97eb10ca3 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/CallbackWrapper.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/CallbackWrapper.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.kafka.helper; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.objectpool.Recyclable; import org.apache.kafka.clients.producer.Callback; import org.apache.kafka.clients.producer.RecordMetadata; @@ -32,13 +32,13 @@ class CallbackWrapper implements Callback, Recyclable { @Nullable private Callback delegate; @SuppressWarnings("NotNullFieldNotInitialized") - private volatile Span span; + private volatile Span span; CallbackWrapper(KafkaInstrumentationHelper helper) { this.helper = helper; } - Callback wrap(@Nullable Callback delegate, Span span) { + Callback wrap(@Nullable Callback delegate, Span span) { this.delegate = delegate; this.span = span; return this; diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHelper.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHelper.java index 6fa00387620..54cbd466ba2 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHelper.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHelper.java @@ -19,12 +19,8 @@ package co.elastic.apm.agent.kafka.helper; import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.objectpool.Allocator; -import co.elastic.apm.agent.objectpool.ObjectPool; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import org.apache.kafka.clients.producer.Callback; @@ -69,14 +65,14 @@ private boolean ignoreTopic(String topicName) { } @Nullable - public Span onSendStart(ProducerRecord record) { + public Span onSendStart(ProducerRecord record) { String topic = record.topic(); if (ignoreTopic(topic)) { return null; } - final Span span = tracer.createExitChildSpan(); + final Span span = tracer.createExitChildSpan(); if (span == null) { return null; } @@ -98,7 +94,7 @@ public Span onSendStart(ProducerRecord record) { } @Nullable - public Callback wrapCallback(@Nullable Callback callback, Span span) { + public Callback wrapCallback(@Nullable Callback callback, Span span) { if (callback instanceof CallbackWrapper) { // don't wrap twice return callback; @@ -115,7 +111,7 @@ void recycle(CallbackWrapper callbackWrapper) { callbackWrapperObjectPool.recycle(callbackWrapper); } - public void onSendEnd(Span span, ProducerRecord producerRecord, KafkaProducer kafkaProducer, @Nullable Throwable throwable) { + public void onSendEnd(Span span, ProducerRecord producerRecord, KafkaProducer kafkaProducer, @Nullable Throwable throwable) { // Topic address collection is normally very fast, as it uses cached cluster state information. However, // when the cluster metadata is required to be updated, its query may block for a short period. In diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaProducerHeadersInstrumentation.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaProducerHeadersInstrumentation.java index bec7ec0916a..3c21e2ed42d 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaProducerHeadersInstrumentation.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaProducerHeadersInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.kafka; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.kafka.helper.KafkaInstrumentationHeadersHelper; import co.elastic.apm.agent.kafka.helper.KafkaInstrumentationHelper; import net.bytebuddy.asm.Advice; @@ -70,7 +70,7 @@ public static class KafkaProducerHeadersAdvice { public static Object[] beforeSend(@Advice.FieldValue("apiVersions") final ApiVersions apiVersions, @Advice.Argument(0) final ProducerRecord record, @Nullable @Advice.Argument(value = 1) Callback callback) { - Span span = helper.onSendStart(record); + Span span = helper.onSendStart(record); if (span == null) { return null; } @@ -107,7 +107,7 @@ public static Object[] afterSend(@Advice.Enter @Nullable Object[] enter, @Advice.This final KafkaProducer thiz, @Advice.Thrown @Nullable final Throwable throwable) { - Span span = enter != null ? (Span) enter[0] : null; + Span span = enter != null ? (Span) enter[0] : null; if (span == null) { return null; } diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/NewKafkaPollExitInstrumentation.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/NewKafkaPollExitInstrumentation.java index bf18f65efbf..ad2318b5380 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/NewKafkaPollExitInstrumentation.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/NewKafkaPollExitInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.kafka; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.kafka.helper.KafkaInstrumentationHeadersHelper; import net.bytebuddy.asm.Advice; import net.bytebuddy.matcher.ElementMatcher; @@ -51,7 +51,7 @@ public static class KafkaPollExitAdvice { public static void pollEnd(@Advice.Thrown final Throwable throwable, @Advice.Return @Nullable ConsumerRecords records) { - Span span = tracer.getActiveSpan(); + Span span = tracer.getActiveSpan(); if (span != null && span.getSubtype() != null && span.getSubtype().equals("kafka") && span.getAction() != null && span.getAction().equals("poll") diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsIterableWrapper.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsIterableWrapper.java index 2e2b359e5ed..a8b4a3bca26 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsIterableWrapper.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsIterableWrapper.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.kafka.helper; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import org.apache.kafka.clients.consumer.ConsumerRecord; import java.util.Iterator; diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsIteratorWrapper.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsIteratorWrapper.java index b59099ca96e..9de2953c41d 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsIteratorWrapper.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsIteratorWrapper.java @@ -20,10 +20,10 @@ import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.context.Message; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Message; +import co.elastic.apm.plugin.spi.TraceContext; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.util.PrivilegedActionUtils; import org.apache.kafka.clients.consumer.ConsumerRecord; @@ -59,7 +59,7 @@ public boolean hasNext() { public void endCurrentTransaction() { try { - Transaction transaction = tracer.currentTransaction(); + Transaction transaction = tracer.currentTransaction(); if (transaction != null && "messaging".equals(transaction.getType())) { transaction.deactivate().end(); } @@ -75,7 +75,7 @@ public void endCurrentTransaction() { try { String topic = record.topic(); if (!WildcardMatcher.isAnyMatch(messagingConfiguration.getIgnoreMessageQueues(), topic)) { - Transaction transaction = tracer.startChildTransaction(record, KafkaRecordHeaderAccessor.instance(), PrivilegedActionUtils.getClassLoader(ConsumerRecordsIteratorWrapper.class)); + Transaction transaction = tracer.startChildTransaction(record, KafkaRecordHeaderAccessor.instance(), PrivilegedActionUtils.getClassLoader(ConsumerRecordsIteratorWrapper.class)); if (transaction != null) { transaction.withType("messaging").withName("Kafka record from " + topic).activate(); transaction.setFrameworkName(FRAMEWORK_NAME); diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsListWrapper.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsListWrapper.java index 5289049a432..1bc8dc1ce4e 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsListWrapper.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/ConsumerRecordsListWrapper.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.kafka.helper; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import org.apache.kafka.clients.consumer.ConsumerRecord; import java.util.Collection; diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHeadersHelper.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHeadersHelper.java index adb50d02a4c..c607774ccfc 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHeadersHelper.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHeadersHelper.java @@ -18,11 +18,7 @@ */ package co.elastic.apm.agent.kafka.helper; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.*; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.producer.ProducerRecord; @@ -109,7 +105,7 @@ public void addSpanLinks(@Nullable ConsumerRecords records, AbstractSpan record : records) { span.addSpanLink( - TraceContext.getFromTraceContextBinaryHeaders(), + TraceContextUtil.getFromTraceContextBinaryHeaders(), KafkaRecordHeaderAccessor.instance(), record ); @@ -120,11 +116,11 @@ public void addSpanLinks(@Nullable ConsumerRecords records, AbstractSpan producerRecord) { + public void setOutgoingTraceContextHeaders(Span span, ProducerRecord producerRecord) { span.propagateTraceContext(producerRecord, KafkaRecordHeaderAccessor.instance()); } public void removeTraceContextHeader(ProducerRecord producerRecord) { - TraceContext.removeTraceContextHeaders(producerRecord, KafkaRecordHeaderAccessor.instance()); + TraceContextUtil.removeTraceContextHeaders(producerRecord, KafkaRecordHeaderAccessor.instance()); } } diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaRecordHeaderAccessor.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaRecordHeaderAccessor.java index 67f9d3d1733..780aa4ba1ff 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaRecordHeaderAccessor.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaRecordHeaderAccessor.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.kafka.helper; -import co.elastic.apm.agent.impl.transaction.BinaryHeaderGetter; -import co.elastic.apm.agent.impl.transaction.BinaryHeaderSetter; -import co.elastic.apm.agent.impl.transaction.HeaderRemover; +import co.elastic.apm.plugin.spi.BinaryHeaderGetter; +import co.elastic.apm.plugin.spi.BinaryHeaderSetter; +import co.elastic.apm.plugin.spi.HeaderRemover; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.common.header.Header; diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-spring-plugin/src/main/java/co/elastic/apm/agent/kafka/SpringKafkaBatchListenerInstrumentation.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-spring-plugin/src/main/java/co/elastic/apm/agent/kafka/SpringKafkaBatchListenerInstrumentation.java index d3d6dced5ae..ea91a198946 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-spring-plugin/src/main/java/co/elastic/apm/agent/kafka/SpringKafkaBatchListenerInstrumentation.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-spring-plugin/src/main/java/co/elastic/apm/agent/kafka/SpringKafkaBatchListenerInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.kafka; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.util.LoggerUtils; @@ -75,7 +75,7 @@ public static class SpringKafkaBatchListenerAdvice { @Nullable @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object onEnter(@Advice.This Object thiz) { - Transaction transaction = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(thiz.getClass())); + Transaction transaction = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(thiz.getClass())); if (transaction != null) { transaction .withType("messaging") @@ -91,7 +91,7 @@ public static Object onEnter(@Advice.This Object thiz) { @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void onExit(@Nullable @Advice.Enter Object transactionObj) { - Transaction transaction = (Transaction) transactionObj; + Transaction transaction = (Transaction) transactionObj; if (transaction != null) { transaction.deactivate().end(); } diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/correlation/Log4j2_7PlusLogCorrelationHelper.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/correlation/Log4j2_7PlusLogCorrelationHelper.java index 21adbf2723d..3e7fb331fb5 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/correlation/Log4j2_7PlusLogCorrelationHelper.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/correlation/Log4j2_7PlusLogCorrelationHelper.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.log4j2.correlation; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; import co.elastic.apm.agent.impl.error.ErrorCapture; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.loginstr.correlation.AbstractLogCorrelationHelper; import co.elastic.apm.agent.loginstr.correlation.CorrelationIdMapAdapter; import org.apache.logging.log4j.ThreadContext; @@ -32,7 +32,7 @@ */ public class Log4j2_7PlusLogCorrelationHelper extends AbstractLogCorrelationHelper { - private final Tracer tracer = GlobalTracer.get(); + private static final Tracer tracer = GlobalTracer.get(); @Override protected boolean addToMdc() { diff --git a/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/main/java/co/elastic/apm/agent/mongodb/MongoHelper.java b/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/main/java/co/elastic/apm/agent/mongodb/MongoHelper.java index 17cd6818cee..5288df61d83 100644 --- a/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/main/java/co/elastic/apm/agent/mongodb/MongoHelper.java +++ b/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/main/java/co/elastic/apm/agent/mongodb/MongoHelper.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.mongodb; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -34,16 +34,15 @@ public class MongoHelper { private static final Logger logger = LoggerFactory.getLogger(MongoHelper.class); - private final Tracer tracer; + private static final Tracer tracer = GlobalTracer.get(); private final MongoConfiguration config; public MongoHelper() { - this.tracer = GlobalTracer.get(); this.config = tracer.getConfig(MongoConfiguration.class); } - public Span startSpan(@Nullable String database, @Nullable String collection, @Nullable String command, String host, int port, @Nullable BsonDocument commandDocument) { - Span span = null; + public Span startSpan(@Nullable String database, @Nullable String collection, @Nullable String command, String host, int port, @Nullable BsonDocument commandDocument) { + Span span = null; final AbstractSpan activeSpan = tracer.getActive(); if (activeSpan != null) { span = activeSpan.createExitSpan(); diff --git a/apm-agent-plugins/apm-mongodb/apm-mongodb3-plugin/src/main/java/co/elastic/apm/agent/mongodb/v3/ConnectionCommandInstrumentation.java b/apm-agent-plugins/apm-mongodb/apm-mongodb3-plugin/src/main/java/co/elastic/apm/agent/mongodb/v3/ConnectionCommandInstrumentation.java index f0d8aa462d1..0fe9a9fec3d 100644 --- a/apm-agent-plugins/apm-mongodb/apm-mongodb3-plugin/src/main/java/co/elastic/apm/agent/mongodb/v3/ConnectionCommandInstrumentation.java +++ b/apm-agent-plugins/apm-mongodb/apm-mongodb3-plugin/src/main/java/co/elastic/apm/agent/mongodb/v3/ConnectionCommandInstrumentation.java @@ -18,8 +18,7 @@ */ package co.elastic.apm.agent.mongodb.v3; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.mongodb.MongoHelper; import com.mongodb.MongoNamespace; import com.mongodb.ServerAddress; @@ -80,8 +79,8 @@ public static Object onEnter(@Advice.This Connection thiz, @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void onExit(@Nullable @Advice.Enter Object spanObj, @Advice.Thrown Throwable thrown) { - if (spanObj instanceof Span) { - Span span = (Span) spanObj; + if (spanObj instanceof Span) { + Span span = (Span) spanObj; span.deactivate() .captureException(thrown) .end(); diff --git a/apm-agent-plugins/apm-mongodb/apm-mongodb3-plugin/src/main/java/co/elastic/apm/agent/mongodb/v3/ConnectionInstrumentation.java b/apm-agent-plugins/apm-mongodb/apm-mongodb3-plugin/src/main/java/co/elastic/apm/agent/mongodb/v3/ConnectionInstrumentation.java index f34bcdfa0c7..3c83ecab07f 100644 --- a/apm-agent-plugins/apm-mongodb/apm-mongodb3-plugin/src/main/java/co/elastic/apm/agent/mongodb/v3/ConnectionInstrumentation.java +++ b/apm-agent-plugins/apm-mongodb/apm-mongodb3-plugin/src/main/java/co/elastic/apm/agent/mongodb/v3/ConnectionInstrumentation.java @@ -18,8 +18,7 @@ */ package co.elastic.apm.agent.mongodb.v3; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.mongodb.MongoHelper; import com.mongodb.MongoNamespace; import com.mongodb.ServerAddress; @@ -93,8 +92,8 @@ public static Object onEnter(@Advice.This Connection thiz, @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void onExit(@Nullable @Advice.Enter Object spanObj, @Advice.Thrown Throwable thrown) { - if (spanObj instanceof Span) { - Span span = (Span) spanObj; + if (spanObj instanceof Span) { + Span span = (Span) spanObj; span.deactivate().captureException(thrown); span.end(); } diff --git a/apm-agent-plugins/apm-mongodb/apm-mongodb4-plugin/src/main/java/co/elastic/apm/agent/mongodb/v4/ConnectionCommandInstrumentation.java b/apm-agent-plugins/apm-mongodb/apm-mongodb4-plugin/src/main/java/co/elastic/apm/agent/mongodb/v4/ConnectionCommandInstrumentation.java index 4e83bde60e6..73e53aeee16 100644 --- a/apm-agent-plugins/apm-mongodb/apm-mongodb4-plugin/src/main/java/co/elastic/apm/agent/mongodb/v4/ConnectionCommandInstrumentation.java +++ b/apm-agent-plugins/apm-mongodb/apm-mongodb4-plugin/src/main/java/co/elastic/apm/agent/mongodb/v4/ConnectionCommandInstrumentation.java @@ -18,8 +18,7 @@ */ package co.elastic.apm.agent.mongodb.v4; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.mongodb.MongoHelper; import com.mongodb.ServerAddress; import com.mongodb.internal.connection.Connection; @@ -75,8 +74,8 @@ public static Object onEnter(@Advice.This Connection thiz, @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void onExit(@Nullable @Advice.Enter Object spanObj, @Advice.Thrown Throwable thrown) { - if (spanObj instanceof Span) { - Span span = (Span) spanObj; + if (spanObj instanceof Span) { + Span span = (Span) spanObj; span.deactivate() .captureException(thrown) .end(); 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 712787697d1..b5a3b80f9a2 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 @@ -19,10 +19,7 @@ package co.elastic.apm.agent.okhttp; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.*; import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument; import net.bytebuddy.asm.Advice.AssignReturned.ToFields.ToField; @@ -80,14 +77,14 @@ public static Object[] onBeforeEnqueue(final @Advice.Origin Class span = HttpClientHelper.startHttpClientSpan(parent, request.method(), url.toString(), url.scheme(), OkHttpClientHelper.computeHostName(url.host()), url.port()); if (span != null) { span.activate(); } - if (!TraceContext.containsTraceContextTextHeaders(request, OkHttp3RequestHeaderGetter.INSTANCE)) { + if (!TraceContextUtil.containsTraceContextTextHeaders(request, OkHttp3RequestHeaderGetter.INSTANCE)) { Request.Builder builder = originalRequest.newBuilder(); if (span != null) { span.propagateTraceContext(builder, OkHttp3RequestHeaderSetter.INSTANCE); @@ -103,7 +100,7 @@ public static Object[] onBeforeEnqueue(final @Advice.Origin Class span = enter != null ? (Span) enter[2] : null; if (span != null) { span.deactivate(); } @@ -114,15 +111,15 @@ public static class CallbackWrapperCreator implements WrapperCreator { public static final CallbackWrapperCreator INSTANCE = new CallbackWrapperCreator(); @Override - public Callback wrap(final Callback delegate, Span span) { + public Callback wrap(final Callback delegate, Span span) { return new CallbackWrapper(span, delegate); } private static class CallbackWrapper implements Callback { - private final Span span; + private final Span span; private final Callback delegate; - CallbackWrapper(Span span, Callback delegate) { + CallbackWrapper(Span span, Callback delegate) { this.span = span; this.delegate = delegate; } @@ -130,7 +127,7 @@ private static class CallbackWrapper implements Callback { @Override public void onFailure(Call call, IOException e) { try { - span.captureException(e).withOutcome(Outcome.FAILURE).end(); + span.captureException(e).withOutcome(DefaultOutcome.FAILURE).end(); } catch (Throwable t) { logger.error(t.getMessage(), t); } finally { 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 05bd8a643ff..e2528b4d103 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 @@ -19,10 +19,7 @@ package co.elastic.apm.agent.okhttp; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.*; import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice.AssignReturned.ToFields.ToField; import net.bytebuddy.description.method.MethodDescription; @@ -63,14 +60,14 @@ public static Object[] onBeforeExecute(final @Advice.FieldValue("originalRequest okhttp3.Request request = (okhttp3.Request) originalRequest; HttpUrl url = request.url(); - Span span = HttpClientHelper.startHttpClientSpan(parent, request.method(), url.toString(), url.scheme(), + Span span = HttpClientHelper.startHttpClientSpan(parent, request.method(), url.toString(), url.scheme(), OkHttpClientHelper.computeHostName(url.host()), url.port()); if (span != null) { span.activate(); } - if (!TraceContext.containsTraceContextTextHeaders(request, OkHttp3RequestHeaderGetter.INSTANCE)) { + if (false) { // TODO !TraceContext.containsTraceContextTextHeaders(request, OkHttp3RequestHeaderGetter.INSTANCE)) { Request.Builder builder = ((Request) originalRequest).newBuilder(); if (span != null) { span.propagateTraceContext(builder, OkHttp3RequestHeaderSetter.INSTANCE); @@ -86,9 +83,9 @@ public static Object[] onBeforeExecute(final @Advice.FieldValue("originalRequest public static void onAfterExecute(@Advice.Return @Nullable okhttp3.Response response, @Advice.Thrown @Nullable Throwable t, @Advice.Enter @Nonnull Object[] enter) { - Span span = null; - if (enter[1] instanceof Span) { - span = (Span) enter[1]; + Span span = null; + if (enter[1] instanceof Span) { + span = (Span) enter[1]; } if (span != null) { try { @@ -96,7 +93,7 @@ public static void onAfterExecute(@Advice.Return @Nullable okhttp3.Response resp int statusCode = response.code(); span.getContext().getHttp().withStatusCode(statusCode); } else if (t != null) { - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } span.captureException(t); } finally { diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3RequestHeaderGetter.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3RequestHeaderGetter.java index a6e03f8de6d..d56540718c1 100644 --- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3RequestHeaderGetter.java +++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3RequestHeaderGetter.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.okhttp; -import co.elastic.apm.agent.impl.transaction.AbstractHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.AbstractHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import okhttp3.Headers; import okhttp3.Request; diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3RequestHeaderSetter.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3RequestHeaderSetter.java index e36e739296d..1fc850ec4d7 100644 --- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3RequestHeaderSetter.java +++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3RequestHeaderSetter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.okhttp; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import okhttp3.Request; @SuppressWarnings("unused") 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 fe24707eea4..fb6410b6d50 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 @@ -19,10 +19,7 @@ package co.elastic.apm.agent.okhttp; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.*; import com.squareup.okhttp.Call; import com.squareup.okhttp.Callback; import com.squareup.okhttp.Request; @@ -76,14 +73,14 @@ public static Object[] onBeforeEnqueue(final @Advice.Origin Class span = HttpClientHelper.startHttpClientSpan(parent, request.method(), url.toString(), url.getProtocol(), OkHttpClientHelper.computeHostName(url.getHost()), url.getPort()); if (span != null) { span.activate(); } - if (!TraceContext.containsTraceContextTextHeaders(request, OkHttpRequestHeaderGetter.INSTANCE)) { + if (!TraceContextUtil.containsTraceContextTextHeaders(request, OkHttpRequestHeaderGetter.INSTANCE)) { Request.Builder builder = originalRequest.newBuilder(); if (span != null) { span.propagateTraceContext(builder, OkHttpRequestHeaderSetter.INSTANCE); @@ -99,7 +96,7 @@ public static Object[] onBeforeEnqueue(final @Advice.Origin Class span = enter != null ? (Span) enter[2] : null; if (span != null) { span.deactivate(); } @@ -111,15 +108,15 @@ public static class CallbackWrapperCreator implements WrapperCreator { public static final CallbackWrapperCreator INSTANCE = new CallbackWrapperCreator(); @Override - public Callback wrap(final Callback delegate, Span span) { + public Callback wrap(final Callback delegate, Span span) { return new CallbackWrapper(span, delegate); } private static class CallbackWrapper implements Callback { - private final Span span; + private final Span span; private final Callback delegate; - CallbackWrapper(Span span, Callback delegate) { + CallbackWrapper(Span span, Callback delegate) { this.span = span; this.delegate = delegate; } @@ -128,7 +125,7 @@ private static class CallbackWrapper implements Callback { public void onFailure(Request req, IOException e) { try { span.captureException(e) - .withOutcome(Outcome.FAILURE) + .withOutcome(DefaultOutcome.FAILURE) .end(); } catch (Throwable t) { logger.error(t.getMessage(), t); 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 916692350c2..161e15fcf2a 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 @@ -19,10 +19,7 @@ package co.elastic.apm.agent.okhttp; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.*; import com.squareup.okhttp.HttpUrl; import com.squareup.okhttp.Request; import net.bytebuddy.asm.Advice; @@ -60,14 +57,14 @@ public static Object[] onBeforeExecute(@Advice.FieldValue("originalRequest") @Nu com.squareup.okhttp.Request request = (com.squareup.okhttp.Request) originalRequest; HttpUrl httpUrl = request.httpUrl(); - Span span = HttpClientHelper.startHttpClientSpan(parent, request.method(), httpUrl.toString(), httpUrl.scheme(), + Span span = HttpClientHelper.startHttpClientSpan(parent, request.method(), httpUrl.toString(), httpUrl.scheme(), OkHttpClientHelper.computeHostName(httpUrl.host()), httpUrl.port()); if (span != null) { span.activate(); } - if (!TraceContext.containsTraceContextTextHeaders(request, OkHttpRequestHeaderGetter.INSTANCE)) { + if (!TraceContextUtil.containsTraceContextTextHeaders(request, OkHttpRequestHeaderGetter.INSTANCE)) { Request.Builder builder = ((Request) originalRequest).newBuilder(); if (span != null) { span.propagateTraceContext(builder, OkHttpRequestHeaderSetter.INSTANCE); @@ -84,9 +81,9 @@ public static Object[] onBeforeExecute(@Advice.FieldValue("originalRequest") @Nu public static void onAfterExecute(@Advice.Return @Nullable com.squareup.okhttp.Response response, @Advice.Thrown @Nullable Throwable t, @Advice.Enter @Nonnull Object[] enter) { - Span span = null; - if (enter[1] instanceof Span) { - span = (Span) enter[1]; + Span span = null; + if (enter[1] instanceof Span) { + span = (Span) enter[1]; } if (span != null) { try { @@ -94,7 +91,7 @@ public static void onAfterExecute(@Advice.Return @Nullable com.squareup.okhttp.R int statusCode = response.code(); span.getContext().getHttp().withStatusCode(statusCode); } else if (t != null) { - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } span.captureException(t); } finally { diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpRequestHeaderGetter.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpRequestHeaderGetter.java index 69f73c13758..e79582fe316 100644 --- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpRequestHeaderGetter.java +++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpRequestHeaderGetter.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.okhttp; -import co.elastic.apm.agent.impl.transaction.AbstractHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.AbstractHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import com.squareup.okhttp.Headers; import com.squareup.okhttp.Request; diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpRequestHeaderSetter.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpRequestHeaderSetter.java index e250deb82f1..a7b475625b8 100644 --- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpRequestHeaderSetter.java +++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpRequestHeaderSetter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.okhttp; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import com.squareup.okhttp.Request; @SuppressWarnings("unused") diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/WrapperCreator.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/WrapperCreator.java index e5ae857f03c..8b944ee82d9 100644 --- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/WrapperCreator.java +++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/WrapperCreator.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.okhttp; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; /** * Used to create a wrapper for a callback or listener @@ -37,5 +37,5 @@ public interface WrapperCreator { * @param span the currently active span * @return the wrapped callback */ - T wrap(T delegate, Span span); + T wrap(T delegate, Span span); } diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/OpenTracingTextMapBridge.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/OpenTracingTextMapBridge.java index 43cce696094..da1de44f496 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/OpenTracingTextMapBridge.java +++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/OpenTracingTextMapBridge.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.opentracingimpl; +import co.elastic.apm.agent.impl.transaction.HeaderGetter; import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; @@ -47,7 +48,16 @@ public String getFirstHeader(String headerName, Iterable void forEach(String headerName, Iterable> carrier, S state, HeaderConsumer consumer) { + public void forEach(String headerName, Iterable> carrier, S state, HeaderGetter.HeaderConsumer consumer) { + for (Map.Entry entry : carrier) { + if (entry.getKey().equalsIgnoreCase(headerName)) { + consumer.accept(entry.getValue(), state); + } + } + } + + @Override + public void forEach(String headerName, Iterable> carrier, S state, co.elastic.apm.plugin.spi.HeaderGetter.HeaderConsumer consumer) { for (Map.Entry entry : carrier) { if (entry.getKey().equalsIgnoreCase(headerName)) { consumer.accept(entry.getValue(), state); 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 4c54050fa14..0838b3d81ac 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 @@ -19,9 +19,10 @@ package co.elastic.apm.agent.process; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.DefaultOutcome; +import co.elastic.apm.plugin.spi.Outcome; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.sdk.state.GlobalVariables; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; @@ -34,7 +35,7 @@ */ class ProcessHelper { - private static final ProcessHelper INSTANCE = new ProcessHelper(WeakConcurrentProviderImpl.createWeakSpanMap()); + private static final ProcessHelper INSTANCE = new ProcessHelper(WeakConcurrentProviderImpl.>createWeakSpanMap()); /** * A thread local used to indicate whether the currently invoked instrumented method is invoked by the plugin itself. @@ -44,9 +45,9 @@ class ProcessHelper { */ private static final ThreadLocal inTracingContext = GlobalVariables.get(ProcessHelper.class, "inTracingContext", new ThreadLocal()); - private final WeakMap inFlightSpans; + private final WeakMap> inFlightSpans; - ProcessHelper(WeakMap inFlightSpans) { + ProcessHelper(WeakMap> inFlightSpans) { this.inFlightSpans = inFlightSpans; } @@ -80,7 +81,7 @@ void doStartProcess(@Nonnull AbstractSpan parentContext, @Nonnull Process pro String binaryName = getBinaryName(processName); - Span span = parentContext.createSpan() + Span span = parentContext.createSpan() .withType("process") .withName(binaryName); @@ -104,12 +105,12 @@ private static String getBinaryName(String processName) { */ void doEndProcess(Process process, boolean checkTerminatedProcess) { - Span span = inFlightSpans.get(process); + Span span = inFlightSpans.get(process); if (span == null) { return; } - Outcome outcome = Outcome.UNKNOWN; + Outcome outcome = DefaultOutcome.UNKNOWN; boolean endAndRemoveSpan = !checkTerminatedProcess; if (checkTerminatedProcess) { // borrowed from java 8 Process#isAlive() @@ -119,11 +120,11 @@ void doEndProcess(Process process, boolean checkTerminatedProcess) { try { inTracingContext.set(Boolean.TRUE); int exitValue = process.exitValue(); - outcome = exitValue == 0 ? Outcome.SUCCESS : Outcome.FAILURE; + outcome = exitValue == 0 ? DefaultOutcome.SUCCESS : DefaultOutcome.FAILURE; endAndRemoveSpan = true; } catch (IllegalThreadStateException e) { // process hasn't terminated, we don't know it's actual return value - outcome = Outcome.UNKNOWN; + outcome = DefaultOutcome.UNKNOWN; endAndRemoveSpan = false; } finally { inTracingContext.remove(); @@ -141,14 +142,14 @@ void doEndProcess(Process process, boolean checkTerminatedProcess) { * @param exitValue exit value of the terminated process */ void doEndProcessSpan(Process process, int exitValue) { - removeAndEndSpan(process, exitValue == 0 ? Outcome.SUCCESS : Outcome.FAILURE); + removeAndEndSpan(process, exitValue == 0 ? DefaultOutcome.SUCCESS : DefaultOutcome.FAILURE); } private void removeAndEndSpan(Process process, Outcome outcome) { - Span span = inFlightSpans.remove(process); + Span span = inFlightSpans.remove(process); if (span != null) { - span.withOutcome(outcome). - end(); + span.withOutcome(outcome) + .end(); } } } diff --git a/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessStartInstrumentation.java b/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessStartInstrumentation.java index 027526137b0..63c64d89134 100644 --- a/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessStartInstrumentation.java +++ b/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessStartInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.process; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.AbstractSpan; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; 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 12d8cc08a8d..39b40d6fcb9 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 @@ -48,7 +48,7 @@ class ProcessHelperTest extends AbstractInstrumentationTest { private Transaction transaction; - private WeakMap storageMap; + private WeakMap> storageMap; private ProcessHelper helper; @BeforeEach @@ -85,7 +85,7 @@ void startTwiceShouldIgnore() { Process process = mock(Process.class); helper.doStartProcess(transaction, process, "hello"); - Span span = storageMap.get(process); + Span span = (Span) storageMap.get(process); helper.doStartProcess(transaction, process, "hello"); assertThat(storageMap.get(process)) diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/CallTree.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/CallTree.java index 381d2be8da9..c7fda6819d1 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/CallTree.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/CallTree.java @@ -78,7 +78,7 @@ public class CallTree implements Recyclable { private boolean isSpan; private int depth; /** - * @see co.elastic.apm.agent.impl.transaction.AbstractSpan#childIds + * @see co.elastic.apm.plugin.spi.AbstractSpan#childIds */ @Nullable private LongList childIds; diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingActivationListener.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingActivationListener.java index a38311b359a..277759536fe 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingActivationListener.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingActivationListener.java @@ -20,7 +20,6 @@ import co.elastic.apm.agent.impl.ActivationListener; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.Tracer; import co.elastic.apm.agent.impl.transaction.AbstractSpan; import java.util.Objects; diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java index 04a77a9ebcd..b2e76786f72 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java @@ -23,9 +23,8 @@ import co.elastic.apm.agent.context.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.StackFrame; import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.transaction.StackFrame; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.objectpool.Allocator; import co.elastic.apm.agent.objectpool.ObjectPool; diff --git a/apm-agent-plugins/apm-quartz-job-plugin/apm-quartz-1-plugin/src/main/java/co/elastic/apm/agent/quartzjob/Quartz1JobTransactionNameInstrumentation.java b/apm-agent-plugins/apm-quartz-job-plugin/apm-quartz-1-plugin/src/main/java/co/elastic/apm/agent/quartzjob/Quartz1JobTransactionNameInstrumentation.java index a4e31f72fb1..58f4c001658 100644 --- a/apm-agent-plugins/apm-quartz-job-plugin/apm-quartz-1-plugin/src/main/java/co/elastic/apm/agent/quartzjob/Quartz1JobTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-quartz-job-plugin/apm-quartz-1-plugin/src/main/java/co/elastic/apm/agent/quartzjob/Quartz1JobTransactionNameInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.quartzjob; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; diff --git a/apm-agent-plugins/apm-quartz-job-plugin/apm-quartz-2-plugin/src/main/java/co/elastic/apm/agent/quartzjob/Quartz2JobTransactionNameInstrumentation.java b/apm-agent-plugins/apm-quartz-job-plugin/apm-quartz-2-plugin/src/main/java/co/elastic/apm/agent/quartzjob/Quartz2JobTransactionNameInstrumentation.java index f2ce10e5c47..7542fc04f23 100644 --- a/apm-agent-plugins/apm-quartz-job-plugin/apm-quartz-2-plugin/src/main/java/co/elastic/apm/agent/quartzjob/Quartz2JobTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-quartz-job-plugin/apm-quartz-2-plugin/src/main/java/co/elastic/apm/agent/quartzjob/Quartz2JobTransactionNameInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.quartzjob; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; diff --git a/apm-agent-plugins/apm-quartz-job-plugin/quartz-common/src/main/java/co/elastic/apm/agent/quartzjob/AbstractJobTransactionNameInstrumentation.java b/apm-agent-plugins/apm-quartz-job-plugin/quartz-common/src/main/java/co/elastic/apm/agent/quartzjob/AbstractJobTransactionNameInstrumentation.java index a58ef6fec1e..9287d7572b5 100644 --- a/apm-agent-plugins/apm-quartz-job-plugin/quartz-common/src/main/java/co/elastic/apm/agent/quartzjob/AbstractJobTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-quartz-job-plugin/quartz-common/src/main/java/co/elastic/apm/agent/quartzjob/AbstractJobTransactionNameInstrumentation.java @@ -19,12 +19,9 @@ package co.elastic.apm.agent.quartzjob; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.util.PrivilegedActionUtils; import co.elastic.apm.agent.util.VersionUtils; import net.bytebuddy.description.NamedElement; @@ -73,9 +70,9 @@ static class BaseAdvice { private static final Logger logger = LoggerFactory.getLogger(BaseAdvice.class); @Nullable - protected static Transaction createAndActivateTransaction(@Nullable T jobExecutionContext, String signature, Class clazz, JobExecutionContextHandler helper) { - Transaction transaction = null; - AbstractSpan active = GlobalTracer.get().getActive(); + protected static Transaction createAndActivateTransaction(@Nullable T jobExecutionContext, String signature, Class clazz, JobExecutionContextHandler helper) { + Transaction transaction = null; + AbstractSpan active = tracer.getActive(); if (active == null) { String transactionName = null; if (jobExecutionContext != null) { @@ -97,8 +94,8 @@ protected static void endTransaction(@Nullable T jobExecutionContext, @Nullable Object transactionObj, @Nullable Throwable t, JobExecutionContextHandler helper) { - if (transactionObj instanceof Transaction) { - Transaction transaction = (Transaction) transactionObj; + if (transactionObj instanceof Transaction) { + Transaction transaction = (Transaction) transactionObj; if (jobExecutionContext != null) { Object result = helper.getResult(jobExecutionContext); if (result != null) { @@ -106,15 +103,15 @@ protected static void endTransaction(@Nullable T jobExecutionContext, } } transaction.captureException(t) - .withOutcome(t != null ? Outcome.FAILURE : Outcome.SUCCESS) + .withOutcome(t != null ? DefaultOutcome.FAILURE : DefaultOutcome.SUCCESS) .deactivate() .end(); } } @Nullable - private static Transaction createAndActivateTransaction(Class originClass, String name) { - Transaction transaction = GlobalTracer.get().startRootTransaction(PrivilegedActionUtils.getClassLoader(originClass)); + private static Transaction createAndActivateTransaction(Class originClass, String name) { + Transaction transaction = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(originClass)); if (transaction != null) { transaction.withName(name) .withType(AbstractJobTransactionNameInstrumentation.TRANSACTION_TYPE) diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/AbstractBaseInstrumentation.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/AbstractBaseInstrumentation.java index 5db3d494459..d289187975b 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/AbstractBaseInstrumentation.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/AbstractBaseInstrumentation.java @@ -21,10 +21,10 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.context.Message; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.AbstractSpan; import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.plugin.spi.Message; import javax.annotation.Nullable; import java.util.Date; diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ChannelInstrumentation.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ChannelInstrumentation.java index 7d59af8ba03..230e5e2f8b3 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ChannelInstrumentation.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ChannelInstrumentation.java @@ -18,13 +18,13 @@ */ package co.elastic.apm.agent.rabbitmq; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.rabbitmq.header.RabbitMQTextHeaderGetter; import co.elastic.apm.agent.rabbitmq.header.RabbitMQTextHeaderSetter; import co.elastic.apm.agent.sdk.DynamicTransformer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; +import co.elastic.apm.plugin.spi.TraceContextUtil; import com.rabbitmq.client.AMQP; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; @@ -134,7 +134,7 @@ public static Object[] onBasicPublish(@Advice.This Channel channel, return null; } - Span exitSpan = RabbitMqHelper.createExitSpan(exchange); + Span exitSpan = RabbitMqHelper.createExitSpan(exchange); if (exitSpan == null) { // tracer disabled or ignored exchange or this is nested within another exit span return null; @@ -154,7 +154,7 @@ public static Object[] onBasicPublish(@Advice.This Channel channel, return new Object[]{properties, exitSpan}; } - private static AMQP.BasicProperties propagateTraceContext(Span exitSpan, + private static AMQP.BasicProperties propagateTraceContext(Span exitSpan, @Nullable AMQP.BasicProperties originalBasicProperties) { AMQP.BasicProperties properties = originalBasicProperties; if (properties == null) { @@ -177,7 +177,7 @@ private static AMQP.BasicProperties propagateTraceContext(Span exitSpan, public static void afterBasicPublish(@Advice.Enter @Nullable Object[] enterArray, @Advice.Thrown @Nullable Throwable throwable) { if (enterArray != null && enterArray.length >= 2 && enterArray[1] != null) { - Span span = (Span) enterArray[1]; + Span span = (Span) enterArray[1]; span.captureException(throwable) .deactivate() .end(); @@ -219,10 +219,10 @@ public static void onExit(@Advice.This Channel channel, @Advice.Return @Nullable GetResponse rv, @Advice.Thrown @Nullable Throwable thrown) { - if (!(objSpan instanceof Span)) { + if (!(objSpan instanceof Span)) { return; } - Span span = (Span) objSpan; + Span span = (Span) objSpan; if (isIgnored(queue)) { // allow to ignore on queue name when there is no answer @@ -255,7 +255,7 @@ public static void onExit(@Advice.This Channel channel, if (properties != null) { span.addSpanLink( - TraceContext.getFromTraceContextTextHeaders(), + TraceContextUtil.getFromTraceContextTextHeaders(), RabbitMQTextHeaderGetter.INSTANCE, properties); } @@ -275,12 +275,12 @@ public static class RabbitMqHelper { * @return exit span if applicable, {@literal null} otherwise */ @Nullable - public static Span createExitSpan(@Nullable String exchangeOrQueue) { + public static Span createExitSpan(@Nullable String exchangeOrQueue) { AbstractSpan context = tracer.getActive(); if (exchangeOrQueue == null || context == null || isIgnored(exchangeOrQueue)) { return null; } - Span exitSpan = context.createExitSpan(); + Span exitSpan = context.createExitSpan(); if (exitSpan == null) { return null; } @@ -298,7 +298,7 @@ public static Span createExitSpan(@Nullable String exchangeOrQueue) { * @param port broker port * @param span span */ - public static void captureDestination(String exchange, InetAddress brokerAddress, int port, Span span) { + public static void captureDestination(String exchange, InetAddress brokerAddress, int port, Span span) { span.getContext().getDestination() .withInetAddress(brokerAddress) .withPort(port); diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ConsumerInstrumentation.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ConsumerInstrumentation.java index daf76490384..e5637a18519 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ConsumerInstrumentation.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ConsumerInstrumentation.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.rabbitmq; -import co.elastic.apm.agent.impl.context.Message; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Message; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.rabbitmq.header.RabbitMQTextHeaderGetter; import co.elastic.apm.agent.util.PrivilegedActionUtils; import com.rabbitmq.client.AMQP; @@ -96,7 +96,7 @@ public static Object onHandleDelivery(@Advice.Origin Class originClazz, return null; } - Transaction transaction = tracer.currentTransaction(); + Transaction transaction = tracer.currentTransaction(); if (transaction != null) { return null; } @@ -122,8 +122,8 @@ public static Object onHandleDelivery(@Advice.Origin Class originClazz, @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false) public static void afterHandleDelivery(@Advice.Enter @Nullable final Object transactionObject, @Advice.Thrown @Nullable final Throwable throwable) { - if (transactionObject instanceof Transaction) { - Transaction transaction = (Transaction) transactionObject; + if (transactionObject instanceof Transaction) { + Transaction transaction = (Transaction) transactionObject; transaction.captureException(throwable) .deactivate() .end(); diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/header/AbstractTextHeaderGetter.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/header/AbstractTextHeaderGetter.java index bb8869f8239..d9e61320acd 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/header/AbstractTextHeaderGetter.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/header/AbstractTextHeaderGetter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.rabbitmq.header; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import javax.annotation.Nullable; import java.util.Map; diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/header/RabbitMQTextHeaderSetter.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/header/RabbitMQTextHeaderSetter.java index 6312c965c8c..1101fdf3058 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/header/RabbitMQTextHeaderSetter.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/header/RabbitMQTextHeaderSetter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.rabbitmq.header; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import java.util.HashMap; diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/MessageBatchHelper.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/MessageBatchHelper.java index 475ca37e3fe..dbe0677413f 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/MessageBatchHelper.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/MessageBatchHelper.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.rabbitmq; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import org.springframework.amqp.core.Message; diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/MessageBatchIteratorWrapper.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/MessageBatchIteratorWrapper.java index 03630860f76..0af235af0a3 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/MessageBatchIteratorWrapper.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/MessageBatchIteratorWrapper.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.rabbitmq; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import org.springframework.amqp.core.Message; @@ -49,7 +49,7 @@ public boolean hasNext() { public void endCurrentTransaction() { try { - Transaction transaction = tracer.currentTransaction(); + Transaction transaction = tracer.currentTransaction(); if (transaction != null && "messaging".equals(transaction.getType())) { transaction.deactivate().end(); } diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/MessageBatchListWrapper.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/MessageBatchListWrapper.java index 37f3608a1d8..a8eff100e04 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/MessageBatchListWrapper.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/MessageBatchListWrapper.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.rabbitmq; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import org.springframework.amqp.core.Message; import java.util.Collection; diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpBatchMessageListenerInstrumentation.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpBatchMessageListenerInstrumentation.java index 3f78e6b7170..bab80acca42 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpBatchMessageListenerInstrumentation.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpBatchMessageListenerInstrumentation.java @@ -20,11 +20,7 @@ import co.elastic.apm.agent.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -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.plugin.spi.*; import co.elastic.apm.agent.rabbitmq.header.SpringRabbitMQTextHeaderGetter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -75,7 +71,7 @@ public static Object[] beforeOnBatch(@Advice.This Object thiz, @Advice.Argument(0) @Nullable final List messageBatch) { List processedBatch = messageBatch; - Transaction batchTransaction = null; + Transaction batchTransaction = null; if (tracer.isRunning() && messageBatch != null && !messageBatch.isEmpty()) { AbstractSpan active = tracer.getActive(); @@ -99,7 +95,7 @@ public static Object[] beforeOnBatch(@Advice.This Object thiz, MessageProperties messageProperties = message.getMessageProperties(); if (messageProperties != null) { active.addSpanLink( - TraceContext.getFromTraceContextTextHeaders(), + TraceContextUtil.getFromTraceContextTextHeaders(), SpringRabbitMQTextHeaderGetter.INSTANCE, messageProperties ); @@ -115,7 +111,7 @@ public static Object[] beforeOnBatch(@Advice.This Object thiz, @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void afterOnBatch(@Advice.Enter @Nullable Object[] enter, @Advice.Thrown @Nullable Throwable throwable) { - Transaction batchTransaction = enter != null ? (Transaction) enter[1] : null; + Transaction batchTransaction = enter != null ? (Transaction) enter[1] : null; if (batchTransaction != null) { try { batchTransaction diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpMessageListenerInstrumentation.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpMessageListenerInstrumentation.java index db1264012b6..5feed8cf2f5 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpMessageListenerInstrumentation.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpMessageListenerInstrumentation.java @@ -18,14 +18,13 @@ */ package co.elastic.apm.agent.rabbitmq; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageListener; -import org.springframework.amqp.core.MessageProperties; import javax.annotation.Nullable; @@ -76,8 +75,8 @@ public static Object beforeMessageHandle(@Advice.This MessageListener listener, @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false) public static void afterMessageHandle(@Advice.Enter @Nullable final Object transactionObject, @Advice.Thrown @Nullable final Throwable throwable) { - if (transactionObject instanceof Transaction) { - Transaction transaction = (Transaction) transactionObject; + if (transactionObject instanceof Transaction) { + Transaction transaction = (Transaction) transactionObject; transaction.captureException(throwable) .deactivate() .end(); diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpTransactionHelper.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpTransactionHelper.java index 6cb63aac0df..a13d8e2bb6d 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpTransactionHelper.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringAmqpTransactionHelper.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.rabbitmq; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.rabbitmq.header.SpringRabbitMQTextHeaderGetter; import co.elastic.apm.agent.util.PrivilegedActionUtils; import org.springframework.amqp.core.Message; @@ -36,7 +36,7 @@ public SpringAmqpTransactionHelper(Tracer tracer) { } @Nullable - public Transaction createTransaction(Message message, String transactionNamePrefix) { + public Transaction createTransaction(Message message, String transactionNamePrefix) { String exchange = null; MessageProperties messageProperties = message.getMessageProperties(); if (messageProperties != null) { @@ -46,7 +46,7 @@ public Transaction createTransaction(Message message, String transactionNamePref return null; } - Transaction transaction = tracer.currentTransaction(); + Transaction transaction = tracer.currentTransaction(); if (transaction != null) { return null; } diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringBaseInstrumentation.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringBaseInstrumentation.java index 218b02b7fe1..c188843d8c9 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringBaseInstrumentation.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/main/java/co/elastic/apm/agent/rabbitmq/SpringBaseInstrumentation.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.rabbitmq; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; diff --git a/apm-agent-plugins/apm-reactor-plugin/src/main/java/co/elastic/apm/agent/reactor/TracedSubscriber.java b/apm-agent-plugins/apm-reactor-plugin/src/main/java/co/elastic/apm/agent/reactor/TracedSubscriber.java index c0d7a8771a9..18069a018b6 100644 --- a/apm-agent-plugins/apm-reactor-plugin/src/main/java/co/elastic/apm/agent/reactor/TracedSubscriber.java +++ b/apm-agent-plugins/apm-reactor-plugin/src/main/java/co/elastic/apm/agent/reactor/TracedSubscriber.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.reactor; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.AbstractSpan; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.sdk.state.GlobalVariables; diff --git a/apm-agent-plugins/apm-redis-plugin/apm-jedis-4-plugin/src/main/java/co/elastic/apm/agent/jedis/Jedis4SendCommandAdvice.java b/apm-agent-plugins/apm-redis-plugin/apm-jedis-4-plugin/src/main/java/co/elastic/apm/agent/jedis/Jedis4SendCommandAdvice.java index 5d5ec009da1..592bbf4ac51 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-jedis-4-plugin/src/main/java/co/elastic/apm/agent/jedis/Jedis4SendCommandAdvice.java +++ b/apm-agent-plugins/apm-redis-plugin/apm-jedis-4-plugin/src/main/java/co/elastic/apm/agent/jedis/Jedis4SendCommandAdvice.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.jedis; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.redis.RedisSpanUtils; import net.bytebuddy.asm.Advice; import redis.clients.jedis.CommandArguments; @@ -40,7 +40,7 @@ public static Object sendCommandEntry(@Advice.Argument(0) CommandArguments comma public static void sendCommandExit(@Advice.FieldValue("socketFactory") JedisSocketFactory socketFactory, @Nullable @Advice.Enter Object spanObj, @Nullable @Advice.Thrown Throwable thrown) { - Span span = (Span) spanObj; + Span span = (Span) spanObj; if (span != null) { if (socketFactory instanceof DefaultJedisSocketFactory) { HostAndPort hostAndPort = ((DefaultJedisSocketFactory) socketFactory).getHostAndPort(); diff --git a/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/src/main/java/co/elastic/apm/agent/jedis/SendCommandAdvice.java b/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/src/main/java/co/elastic/apm/agent/jedis/SendCommandAdvice.java index 3fd171d4d59..103e6d4c2da 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/src/main/java/co/elastic/apm/agent/jedis/SendCommandAdvice.java +++ b/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/src/main/java/co/elastic/apm/agent/jedis/SendCommandAdvice.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.jedis; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.redis.RedisSpanUtils; import net.bytebuddy.asm.Advice; import net.bytebuddy.implementation.bytecode.assign.Assigner; @@ -39,7 +39,7 @@ public static Object sendCommandEntry(@Advice.Argument(0) Object command) { public static void sendCommandExit(@Advice.This(typing = Assigner.Typing.DYNAMIC) Connection thiz, @Nullable @Advice.Enter Object spanObj, @Nullable @Advice.Thrown Throwable thrown) { - Span span = (Span) spanObj; + Span span = (Span) spanObj; if (span != null) { span.getContext().getDestination() .withAddress(thiz.getHost()) diff --git a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce34Instrumentation.java b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce34Instrumentation.java index 706da4bc46c..3c7cfa69271 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce34Instrumentation.java +++ b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce34Instrumentation.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; 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/lettuce/Lettuce34StartSpanInstrumentation.java b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce34StartSpanInstrumentation.java index 6e54c4de85f..35376885ff0 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce34StartSpanInstrumentation.java +++ b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce34StartSpanInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.lettuce; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.redis.RedisSpanUtils; import com.lambdaworks.redis.protocol.RedisCommand; import net.bytebuddy.asm.Advice; @@ -57,7 +57,7 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object beforeDispatch(@Nullable @Advice.Argument(0) RedisCommand command) { if (command != null) { - Span span = RedisSpanUtils.createRedisSpan(command.getType().toString()); + Span span = RedisSpanUtils.createRedisSpan(command.getType().toString()); if (span != null) { commandToSpan.put(command, span); return span; @@ -68,7 +68,7 @@ public static Object beforeDispatch(@Nullable @Advice.Argument(0) RedisCommand span = (Span) spanObj; if (span != null) { span.deactivate(); } diff --git a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce34StopSpanInstrumentation.java b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce34StopSpanInstrumentation.java index ddd989a3549..df4d3f6213f 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce34StopSpanInstrumentation.java +++ b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce34StopSpanInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.lettuce; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import com.lambdaworks.redis.protocol.RedisCommand; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; @@ -72,7 +72,7 @@ public static class OnComplete extends Lettuce34StopSpanInstrumentation { public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void beforeComplete(@Advice.This RedisCommand command) { - Span span = commandToSpan.remove(command); + Span span = commandToSpan.remove(command); if (span != null) { logger.debug("Command#complete"); span.end(); @@ -91,7 +91,7 @@ public static class OnCompleteExceptionally extends Lettuce34StopSpanInstrumenta public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void beforeComplete(@Advice.This RedisCommand command, @Advice.Argument(0) Throwable throwable) { - Span span = commandToSpan.remove(command); + Span span = commandToSpan.remove(command); if (span != null) { logger.debug("Command#completeExceptionally"); span.captureException(throwable).end(); @@ -110,7 +110,7 @@ public static class OnCancel extends Lettuce34StopSpanInstrumentation { public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void beforeComplete(@Advice.This RedisCommand command) { - Span span = commandToSpan.remove(command); + Span span = commandToSpan.remove(command); if (span != null) { logger.debug("Command#cancel"); span.end(); diff --git a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce5StartSpanInstrumentation.java b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce5StartSpanInstrumentation.java index ad23a44fdce..521b021b442 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce5StartSpanInstrumentation.java +++ b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce5StartSpanInstrumentation.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.redis.RedisSpanUtils; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import io.lettuce.core.protocol.RedisCommand; @@ -46,7 +46,7 @@ */ public class Lettuce5StartSpanInstrumentation extends TracerAwareInstrumentation { - static final WeakMap, Span> commandToSpan = WeakConcurrentProviderImpl.createWeakSpanMap(); + static final WeakMap, Span> commandToSpan = WeakConcurrentProviderImpl.createWeakSpanMap(); @Override public ElementMatcher getTypeMatcher() { @@ -71,7 +71,7 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object beforeDispatch(@Nullable @Advice.Argument(0) RedisCommand command) { if (command != null) { - Span span = RedisSpanUtils.createRedisSpan(command.getType().name()); + Span span = RedisSpanUtils.createRedisSpan(command.getType().name()); if (span != null) { commandToSpan.put(command, span); return span; @@ -82,7 +82,7 @@ public static Object beforeDispatch(@Nullable @Advice.Argument(0) RedisCommand span = (Span) spanObj; if (span != null) { span.deactivate(); } diff --git a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce5StopSpanInstrumentation.java b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce5StopSpanInstrumentation.java index e2a49eb10c1..805a257b7b4 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce5StopSpanInstrumentation.java +++ b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/src/main/java/co/elastic/apm/agent/lettuce/Lettuce5StopSpanInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.lettuce; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import io.lettuce.core.protocol.RedisCommand; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; @@ -72,7 +72,7 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void beforeComplete(@Advice.This RedisCommand command) { if (!command.isDone() && !command.isCancelled()) { - Span span = Lettuce5StartSpanInstrumentation.commandToSpan.remove(command); + Span span = Lettuce5StartSpanInstrumentation.commandToSpan.remove(command); if (span != null) { logger.debug("Command#complete"); span.end(); @@ -93,7 +93,7 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void beforeComplete(@Advice.This RedisCommand command, @Advice.Argument(0) Throwable throwable) { if (!command.isDone() && !command.isCancelled()) { - Span span = Lettuce5StartSpanInstrumentation.commandToSpan.remove(command); + Span span = Lettuce5StartSpanInstrumentation.commandToSpan.remove(command); if (span != null) { logger.debug("Command#completeExceptionally"); span.captureException(throwable).end(); @@ -114,7 +114,7 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void beforeComplete(@Advice.This RedisCommand command) { if (!command.isDone() && !command.isCancelled()) { - Span span = commandToSpan.remove(command); + Span span = commandToSpan.remove(command); if (span != null) { logger.debug("Command#cancel"); span.end(); diff --git a/apm-agent-plugins/apm-redis-plugin/apm-redis-common/src/main/java/co/elastic/apm/agent/redis/RedisSpanUtils.java b/apm-agent-plugins/apm-redis-plugin/apm-redis-common/src/main/java/co/elastic/apm/agent/redis/RedisSpanUtils.java index a6ad14f3608..8316fc58e37 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-redis-common/src/main/java/co/elastic/apm/agent/redis/RedisSpanUtils.java +++ b/apm-agent-plugins/apm-redis-plugin/apm-redis-common/src/main/java/co/elastic/apm/agent/redis/RedisSpanUtils.java @@ -18,21 +18,24 @@ */ package co.elastic.apm.agent.redis; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; +import co.elastic.apm.plugin.spi.Tracer; import javax.annotation.Nullable; public class RedisSpanUtils { + + private static final Tracer tracer = GlobalTracer.get(); @Nullable - public static Span createRedisSpan(String command) { - AbstractSpan activeSpan = GlobalTracer.get().getActive(); + public static Span createRedisSpan(String command) { + AbstractSpan activeSpan = tracer.getActive(); if (activeSpan == null) { return null; } - Span span = activeSpan.createExitSpan(); + Span span = activeSpan.createExitSpan(); if (span == null) { return null; } diff --git a/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/src/main/java/co/elastic/apm/agent/redisson/RedisConnectionInstrumentation.java b/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/src/main/java/co/elastic/apm/agent/redisson/RedisConnectionInstrumentation.java index fe0575e7ff0..76c406ea0a4 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/src/main/java/co/elastic/apm/agent/redisson/RedisConnectionInstrumentation.java +++ b/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/src/main/java/co/elastic/apm/agent/redisson/RedisConnectionInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.redisson; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.redis.RedisSpanUtils; import io.netty.channel.Channel; import net.bytebuddy.asm.Advice; @@ -47,7 +47,7 @@ public static class AdviceClass { @Advice.OnMethodEnter(inline = false) public static Object beforeSend(@Advice.This RedisConnection connection, @Advice.Argument(0) Object args) { - Span span = RedisSpanUtils.createRedisSpan(""); + Span span = RedisSpanUtils.createRedisSpan(""); if (span != null) { // get command if (args instanceof CommandsData) { @@ -72,7 +72,7 @@ public static Object beforeSend(@Advice.This RedisConnection connection, @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false) public static void afterSend(@Nullable @Advice.Enter Object spanObj, @Nullable @Advice.Thrown Throwable thrown) { - Span span = (Span) spanObj; + Span span = (Span) spanObj; if (span != null) { span.captureException(thrown) .deactivate() diff --git a/apm-agent-plugins/apm-scala-concurrent-plugin/src/main/java/co/elastic/apm/agent/scalaconcurrent/FutureInstrumentation.java b/apm-agent-plugins/apm-scala-concurrent-plugin/src/main/java/co/elastic/apm/agent/scalaconcurrent/FutureInstrumentation.java index 2e4660a0408..e445bfc5542 100644 --- a/apm-agent-plugins/apm-scala-concurrent-plugin/src/main/java/co/elastic/apm/agent/scalaconcurrent/FutureInstrumentation.java +++ b/apm-agent-plugins/apm-scala-concurrent-plugin/src/main/java/co/elastic/apm/agent/scalaconcurrent/FutureInstrumentation.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.AbstractSpan; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; diff --git a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/ScheduledTransactionNameInstrumentation.java b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/ScheduledTransactionNameInstrumentation.java index 9e56f0a43d7..091661a46bb 100644 --- a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/ScheduledTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/ScheduledTransactionNameInstrumentation.java @@ -20,11 +20,8 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory.SimpleMethodSignature; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.util.PrivilegedActionUtils; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; @@ -63,7 +60,7 @@ public static Object setTransactionName(@SimpleMethodSignature String signature, @Advice.Origin Class clazz) { AbstractSpan active = tracer.getActive(); if (active == null) { - Transaction transaction = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(clazz)); + Transaction transaction = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(clazz)); if (transaction != null) { transaction.withName(signature) .withType("scheduled") @@ -79,10 +76,10 @@ public static Object setTransactionName(@SimpleMethodSignature String signature, @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void onMethodExit(@Advice.Enter @Nullable Object transactionObj, @Advice.Thrown @Nullable Throwable t) { - if (transactionObj instanceof Transaction) { - Transaction transaction = (Transaction) transactionObj; + if (transactionObj instanceof Transaction) { + Transaction transaction = (Transaction) transactionObj; transaction.captureException(t) - .withOutcome(t != null ? Outcome.FAILURE : Outcome.SUCCESS) + .withOutcome(t != null ? DefaultOutcome.FAILURE : DefaultOutcome.SUCCESS) .deactivate() .end(); } diff --git a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/TimerTaskInstrumentation.java b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/TimerTaskInstrumentation.java index 440a10f25ea..028b5574430 100644 --- a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/TimerTaskInstrumentation.java +++ b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/main/java/co/elastic/apm/agent/scheduled/TimerTaskInstrumentation.java @@ -20,10 +20,10 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.bci.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.PrivilegedActionUtils; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; @@ -62,7 +62,7 @@ public static Object setTransactionName(@SimpleMethodSignatureOffsetMappingFacto @Advice.Origin Class clazz) { AbstractSpan active = tracer.getActive(); if (active == null) { - Transaction transaction = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(clazz)); + Transaction transaction = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(clazz)); if (transaction != null) { transaction.withName(signature) .withType("scheduled") @@ -79,8 +79,8 @@ public static Object setTransactionName(@SimpleMethodSignatureOffsetMappingFacto @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void onMethodExit(@Advice.Enter @Nullable Object transactionObj, @Advice.Thrown Throwable t) { - if (transactionObj instanceof Transaction) { - Transaction transaction = (Transaction) transactionObj; + if (transactionObj instanceof Transaction) { + Transaction transaction = (Transaction) transactionObj; transaction.captureException(t) .deactivate() .end(); diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JakartaAsyncInstrumentation.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JakartaAsyncInstrumentation.java index 4fead910dcd..5f36d290091 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JakartaAsyncInstrumentation.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JakartaAsyncInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.servlet; -import co.elastic.apm.agent.impl.GlobalTracer; +import co.elastic.apm.plugin.spi.GlobalTracer; import co.elastic.apm.agent.servlet.helper.AsyncContextAdviceHelper; import co.elastic.apm.agent.servlet.helper.JakartaAsyncContextAdviceHelper; import jakarta.servlet.AsyncContext; diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JakartaRequestStreamRecordingInstrumentation.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JakartaRequestStreamRecordingInstrumentation.java index 4eab1884f8f..a67cb3dea1f 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JakartaRequestStreamRecordingInstrumentation.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JakartaRequestStreamRecordingInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.servlet; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.state.CallDepth; import co.elastic.apm.agent.servlet.helper.JakartaRecordingServletInputStreamWrapper; import jakarta.servlet.ServletInputStream; @@ -54,7 +54,7 @@ public static ServletInputStream afterGetInputStream(@Advice.Return @Nullable Se if (callDepth.isNestedCallAndDecrement() || inputStream == null) { return inputStream; } - final Transaction transaction = tracer.currentTransaction(); + final Transaction transaction = tracer.currentTransaction(); // only wrap if the body buffer has been initialized via ServletTransactionHelper.startCaptureBody if (transaction != null && transaction.getContext().getRequest().getBodyBuffer() != null) { return new JakartaRecordingServletInputStreamWrapper(transaction.getContext().getRequest(), inputStream); diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JavaxAsyncInstrumentation.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JavaxAsyncInstrumentation.java index 3473ae22dc7..16554547707 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JavaxAsyncInstrumentation.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JavaxAsyncInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.servlet; -import co.elastic.apm.agent.impl.GlobalTracer; +import co.elastic.apm.plugin.spi.GlobalTracer; import co.elastic.apm.agent.servlet.helper.AsyncContextAdviceHelper; import co.elastic.apm.agent.servlet.helper.JavaxAsyncContextAdviceHelper; import javax.servlet.ServletRequest; diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JavaxRequestStreamRecordingInstrumentation.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JavaxRequestStreamRecordingInstrumentation.java index 2b85480420c..50ab2c1e697 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JavaxRequestStreamRecordingInstrumentation.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/JavaxRequestStreamRecordingInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.servlet; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.state.CallDepth; import co.elastic.apm.agent.servlet.helper.JavaxRecordingServletInputStreamWrapper; import net.bytebuddy.asm.Advice; @@ -54,7 +54,7 @@ public static ServletInputStream afterGetInputStream(@Advice.Return @Nullable Se if (callDepth.isNestedCallAndDecrement() || inputStream == null) { return inputStream; } - final Transaction transaction = tracer.currentTransaction(); + final Transaction transaction = tracer.currentTransaction(); // only wrap if the body buffer has been initialized via ServletTransactionHelper.startCaptureBody if (transaction != null && transaction.getContext().getRequest().getBodyBuffer() != null) { return new JavaxRecordingServletInputStreamWrapper(transaction.getContext().getRequest(), inputStream); 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 7233bbaec9c..38b8c6d384d 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 @@ -19,15 +19,7 @@ package co.elastic.apm.agent.servlet; import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Scope; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.sdk.state.GlobalVariables; import co.elastic.apm.agent.sdk.weakconcurrent.DetachedThreadLocal; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; @@ -40,15 +32,17 @@ import java.util.List; import java.util.Map; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_LOW_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_LOW_LEVEL_FRAMEWORK; import static co.elastic.apm.agent.servlet.ServletTransactionHelper.TRANSACTION_ATTRIBUTE; public abstract class ServletApiAdvice { private static final String FRAMEWORK_NAME = "Servlet API"; + + private static final Tracer tracer = GlobalTracer.get(); static final String SPAN_TYPE = "servlet"; static final String SPAN_SUBTYPE = "request-dispatcher"; - private static final ServletTransactionHelper servletTransactionHelper = new ServletTransactionHelper(GlobalTracer.requireTracerImpl()); + private static final ServletTransactionHelper servletTransactionHelper = new ServletTransactionHelper(GlobalTracer.get()); private static final DetachedThreadLocal excluded = GlobalVariables.get(ServletApiAdvice.class, "excluded", WeakConcurrent.buildThreadLocal()); private static final DetachedThreadLocal servletPathTL = GlobalVariables.get(ServletApiAdvice.class, "servletPath", WeakConcurrent.buildThreadLocal()); @@ -61,15 +55,13 @@ public static adapter, Object servletRequest) { - Tracer tracer = GlobalTracer.get(); - final HttpServletRequest httpServletRequest = adapter.asHttpServletRequest(servletRequest); if (httpServletRequest == null) { return null; } AbstractSpan ret = null; // re-activate transactions for async requests - final Transaction transactionAttr = (Transaction) adapter.getAttribute(httpServletRequest, TRANSACTION_ATTRIBUTE); + final Transaction transactionAttr = (Transaction) adapter.getAttribute(httpServletRequest, TRANSACTION_ATTRIBUTE); if (tracer.currentTransaction() == null && transactionAttr != null) { return transactionAttr.activateInScope(); } @@ -87,7 +79,7 @@ public static transaction = servletTransactionHelper.createAndActivateTransaction(adapter, adapter, httpServletRequest); if (transaction == null) { // if the httpServletRequest is excluded, avoid matching all exclude patterns again on each filter invocation @@ -164,15 +156,15 @@ public static transaction = null; Scope scope = null; - Span span = null; - if (transactionOrScopeOrSpan instanceof Transaction) { - transaction = (Transaction) transactionOrScopeOrSpan; + Span span = null; + if (transactionOrScopeOrSpan instanceof Transaction) { + transaction = (Transaction) transactionOrScopeOrSpan; } else if (transactionOrScopeOrSpan instanceof Scope) { scope = (Scope) transactionOrScopeOrSpan; - } else if (transactionOrScopeOrSpan instanceof Span) { - span = (Span) transactionOrScopeOrSpan; + } else if (transactionOrScopeOrSpan instanceof Span) { + span = (Span) transactionOrScopeOrSpan; } excluded.remove(); @@ -182,7 +174,7 @@ public static currentTransaction = tracer.currentTransaction(); if (currentTransaction != null) { TransactionNameUtils.setTransactionNameByServletClass(adapter.getMethod(httpServletRequest), thiz.getClass(), currentTransaction.getAndOverrideName(PRIO_LOW_LEVEL_FRAMEWORK)); @@ -261,7 +253,7 @@ public static Transaction createAndActivateTransaction( + public Transaction createAndActivateTransaction( ServletRequestAdapter requestAdapter, ServletContextAdapter contextAdapter, HttpServletRequest request) { @@ -83,14 +78,14 @@ public Transaction createAndActivateTransac return null; } ClassLoader cl = contextAdapter.getClassLoader(requestAdapter.getServletContext(request)); - Transaction transaction = tracer.startChildTransaction(request, requestAdapter.getRequestHeaderGetter(), cl); + Transaction transaction = tracer.startChildTransaction(request, requestAdapter.getRequestHeaderGetter(), cl); if (transaction != null) { transaction.activate(); } return transaction; } - public void fillRequestContext(Transaction transaction, String protocol, String method, boolean secure, + public void fillRequestContext(Transaction transaction, String protocol, String method, boolean secure, String scheme, String serverName, int serverPort, String requestURI, String queryString, String remoteAddr, @Nullable String contentTypeHeader) { @@ -114,7 +109,7 @@ public void fillRequestContext(Transaction transaction, String protocol, String } - private void startCaptureBody(Transaction transaction, String method, @Nullable String contentTypeHeader) { + private void startCaptureBody(Transaction transaction, String method, @Nullable String contentTypeHeader) { Request request = transaction.getContext().getRequest(); if (hasBody(contentTypeHeader, method)) { if (coreConfiguration.getCaptureBody() != OFF @@ -223,7 +218,7 @@ public String normalizeServletPath(String requestURI, @Nullable String contextPa return path; } - public void onAfter(Transaction transaction, @Nullable Throwable exception, boolean committed, int status, + public void onAfter(Transaction transaction, @Nullable Throwable exception, boolean committed, int status, boolean overrideStatusCodeOnThrowable, String method, @Nullable Map parameterMap, @Nullable String servletPath, @Nullable String pathInfo, @Nullable String contentTypeHeader, boolean deactivate) { try { @@ -244,7 +239,7 @@ public void onAfter(Transaction transaction, @Nullable Throwable exception, bool transaction.end(); } - private void doOnAfter(Transaction transaction, @Nullable Throwable exception, boolean committed, int status, + private void doOnAfter(Transaction transaction, @Nullable Throwable exception, boolean committed, int status, boolean overrideStatusCodeOnThrowable, String method, @Nullable Map parameterMap, String servletPath, @Nullable String pathInfo, @Nullable String contentTypeHeader) { fillRequestParameters(transaction, method, parameterMap, contentTypeHeader); @@ -259,7 +254,7 @@ private void doOnAfter(Transaction transaction, @Nullable Throwable exception, b applyDefaultTransactionName(method, servletPath, pathInfo, transaction); } - void applyDefaultTransactionName(String method, String servletPath, @Nullable String pathInfo, Transaction transaction) { + void applyDefaultTransactionName(String method, String servletPath, @Nullable String pathInfo, Transaction transaction) { // JSPs don't contain path params and the name is more telling than the generated servlet class if (webConfiguration.isUsePathAsName() || ENDS_WITH_JSP.matches(servletPath, pathInfo)) { // should override ServletName#doGet @@ -276,7 +271,7 @@ void applyDefaultTransactionName(String method, String servletPath, @Nullable St * for example when the amount of query parameters is longer than the application server allows. * In that case, we rather not want that the agent looks like the cause for this. */ - private void fillRequestParameters(Transaction transaction, String method, @Nullable Map parameterMap, @Nullable String contentTypeHeader) { + private void fillRequestParameters(Transaction transaction, String method, @Nullable Map parameterMap, @Nullable String contentTypeHeader) { Request request = transaction.getContext().getRequest(); if (hasBody(contentTypeHeader, method)) { if (coreConfiguration.getCaptureBody() != OFF && parameterMap != null) { diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/adapter/JakartaServletApiAdapter.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/adapter/JakartaServletApiAdapter.java index cf1aa47bab6..eb5af97852d 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/adapter/JakartaServletApiAdapter.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/adapter/JakartaServletApiAdapter.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.servlet.adapter; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.Request; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import co.elastic.apm.agent.servlet.helper.JakartaServletRequestHeaderGetter; import jakarta.servlet.DispatcherType; import jakarta.servlet.FilterConfig; diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/adapter/JavaxServletApiAdapter.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/adapter/JavaxServletApiAdapter.java index 05a5bda8c8c..229e2aff194 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/adapter/JavaxServletApiAdapter.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/adapter/JavaxServletApiAdapter.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.servlet.adapter; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.Request; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import co.elastic.apm.agent.servlet.helper.JavaxServletRequestHeaderGetter; import javax.annotation.Nullable; diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/adapter/ServletRequestAdapter.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/adapter/ServletRequestAdapter.java index a8d2f71fc5b..3babc50d578 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/adapter/ServletRequestAdapter.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/adapter/ServletRequestAdapter.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.servlet.adapter; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.Request; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import co.elastic.apm.agent.sdk.state.GlobalState; import javax.annotation.Nullable; diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/AbstractServletRequestHeaderGetter.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/AbstractServletRequestHeaderGetter.java index 73beb5cb7ea..3ef433a7f87 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/AbstractServletRequestHeaderGetter.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/AbstractServletRequestHeaderGetter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.servlet.helper; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import java.util.Enumeration; diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaApmAsyncListener.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaApmAsyncListener.java index a689a9a3eea..1b7972a8db4 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaApmAsyncListener.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaApmAsyncListener.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.servlet.helper; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Response; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.servlet.ServletTransactionHelper; @@ -57,7 +57,7 @@ public class JakartaApmAsyncListener implements AsyncListener, Recyclable { private final JakartaAsyncContextAdviceHelper asyncContextAdviceHelperImpl; private final ServletTransactionHelper servletTransactionHelper; @Nullable - private volatile Transaction transaction; + private volatile Transaction transaction; @Nullable private volatile Throwable throwable; @@ -66,7 +66,7 @@ public class JakartaApmAsyncListener implements AsyncListener, Recyclable { this.servletTransactionHelper = asyncContextAdviceHelperImpl.getServletTransactionHelper(); } - JakartaApmAsyncListener withTransaction(Transaction transaction) { + JakartaApmAsyncListener withTransaction(Transaction transaction) { this.transaction = transaction; return this; } diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaAsyncContextAdviceHelper.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaAsyncContextAdviceHelper.java index adca4c22714..cf4d7ca2efa 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaAsyncContextAdviceHelper.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaAsyncContextAdviceHelper.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.servlet.helper; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.objectpool.Allocator; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.plugin.spi.Allocator; +import co.elastic.apm.plugin.spi.ObjectPool; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.servlet.ServletTransactionHelper; import jakarta.servlet.AsyncContext; import jakarta.servlet.ServletRequest; @@ -62,7 +62,7 @@ public void onExitStartAsync(AsyncContext asyncContext) { if (request.getAttribute(ASYNC_LISTENER_ADDED) != null) { return; } - final Transaction transaction = tracer.currentTransaction(); + final Transaction transaction = tracer.currentTransaction(); if (transaction != null && transaction.isSampled() && request.getAttribute(ASYNC_LISTENER_ADDED) == null) { // makes sure that the listener is only added once, even if the request is wrapped // which leads to multiple invocations of startAsync for the same underlying request diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaRecordingServletInputStreamWrapper.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaRecordingServletInputStreamWrapper.java index cde1c51de9d..ced027c0024 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaRecordingServletInputStreamWrapper.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaRecordingServletInputStreamWrapper.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.servlet.helper; -import co.elastic.apm.agent.impl.context.Request; import co.elastic.apm.agent.util.IOUtils; +import co.elastic.apm.plugin.spi.Request; import jakarta.servlet.ReadListener; import jakarta.servlet.ServletInputStream; import java.io.IOException; diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaServletRequestHeaderGetter.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaServletRequestHeaderGetter.java index 69404eeea7d..94438d9dab0 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaServletRequestHeaderGetter.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JakartaServletRequestHeaderGetter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.servlet.helper; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import jakarta.servlet.http.HttpServletRequest; import java.util.Enumeration; diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxApmAsyncListener.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxApmAsyncListener.java index 4fc8d2e0770..01f869b78a2 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxApmAsyncListener.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxApmAsyncListener.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.servlet.helper; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Response; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.servlet.ServletTransactionHelper; @@ -57,7 +57,7 @@ public class JavaxApmAsyncListener implements AsyncListener, Recyclable { private final JavaxAsyncContextAdviceHelper asyncContextAdviceHelperImpl; private final ServletTransactionHelper servletTransactionHelper; @Nullable - private volatile Transaction transaction; + private volatile Transaction transaction; @Nullable private volatile Throwable throwable; @@ -66,7 +66,7 @@ public class JavaxApmAsyncListener implements AsyncListener, Recyclable { this.servletTransactionHelper = asyncContextAdviceHelperImpl.getServletTransactionHelper(); } - JavaxApmAsyncListener withTransaction(Transaction transaction) { + JavaxApmAsyncListener withTransaction(Transaction transaction) { this.transaction = transaction; return this; } diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxAsyncContextAdviceHelper.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxAsyncContextAdviceHelper.java index ee5add938e3..b14ff8c679d 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxAsyncContextAdviceHelper.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxAsyncContextAdviceHelper.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.servlet.helper; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.objectpool.Allocator; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.plugin.spi.Allocator; +import co.elastic.apm.plugin.spi.ObjectPool; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.servlet.ServletTransactionHelper; import javax.servlet.AsyncContext; @@ -62,7 +62,7 @@ public void onExitStartAsync(AsyncContext asyncContext) { if (request.getAttribute(ASYNC_LISTENER_ADDED) != null) { return; } - final Transaction transaction = tracer.currentTransaction(); + final Transaction transaction = tracer.currentTransaction(); if (transaction != null && transaction.isSampled() && request.getAttribute(ASYNC_LISTENER_ADDED) == null) { // makes sure that the listener is only added once, even if the request is wrapped // which leads to multiple invocations of startAsync for the same underlying request diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxRecordingServletInputStreamWrapper.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxRecordingServletInputStreamWrapper.java index e949f975588..f22cb0fbb91 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxRecordingServletInputStreamWrapper.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxRecordingServletInputStreamWrapper.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.servlet.helper; -import co.elastic.apm.agent.impl.context.Request; import co.elastic.apm.agent.util.IOUtils; +import co.elastic.apm.plugin.spi.Request; import javax.servlet.ReadListener; import javax.servlet.ServletInputStream; diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxServletRequestHeaderGetter.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxServletRequestHeaderGetter.java index 145e27a8d15..702f6872249 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxServletRequestHeaderGetter.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/helper/JavaxServletRequestHeaderGetter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.servlet.helper; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import javax.servlet.http.HttpServletRequest; import java.util.Enumeration; diff --git a/apm-agent-plugins/apm-sparkjava-plugin/src/main/java/co/elastic/apm/agent/sparkjava/RoutesAdvice.java b/apm-agent-plugins/apm-sparkjava-plugin/src/main/java/co/elastic/apm/agent/sparkjava/RoutesAdvice.java index cc385cd3b36..7343a1d8d9a 100644 --- a/apm-agent-plugins/apm-sparkjava-plugin/src/main/java/co/elastic/apm/agent/sparkjava/RoutesAdvice.java +++ b/apm-agent-plugins/apm-sparkjava-plugin/src/main/java/co/elastic/apm/agent/sparkjava/RoutesAdvice.java @@ -18,17 +18,17 @@ */ package co.elastic.apm.agent.sparkjava; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.impl.context.web.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.TransactionNameUtils; import co.elastic.apm.agent.util.VersionUtils; import net.bytebuddy.asm.Advice; import spark.Route; import spark.routematch.RouteMatch; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_LOW_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_LOW_LEVEL_FRAMEWORK; public class RoutesAdvice { @@ -36,7 +36,7 @@ public class RoutesAdvice { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void onExitFind(@Advice.Return RouteMatch routeMatch) { - Transaction transaction = tracer.currentTransaction(); + Transaction transaction = tracer.currentTransaction(); if (transaction == null || routeMatch == null) { return; } diff --git a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/main/java/co/elastic/apm/agent/resttemplate/SpringRestRequestHeaderSetter.java b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/main/java/co/elastic/apm/agent/resttemplate/SpringRestRequestHeaderSetter.java index 40d428371ac..888bab065e5 100644 --- a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/main/java/co/elastic/apm/agent/resttemplate/SpringRestRequestHeaderSetter.java +++ b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/main/java/co/elastic/apm/agent/resttemplate/SpringRestRequestHeaderSetter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.resttemplate; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import org.springframework.http.HttpRequest; public class SpringRestRequestHeaderSetter implements TextHeaderSetter { diff --git a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/main/java/co/elastic/apm/agent/resttemplate/SpringRestTemplateAdvice.java b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/main/java/co/elastic/apm/agent/resttemplate/SpringRestTemplateAdvice.java index 15bdde6228e..e7116f3af71 100644 --- a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/main/java/co/elastic/apm/agent/resttemplate/SpringRestTemplateAdvice.java +++ b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/main/java/co/elastic/apm/agent/resttemplate/SpringRestTemplateAdvice.java @@ -20,9 +20,9 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.DefaultOutcome; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -48,7 +48,7 @@ public static Object beforeExecute(@Advice.This ClientHttpRequest request) { return null; } URI uri = request.getURI(); - Span span = HttpClientHelper.startHttpClientSpan(parent, Objects.toString(request.getMethod()), uri, uri.getHost()); + Span span = HttpClientHelper.startHttpClientSpan(parent, Objects.toString(request.getMethod()), uri, uri.getHost()); if (span != null) { span.activate(); span.propagateTraceContext(request, SpringRestRequestHeaderSetter.INSTANCE); @@ -63,15 +63,15 @@ public static void afterExecute(@Advice.Return @Nullable ClientHttpResponse clie @Advice.Enter @Nullable Object spanObj, @Advice.Thrown @Nullable Throwable t) throws IOException { logger.trace("Exit advice for RestTemplate client execute() method, span object: {}", spanObj); - if (spanObj instanceof Span) { - Span span = (Span) spanObj; + if (spanObj instanceof Span) { + Span span = (Span) spanObj; try { if (clientHttpResponse != null) { // getRawStatusCode has been introduced in 3.1.1 span.getContext().getHttp().withStatusCode(clientHttpResponse.getRawStatusCode()); } if (t != null) { - span.withOutcome(Outcome.FAILURE); + span.withOutcome(DefaultOutcome.FAILURE); } span.captureException(t); } finally { diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientExchangeFunctionInstrumentation.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientExchangeFunctionInstrumentation.java index caea36a19f6..585426f4f7a 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientExchangeFunctionInstrumentation.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientExchangeFunctionInstrumentation.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument; import net.bytebuddy.description.NamedElement; @@ -80,7 +80,7 @@ public static Object[] onBefore(@Advice.Argument(0) ClientRequest clientRequest) } ClientRequest.Builder builder = ClientRequest.from(clientRequest); URI uri = clientRequest.url(); - Span span = HttpClientHelper.startHttpClientSpan(parent, clientRequest.method().name(), uri, uri.getHost()); + Span span = HttpClientHelper.startHttpClientSpan(parent, clientRequest.method().name(), uri, uri.getHost()); if (span != null) { span.activate(); span.propagateTraceContext(builder, WebClientRequestHeaderSetter.INSTANCE); @@ -101,10 +101,10 @@ public static Object afterExecute(@Advice.Return @Nullable Publisher returnVa return returnValue; } Object spanObj = spanRequestObj[1]; - if (!(spanObj instanceof Span)) { + if (!(spanObj instanceof Span)) { return returnValue; } - Span span = (Span) spanObj; + Span span = (Span) spanObj; span = span.captureException(t).deactivate(); if (t != null || returnValue == null) { return returnValue; diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientHelper.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientHelper.java index edc81b9cf6c..13159dc4627 100755 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientHelper.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientHelper.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.springwebclient; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Span; import org.reactivestreams.Publisher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,7 +35,7 @@ public class WebClientHelper { private static final Logger log = LoggerFactory.getLogger(WebClientHelper.class); - public static Publisher wrapSubscriber(Publisher publisher, final Span span, final Tracer tracer) { + public static Publisher wrapSubscriber(Publisher publisher, final Span span, final Tracer tracer) { Function, ? extends Publisher> lift = Operators.liftPublisher( new BiFunction, CoreSubscriber>() { diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientRequestHeaderSetter.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientRequestHeaderSetter.java index b6fe9c5e526..eddb98bd5fb 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientRequestHeaderSetter.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientRequestHeaderSetter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.springwebclient; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import org.springframework.web.reactive.function.client.ClientRequest; public class WebClientRequestHeaderSetter implements TextHeaderSetter { diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientSubscriber.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientSubscriber.java index 4766f09b522..93668178339 100755 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientSubscriber.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientSubscriber.java @@ -19,10 +19,9 @@ package co.elastic.apm.agent.springwebclient; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.context.web.ResultUtil; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.ResultUtil; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Span; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import org.reactivestreams.Subscription; import org.slf4j.Logger; @@ -36,13 +35,13 @@ public class WebClientSubscriber implements CoreSubscriber, Subscription { private static final Logger logger = LoggerFactory.getLogger(WebClientSubscriber.class); - private static final WeakMap, Span> spanMap = WeakConcurrentProviderImpl.createWeakSpanMap(); + private static final WeakMap, Span> spanMap = WeakConcurrentProviderImpl.createWeakSpanMap(); private final Tracer tracer; private final CoreSubscriber subscriber; private Subscription subscription; - public WebClientSubscriber(CoreSubscriber subscriber, Span span, Tracer tracer) { + public WebClientSubscriber(CoreSubscriber subscriber, Span span, Tracer tracer) { this.subscriber = subscriber; this.tracer = tracer; @@ -52,7 +51,7 @@ public WebClientSubscriber(CoreSubscriber subscriber, Span span, Trac @Override public void onSubscribe(Subscription s) { this.subscription = s; - Span span = getSpan(); + Span span = getSpan(); boolean hasActivated = doEnter("onSubscribe", span); Throwable thrown = null; @@ -69,7 +68,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { - final Span span = getSpan(); + final Span span = getSpan(); boolean hasActivated = doEnter("onNext", span); Throwable thrown = null; try { @@ -91,7 +90,7 @@ public void onNext(T t) { @Override public void onError(Throwable throwable) { - Span span = getSpan(); + Span span = getSpan(); boolean hasActivated = doEnter("onError", span); try { subscriber.onError(throwable); @@ -104,7 +103,7 @@ public void onError(Throwable throwable) { @Override public void onComplete() { - final Span span = getSpan(); + final Span span = getSpan(); boolean hasActivated = doEnter("onComplete", span); try { subscriber.onComplete(); @@ -127,7 +126,7 @@ public void cancel() { } @Nullable - private Span getSpan() { + private Span getSpan() { return spanMap.get(this); } @@ -139,7 +138,7 @@ private void discardIf(boolean condition) { spanMap.remove(this); } - private boolean doEnter(String method, @Nullable Span span) { + private boolean doEnter(String method, @Nullable Span span) { debugTrace(true, method, span); if (span == null || tracer.getActive() == span) { @@ -151,7 +150,7 @@ private boolean doEnter(String method, @Nullable Span span) { return true; } - private void doExit(boolean deactivate, String method, @Nullable Span span) { + private void doExit(boolean deactivate, String method, @Nullable Span span) { debugTrace(false, method, span); if (span == null || !deactivate) { @@ -166,14 +165,14 @@ private void doExit(boolean deactivate, String method, @Nullable Span span) { span.deactivate(); } - private void debugTrace(boolean isEnter, String method, @Nullable Span span) { + private void debugTrace(boolean isEnter, String method, @Nullable Span span) { if (!logger.isTraceEnabled()) { return; } logger.trace("{} webclient {} {}", isEnter ? ">>" : "<<", method, span); } - private void endSpan(@Nullable Throwable thrown, @Nullable Span span) { + private void endSpan(@Nullable Throwable thrown, @Nullable Span span) { if (span == null) { // already discarded return; @@ -182,7 +181,7 @@ private void endSpan(@Nullable Throwable thrown, @Nullable Span span) { } private void cancelSpan() { - Span span = getSpan(); + Span span = getSpan(); debugTrace(true, "cancelSpan", span); try { if (span != null) { diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/BodyInsertersInstrumentation.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/BodyInsertersInstrumentation.java index 8aaef23baf0..3f7cbaf4565 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/BodyInsertersInstrumentation.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/BodyInsertersInstrumentation.java @@ -18,8 +18,7 @@ */ package co.elastic.apm.agent.springwebflux; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -87,7 +86,7 @@ public static void onEnter(@Advice.Argument(1) @Nullable Object arg) { } if (type.getType().getTypeName().equals(WebfluxHelper.SSE_EVENT_CLASS)) { - Transaction transaction = GlobalTracer.get().currentTransaction(); + Transaction transaction = tracer.currentTransaction(); if (transaction != null) { // mark the transaction to be ignored and later discarded transaction.ignoreTransaction(); diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/DispatcherHandlerInstrumentation.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/DispatcherHandlerInstrumentation.java index 15edbfa17cc..e8ed5c1fc19 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/DispatcherHandlerInstrumentation.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/DispatcherHandlerInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.springwebflux; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -77,10 +77,10 @@ public static Object onExit(@Advice.Enter @Nullable Object enterTransaction, @Advice.Thrown @Nullable Throwable thrown, @Advice.Return @Nullable Mono returnValue) { - if (!(enterTransaction instanceof Transaction)) { + if (!(enterTransaction instanceof Transaction)) { return returnValue; } - Transaction transaction = (Transaction) enterTransaction; + Transaction transaction = (Transaction) enterTransaction; transaction.deactivate(); if (thrown != null || returnValue == null) { diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/HandlerAdapterInstrumentation.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/HandlerAdapterInstrumentation.java index dc0fd27100d..049b6dd487d 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/HandlerAdapterInstrumentation.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/HandlerAdapterInstrumentation.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.springwebflux; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.TransactionNameUtils; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; @@ -82,7 +82,7 @@ public static Object onEnter(@Advice.Argument(0) ServerWebExchange exchange, TransactionNameUtils.setNameFromClassAndMethod( handlerMethod.getBeanType().getSimpleName(), handlerMethod.getMethod().getName(), - ((Transaction) exchangeTransaction).getAndOverrideName(AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK, false)); + ((Transaction) exchangeTransaction).getAndOverrideName(AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK, false)); } @@ -97,11 +97,11 @@ public static Mono onExit(@Advice.Argument(0) ServerWebExchange e @Advice.Enter @Nullable Object enterTransaction, @Advice.Return @Nullable Mono resultMono) { - if (!(enterTransaction instanceof Transaction) || resultMono == null) { + if (!(enterTransaction instanceof Transaction) || resultMono == null) { return resultMono; } - Transaction transaction = (Transaction) enterTransaction; + Transaction transaction = (Transaction) enterTransaction; transaction.captureException(thrown); if (transaction.isNoop()) { diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/HeaderGetter.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/HeaderGetter.java index 0fbd13d169d..994dfeddcfa 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/HeaderGetter.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/HeaderGetter.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.springwebflux; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; import org.springframework.http.HttpHeaders; import javax.annotation.Nullable; diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/TransactionAwareSubscriber.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/TransactionAwareSubscriber.java index bbe25568d16..4b5db98f456 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/TransactionAwareSubscriber.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/TransactionAwareSubscriber.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.springwebflux; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -41,7 +41,7 @@ class TransactionAwareSubscriber implements CoreSubscriber, Subscription { private static final Logger log = LoggerFactory.getLogger(TransactionAwareSubscriber.class); - private static final WeakMap, Transaction> transactionMap = WeakConcurrentProviderImpl.createWeakSpanMap(); + private static final WeakMap, Transaction> transactionMap = WeakConcurrentProviderImpl.createWeakSpanMap(); private final CoreSubscriber subscriber; @@ -60,7 +60,7 @@ class TransactionAwareSubscriber implements CoreSubscriber, Subscription { * @param description human-readable description to make debugging easier */ TransactionAwareSubscriber(CoreSubscriber subscriber, - Transaction transaction, + Transaction transaction, ServerWebExchange exchange, String description) { @@ -99,7 +99,7 @@ public void cancel() { @Override public void onSubscribe(Subscription s) { this.subscription = s; - Transaction transaction = getTransaction(); + Transaction transaction = getTransaction(); doEnter("onSubscribe", transaction); Throwable thrown = null; try { @@ -120,7 +120,7 @@ public void onSubscribe(Subscription s) { */ @Override public void onNext(T next) { - Transaction transaction = getTransaction(); + Transaction transaction = getTransaction(); doEnter("onNext", transaction); Throwable thrown = null; try { @@ -142,7 +142,7 @@ public void onNext(T next) { */ @Override public void onError(Throwable t) { - Transaction transaction = getTransaction(); + Transaction transaction = getTransaction(); doEnter("onError", transaction); try { @@ -164,7 +164,7 @@ public void onError(Throwable t) { */ @Override public void onComplete() { - Transaction transaction = getTransaction(); + Transaction transaction = getTransaction(); doEnter("onComplete", transaction); try { @@ -179,7 +179,7 @@ public void onComplete() { } } - private void doEnter(String method, @Nullable Transaction transaction) { + private void doEnter(String method, @Nullable Transaction transaction) { debugTrace(true, method, transaction); if (transaction == null) { @@ -189,7 +189,7 @@ private void doEnter(String method, @Nullable Transaction transaction) { transaction.activate(); } - private void doExit(boolean discard, String method, @Nullable Transaction transaction) { + private void doExit(boolean discard, String method, @Nullable Transaction transaction) { debugTrace(false, method, transaction); if (transaction == null) { @@ -203,7 +203,7 @@ private void doExit(boolean discard, String method, @Nullable Transaction transa } private void cancelTransaction() { - Transaction transaction = getTransaction(); + Transaction transaction = getTransaction(); debugTrace(true, "cancelTransaction", transaction); try { if (transaction == null) { @@ -220,11 +220,11 @@ private void cancelTransaction() { } @Nullable - private Transaction getTransaction() { + private Transaction getTransaction() { return transactionMap.get(this); } - private void debugTrace(boolean isEnter, String method, @Nullable Transaction transaction) { + private void debugTrace(boolean isEnter, String method, @Nullable Transaction transaction) { if (!log.isTraceEnabled()) { return; } diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java index fc558dd833a..a0f98874eb8 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxHelper.java @@ -20,19 +20,13 @@ import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.httpserver.HttpServerHelper; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.context.web.ResultUtil; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.impl.context.web.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import co.elastic.apm.agent.util.LoggerUtils; -import co.elastic.apm.agent.util.PotentiallyMultiValuedMap; import co.elastic.apm.agent.util.PrivilegedActionUtils; import co.elastic.apm.agent.util.TransactionNameUtils; import org.reactivestreams.Publisher; @@ -57,8 +51,8 @@ import java.util.Map; import java.util.function.BiFunction; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_LOW_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_LOW_LEVEL_FRAMEWORK; import static org.springframework.web.reactive.function.server.RouterFunctions.MATCHING_PATTERN_ATTRIBUTE; public class WebfluxHelper { @@ -81,17 +75,17 @@ public class WebfluxHelper { private static final WeakMap ignoredHandlerMethods = WeakConcurrent.buildMap(); static { - - coreConfig = GlobalTracer.get().getConfig(CoreConfiguration.class); - webConfig = GlobalTracer.get().getConfig(WebConfiguration.class); + Tracer tracer = GlobalTracer.get(); + coreConfig = tracer.getConfig(CoreConfiguration.class); + webConfig = tracer.getConfig(WebConfiguration.class); serverHelper = new HttpServerHelper(webConfig); } @Nullable - public static Transaction getOrCreateTransaction(Tracer tracer, ServerWebExchange exchange) { + public static Transaction getOrCreateTransaction(Tracer tracer, ServerWebExchange exchange) { - Transaction transaction = WebfluxServletHelper.getServletTransaction(exchange); + Transaction transaction = WebfluxServletHelper.getServletTransaction(exchange); boolean fromServlet = transaction != null; String path = exchange.getRequest().getPath().value(); @@ -118,11 +112,11 @@ public static boolean isServletTransaction(ServerWebExchange exchange) { return Boolean.TRUE == exchange.getAttributes().get(SERVLET_TRANSACTION); } - public static Mono wrapDispatcher(Mono mono, Transaction transaction, ServerWebExchange exchange) { + public static Mono wrapDispatcher(Mono mono, Transaction transaction, ServerWebExchange exchange) { return doWrap(mono, transaction, exchange, "webflux-dispatcher"); } - private static Mono doWrap(Mono mono, final Transaction transaction, final ServerWebExchange exchange, final String description) { + private static Mono doWrap(Mono mono, final Transaction transaction, final ServerWebExchange exchange, final String description) { //noinspection Convert2Lambda,rawtypes,Convert2Diamond mono = mono.transform(Operators.liftPublisher(new BiFunction, CoreSubscriber>() { @Override // liftPublisher too (or whole transform param) @@ -146,7 +140,7 @@ public CoreSubscriber apply(Publisher publisher, CoreSubscriber transaction, ServerWebExchange exchange) { if (transaction == null) { // already discarded return; @@ -180,7 +174,7 @@ public static void endTransaction(@Nullable Throwable thrown, @Nullable Transact } } - public static void setTransactionName(@Nullable Transaction transaction, ServerWebExchange exchange) { + public static void setTransactionName(@Nullable Transaction transaction, ServerWebExchange exchange) { if (transaction == null) { return; } @@ -248,7 +242,7 @@ private static boolean ignoreTransaction(ServerWebExchange exchange) { return false; } - private static void fillRequest(Transaction transaction, ServerWebExchange exchange) { + private static void fillRequest(Transaction transaction, ServerWebExchange exchange) { ServerHttpRequest serverRequest = exchange.getRequest(); Request request = transaction.getContext().getRequest(); @@ -269,7 +263,7 @@ private static void fillRequest(Transaction transaction, ServerWebExchange excha } - private static void fillResponse(Transaction transaction, ServerWebExchange exchange) { + private static void fillResponse(Transaction transaction, ServerWebExchange exchange) { ServerHttpResponse serverResponse = exchange.getResponse(); int status = 0; try { diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxServletHelper.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxServletHelper.java index e114262d70d..0beb0d18e84 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxServletHelper.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/src/main/java/co/elastic/apm/agent/springwebflux/WebfluxServletHelper.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.springwebflux; import co.elastic.apm.agent.cache.WeakKeySoftValueLoadingCache; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import org.springframework.http.server.reactive.AbstractServerHttpRequest; @@ -55,20 +55,20 @@ public MethodHandle get(Class klass) { }); @Nullable - public static Transaction getServletTransaction(ServerWebExchange exchange) { + public static Transaction getServletTransaction(ServerWebExchange exchange) { // see ServletHttpHandlerAdapter and sub-classes for implementation details // While the active transaction is the one created by Servlet, it would rely on the fact that we are on the // same thread as the one that created the transaction, which is an implementation detail. - Transaction transaction = null; + Transaction transaction = null; ServerHttpRequest exchangeRequest = exchange.getRequest(); if (exchangeRequest instanceof AbstractServerHttpRequest) { Object nativeRequest = ((AbstractServerHttpRequest) exchangeRequest).getNativeRequest(); // note: attribute name is defined in Servlet plugin and should be kept in sync - transaction = (Transaction) getServletAttribute(nativeRequest, "co.elastic.apm.agent.servlet.ServletApiAdvice.transaction"); + transaction = (Transaction) getServletAttribute(nativeRequest, "co.elastic.apm.agent.servlet.ServletApiAdvice.transaction"); } diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingAnnotated.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingAnnotated.java index 16af97bf522..1e3469f0018 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingAnnotated.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingAnnotated.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.springwebflux.testapp; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -172,7 +172,7 @@ public Mono customTransactionName() { // In practice, it's called after onSubscribe and before onNext, thus the active context is not provided // by reactor plugin, but only by the webflux plugin that keeps the transaction active. Tracer tracer = GlobalTracer.get(); - Transaction transaction = Objects.requireNonNull(tracer.currentTransaction(), "active transaction is required"); + Transaction transaction = Objects.requireNonNull(tracer.currentTransaction(), "active transaction is required"); // This mimics setting the name through the public API. We cannot use the public API if we want to test span recycling transaction.withName("user-provided-name", AbstractSpan.PRIO_USER_SUPPLIED); diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingFunctional.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingFunctional.java index 15517938eed..8bde7d8314d 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingFunctional.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingFunctional.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.springwebflux.testapp; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Transaction; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; @@ -82,7 +82,7 @@ public RouterFunction route(GreetingHandler greetingHandler) { // custom transaction name set through API .GET("/functional/custom-transaction-name", accept(MediaType.TEXT_PLAIN), request -> { Tracer tracer = GlobalTracer.get(); - Transaction transaction = Objects.requireNonNull(tracer.currentTransaction(), "active transaction is required"); + Transaction transaction = Objects.requireNonNull(tracer.currentTransaction(), "active transaction is required"); // This mimics setting the name through the public API. We cannot use the public API if we want to test span recycling transaction.withName("user-provided-name", AbstractSpan.PRIO_USER_SUPPLIED); return response(greetingHandler.helloMessage("transaction=" + Objects.requireNonNull(tracer.currentTransaction()).getTraceContext().getId())); diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingHandler.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingHandler.java index 33c2c258f62..516eed07334 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingHandler.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingHandler.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.springwebflux.testapp; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Span; import org.springframework.http.codec.ServerSentEvent; import org.springframework.security.core.context.ReactiveSecurityContextHolder; import org.springframework.stereotype.Component; @@ -73,7 +73,7 @@ public Flux childSpans(int count, long delayMillis, long durationMillis) .delayElements(Duration.ofMillis(delayMillis)) .map(i -> String.format("child %d", i)) .doOnNext(name -> { - Span span = Objects.requireNonNull(GlobalTracer.get().currentTransaction()).createSpan(); + Span span = Objects.requireNonNull(GlobalTracer.get().currentTransaction()).createSpan(); span.withName(String.format("%s id=%s", name, span.getTraceContext().getId())); try { fakeWork(durationMillis); diff --git a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/ServletWrappingControllerTransactionNameInstrumentation.java b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/ServletWrappingControllerTransactionNameInstrumentation.java index 013a45ced31..3099b816677 100644 --- a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/ServletWrappingControllerTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/ServletWrappingControllerTransactionNameInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.springwebmvc; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.TransactionNameUtils; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; @@ -30,7 +30,7 @@ import java.util.Collection; import java.util.Collections; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; import static net.bytebuddy.matcher.ElementMatchers.named; /** @@ -57,7 +57,7 @@ public Collection getInstrumentationGroupNames() { public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void onEnter(@Advice.FieldValue("servletClass") Class servletClass, @Advice.Argument(0) HttpServletRequest request) { - final Transaction transaction = tracer.currentTransaction(); + final Transaction transaction = tracer.currentTransaction(); if (transaction == null) { return; } diff --git a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringServiceNameInstrumentation.java b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringServiceNameInstrumentation.java index f2e01c2887c..76f684d0f4c 100644 --- a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringServiceNameInstrumentation.java +++ b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringServiceNameInstrumentation.java @@ -19,10 +19,9 @@ package co.elastic.apm.agent.springwebmvc; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.configuration.ServiceInfo; +import co.elastic.apm.plugin.spi.ServiceInfo; import co.elastic.apm.agent.servlet.ServletServiceNameHelper; import co.elastic.apm.agent.servlet.adapter.JavaxServletApiAdapter; -import co.elastic.apm.agent.servlet.adapter.ServletApiAdapter; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -74,7 +73,7 @@ public static class SpringServiceNameAdvice { public static void afterInitPropertySources(@Advice.This WebApplicationContext applicationContext) { // avoid having two service names for a standalone jar // one based on Implementation-Title and one based on spring.application.name - if (!ServiceInfo.autoDetected().isMultiServiceContainer()) { + if (!tracer.autoDetectedServiceName().isMultiServiceContainer()) { return; } diff --git a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringTransactionNameInstrumentation.java b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringTransactionNameInstrumentation.java index f249f184a8b..876a9bced88 100644 --- a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringTransactionNameInstrumentation.java +++ b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringTransactionNameInstrumentation.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.springwebmvc; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.GlobalTracer; +import co.elastic.apm.plugin.spi.GlobalTracer; import co.elastic.apm.agent.impl.context.web.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.TransactionNameUtils; import co.elastic.apm.agent.util.VersionUtils; import net.bytebuddy.asm.Advice; @@ -35,8 +35,8 @@ import java.util.Collections; import static co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_LOW_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_LOW_LEVEL_FRAMEWORK; import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; import static net.bytebuddy.matcher.ElementMatchers.isInterface; import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith; @@ -107,7 +107,7 @@ public static class HandlerAdapterAdvice { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setTransactionName(@Advice.Argument(0) HttpServletRequest request, @Advice.Argument(2) Object handler) { - final Transaction transaction = tracer.currentTransaction(); + final Transaction transaction = tracer.currentTransaction(); if (transaction == null) { return; } diff --git a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/ViewRenderInstrumentation.java b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/ViewRenderInstrumentation.java index 63d11decfa3..ba7492f4393 100644 --- a/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/ViewRenderInstrumentation.java +++ b/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/ViewRenderInstrumentation.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.springwebmvc; import co.elastic.apm.agent.bci.TracerAwareInstrumentation; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -29,7 +29,6 @@ import org.springframework.web.servlet.view.AbstractView; import javax.annotation.Nullable; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -63,7 +62,7 @@ public static Object beforeExecute(@Advice.This Object thiz) { final AbstractSpan parent = tracer.getActive(); String className = thiz.getClass().getName(); - Span span = parent.createSpan() + Span span = parent.createSpan() .withType(SPAN_TYPE) .withSubtype(getSubtype(className)) .withAction(SPAN_ACTION) @@ -83,8 +82,8 @@ public static Object beforeExecute(@Advice.This Object thiz) { @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void afterExecute(@Advice.Enter @Nullable Object spanObj, @Advice.Thrown @Nullable Throwable t) { - if (spanObj instanceof Span) { - Span span = (Span) spanObj; + if (spanObj instanceof Span) { + Span span = (Span) spanObj; span.captureException(t) .deactivate() .end(); diff --git a/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ActionProxyAdvice.java b/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ActionProxyAdvice.java index 7cab058f367..06c4baffe94 100644 --- a/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ActionProxyAdvice.java +++ b/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ActionProxyAdvice.java @@ -18,24 +18,23 @@ */ package co.elastic.apm.agent.struts; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.util.TransactionNameUtils; +import co.elastic.apm.plugin.spi.*; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionProxy; import net.bytebuddy.asm.Advice; import javax.annotation.Nullable; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; public class ActionProxyAdvice { + private static final Tracer tracer = GlobalTracer.get(); + @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object onEnterExecute(@Advice.This ActionProxy actionProxy) { - Transaction transaction = GlobalTracer.get().currentTransaction(); + Transaction transaction = tracer.currentTransaction(); if (transaction == null) { return null; } @@ -43,7 +42,7 @@ public static Object onEnterExecute(@Advice.This ActionProxy actionProxy) { String className = actionProxy.getAction().getClass().getSimpleName(); String methodName = actionProxy.getMethod(); if (ActionContext.getContext().get("CHAIN_HISTORY") != null) { - Span span = transaction.createSpan().withType("app").withSubtype("internal"); + Span span = transaction.createSpan().withType("app").withSubtype("internal"); TransactionNameUtils.setNameFromClassAndMethod(className, methodName, span.getAndOverrideName(PRIO_HIGH_LEVEL_FRAMEWORK)); return span.activate(); } else { @@ -60,12 +59,12 @@ public static void onExitExecute(@Advice.Enter @Nullable Object spanOrNull, return; } - Span span = (Span) spanOrNull; + Span span = (Span) spanOrNull; try { if (t != null) { - span.captureException(t).withOutcome(Outcome.FAILURE); + span.captureException(t).withOutcome(DefaultOutcome.FAILURE); } else { - span.withOutcome(Outcome.SUCCESS); + span.withOutcome(DefaultOutcome.SUCCESS); } } finally { span.deactivate().end(); diff --git a/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ExecuteOperationsAdvice.java b/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ExecuteOperationsAdvice.java index f06fbf7c935..29cd3a0823c 100644 --- a/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ExecuteOperationsAdvice.java +++ b/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ExecuteOperationsAdvice.java @@ -18,15 +18,15 @@ */ package co.elastic.apm.agent.struts; -import co.elastic.apm.agent.impl.GlobalTracer; +import co.elastic.apm.plugin.spi.GlobalTracer; import co.elastic.apm.agent.impl.context.web.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.TransactionNameUtils; import net.bytebuddy.asm.Advice; import javax.servlet.http.HttpServletRequest; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_HIGH_LEVEL_FRAMEWORK; public class ExecuteOperationsAdvice { @@ -34,7 +34,7 @@ public class ExecuteOperationsAdvice { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void setTransactionName(@Advice.Argument(0) HttpServletRequest request, @Advice.Return boolean handled) { - Transaction transaction = GlobalTracer.get().currentTransaction(); + Transaction transaction = GlobalTracer.get().currentTransaction(); if (!handled || transaction == null) { return; } diff --git a/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/StrutsFrameworkUtils.java b/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/StrutsFrameworkUtils.java index 12ee4223fb9..c3a90c00598 100644 --- a/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/StrutsFrameworkUtils.java +++ b/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/StrutsFrameworkUtils.java @@ -18,13 +18,13 @@ */ package co.elastic.apm.agent.struts; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.util.VersionUtils; import com.opensymphony.xwork2.ActionProxy; public class StrutsFrameworkUtils { - public static void setFrameworkNameAndVersion(Transaction transaction) { + public static void setFrameworkNameAndVersion(Transaction transaction) { transaction.setFrameworkName("Struts"); transaction.setFrameworkVersion(VersionUtils.getVersion(ActionProxy.class, "org.apache.struts", "struts2-core")); } 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 5a7c9c69d73..a4485b4ed72 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 @@ -21,10 +21,7 @@ import co.elastic.apm.agent.bci.TracerAwareInstrumentation; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.sdk.state.CallDepth; import co.elastic.apm.agent.sdk.state.GlobalState; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; @@ -50,7 +47,7 @@ @GlobalState public abstract class HttpUrlConnectionInstrumentation extends TracerAwareInstrumentation { - public static final WeakMap inFlightSpans = WeakConcurrentProviderImpl.createWeakSpanMap(); + public static final WeakMap> inFlightSpans = WeakConcurrentProviderImpl.createWeakSpanMap(); public static final CallDepth callDepth = CallDepth.get(HttpUrlConnectionInstrumentation.class); @Override @@ -82,11 +79,11 @@ public static Object enter(@Advice.This HttpURLConnection thiz, if (parent == null) { return null; } - Span span = inFlightSpans.get(thiz); + Span span = inFlightSpans.get(thiz); if (span == null && !connected) { final URL url = thiz.getURL(); span = HttpClientHelper.startHttpClientSpan(parent, thiz.getRequestMethod(), url.toString(), url.getProtocol(), url.getHost(), url.getPort()); - if (!TraceContext.containsTraceContextTextHeaders(thiz, UrlConnectionPropertyAccessor.instance())) { + if (!TraceContextUtil.containsTraceContextTextHeaders(thiz, UrlConnectionPropertyAccessor.instance())) { if (span != null) { span.propagateTraceContext(thiz, UrlConnectionPropertyAccessor.instance()); } else { @@ -109,7 +106,7 @@ public static void exit(@Advice.This HttpURLConnection thiz, @Advice.Origin String signature) { callDepth.decrement(); - Span span = (Span) spanObject; + Span span = (Span) spanObject; if (span == null) { return; } @@ -130,7 +127,7 @@ public static void exit(@Advice.This HttpURLConnection thiz, // checking if "finished" to avoid multiple endings on nested calls if (!span.isFinished()) { span.captureException(t) - .withOutcome(Outcome.FAILURE) + .withOutcome(DefaultOutcome.FAILURE) .end(); } } else { @@ -164,10 +161,10 @@ public static class AdviceClass { public static void afterDisconnect(@Advice.This HttpURLConnection thiz, @Advice.Thrown @Nullable Throwable t, @Advice.FieldValue("responseCode") int responseCode) { - Span span = inFlightSpans.remove(thiz); + Span span = inFlightSpans.remove(thiz); if (span != null) { span.captureException(t) - .withOutcome(t != null ? Outcome.FAILURE : Outcome.SUCCESS) + .withOutcome(t != null ? DefaultOutcome.FAILURE : DefaultOutcome.SUCCESS) .end(); } } diff --git a/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/UrlConnectionPropertyAccessor.java b/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/UrlConnectionPropertyAccessor.java index 16ce3bbd74b..d983e5cb8ab 100644 --- a/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/UrlConnectionPropertyAccessor.java +++ b/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/UrlConnectionPropertyAccessor.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.urlconnection; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractHttpTransactionHelper.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractHttpTransactionHelper.java index ad92d70829b..33d97d4d48f 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractHttpTransactionHelper.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractHttpTransactionHelper.java @@ -20,11 +20,11 @@ import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.httpserver.HttpServerHelper; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Response; +import co.elastic.apm.plugin.spi.Request; +import co.elastic.apm.plugin.spi.Response; +import co.elastic.apm.plugin.spi.Tracer; import co.elastic.apm.agent.impl.context.web.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.util.TransactionNameUtils; import co.elastic.apm.agent.sdk.logging.Logger; @@ -37,8 +37,8 @@ import java.util.Set; import static co.elastic.apm.agent.configuration.CoreConfiguration.EventType.OFF; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_DEFAULT; -import static co.elastic.apm.agent.impl.transaction.AbstractSpan.PRIO_LOW_LEVEL_FRAMEWORK; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_DEFAULT; +import static co.elastic.apm.plugin.spi.AbstractSpan.PRIO_LOW_LEVEL_FRAMEWORK; public abstract class AbstractHttpTransactionHelper { private static final Logger logger = LoggerFactory.getLogger(AbstractHttpTransactionHelper.class); @@ -64,7 +64,7 @@ protected AbstractHttpTransactionHelper(Tracer tracer) { this.serverHelper = new HttpServerHelper(webConfiguration); } - protected void startCaptureBody(Transaction transaction, String method, @Nullable String contentTypeHeader) { + protected void startCaptureBody(Transaction transaction, String method, @Nullable String contentTypeHeader) { Request request = transaction.getContext().getRequest(); if (hasBody(contentTypeHeader, method)) { if (coreConfiguration.getCaptureBody() != OFF @@ -93,7 +93,7 @@ protected boolean hasBody(@Nullable String contentTypeHeader, String method) { return METHODS_WITH_BODY.contains(method) && contentTypeHeader != null; } - public void applyDefaultTransactionName(String method, String pathFirstPart, @Nullable String pathSecondPart, Transaction transaction, int priorityOffset) { + public void applyDefaultTransactionName(String method, String pathFirstPart, @Nullable String pathSecondPart, Transaction transaction, int priorityOffset) { // JSPs don't contain path params and the name is more telling than the generated servlet class if (webConfiguration.isUsePathAsName() || ENDS_WITH_JSP.matches(pathFirstPart, pathSecondPart)) { // should override ServletName#doGet @@ -115,7 +115,7 @@ public void applyDefaultTransactionName(String method, String pathFirstPart, @Nu * for example when the amount of query parameters is longer than the application server allows. * In that case, we rather not want that the agent looks like the cause for this. */ - protected void fillRequestParameters(Transaction transaction, String method, @Nullable Map parameterMap, @Nullable String contentTypeHeader) { + protected void fillRequestParameters(Transaction transaction, String method, @Nullable Map parameterMap, @Nullable String contentTypeHeader) { Request request = transaction.getContext().getRequest(); if (hasBody(contentTypeHeader, method)) { if (coreConfiguration.getCaptureBody() != OFF && parameterMap != null) { @@ -164,13 +164,7 @@ protected void fillRequest(Request request, String protocol, String method, @Nul } protected void fillUrlRelatedFields(Request request, @Nullable String scheme, @Nullable String serverName, int serverPort, String requestURI, @Nullable String queryString) { - request.getUrl().resetState(); - request.getUrl() - .withProtocol(scheme) - .withHostname(serverName) - .withPort(serverPort) - .withPathname(requestURI) - .withSearch(queryString); + request.getUrl().fillFrom(scheme, serverName, serverPort, requestURI, queryString); } public boolean isCaptureHeaders() { diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebClientHelper.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebClientHelper.java index 24ff54fd640..695a2ee4a62 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebClientHelper.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebClientHelper.java @@ -19,10 +19,7 @@ package co.elastic.apm.agent.vertx; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.*; import io.vertx.core.http.HttpClientRequest; import io.vertx.ext.web.client.HttpResponse; import io.vertx.ext.web.client.impl.HttpContext; @@ -50,10 +47,10 @@ public void startSpan(AbstractSpan parent, HttpContext httpContext, HttpCl if (existingSpanObj != null) { // there is already an active span for this HTTP request, // don't create a new span but propagate tracing headers - ((Span) existingSpanObj).propagateTraceContext(httpRequest, HeaderSetter.INSTANCE); + ((Span) existingSpanObj).propagateTraceContext(httpRequest, HeaderSetter.INSTANCE); } else { URI requestUri = URI.create(httpRequest.absoluteURI()); - Span span = HttpClientHelper.startHttpClientSpan(parent, getMethod(httpRequest), requestUri, null); + Span span = HttpClientHelper.startHttpClientSpan(parent, getMethod(httpRequest), requestUri, null); if (span != null) { span.propagateTraceContext(httpRequest, HeaderSetter.INSTANCE); @@ -68,7 +65,7 @@ public void startSpan(AbstractSpan parent, HttpContext httpContext, HttpCl public void followRedirect(HttpContext httpContext, HttpClientRequest httpRequest) { Object existingSpanObj = httpContext.get(WEB_CLIENT_SPAN_KEY); if (existingSpanObj != null) { - Span existingSpan = (Span) existingSpanObj; + Span existingSpan = (Span) existingSpanObj; existingSpan.propagateTraceContext(httpRequest, HeaderSetter.INSTANCE); } } @@ -88,11 +85,11 @@ private void finalizeSpan(HttpContext httpContext, int statusCode, @Nullable // Setting to null removes from the attributes map httpContext.set(WEB_CLIENT_SPAN_KEY, null); - Span span = (Span) spanObj; + Span span = (Span) spanObj; span.decrementReferences(); if (thrown != null) { - span.captureException(thrown).withOutcome(Outcome.FAILURE); + span.captureException(thrown).withOutcome(DefaultOutcome.FAILURE); } if (statusCode > 0) { diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebHelper.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebHelper.java index 525561830fb..8ac1660d66b 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebHelper.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebHelper.java @@ -18,12 +18,7 @@ */ package co.elastic.apm.agent.vertx; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.context.web.ResultUtil; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.*; import co.elastic.apm.agent.util.PrivilegedActionUtils; import co.elastic.apm.agent.util.VersionUtils; import io.netty.buffer.ByteBuf; @@ -61,8 +56,8 @@ protected AbstractVertxWebHelper(Tracer tracer) { } @Nullable - protected Transaction startOrGetTransaction(HttpServerRequest httpServerRequest) { - Transaction transaction = tracer.currentTransaction(); + protected Transaction startOrGetTransaction(HttpServerRequest httpServerRequest) { + Transaction transaction = tracer.currentTransaction(); if (transaction != null) { return transaction; } else if (!serverHelper.isRequestExcluded(httpServerRequest.uri(), httpServerRequest.headers().get(USER_AGENT_HEADER))) { @@ -72,9 +67,9 @@ protected Transaction startOrGetTransaction(HttpServerRequest httpServerRequest) } @Nullable - public abstract Transaction setRouteBasedNameForCurrentTransaction(RoutingContext routingContext); + public abstract Transaction setRouteBasedNameForCurrentTransaction(RoutingContext routingContext); - protected void setRouteBasedTransactionName(Transaction transaction, RoutingContext routingContext) { + protected void setRouteBasedTransactionName(Transaction transaction, RoutingContext routingContext) { if (!webConfiguration.isUsePathAsName()) { String path = routingContext.currentRoute().getPath(); if (path != null) { @@ -87,7 +82,7 @@ protected void setRouteBasedTransactionName(Transaction transaction, RoutingCont } } - public void finalizeTransaction(@Nullable HttpServerResponse httpServerResponse, Transaction transaction) { + public void finalizeTransaction(@Nullable HttpServerResponse httpServerResponse, Transaction transaction) { try { if (httpServerResponse != null) { final Response response = transaction.getContext().getResponse(); @@ -104,7 +99,7 @@ public void finalizeTransaction(@Nullable HttpServerResponse httpServerResponse, } } - public void captureBody(@Nullable Transaction transaction, Buffer requestDataBuffer) { + public void captureBody(@Nullable Transaction transaction, Buffer requestDataBuffer) { if (transaction == null || transaction.getContext().getRequest().getBodyBuffer() == null) { return; } @@ -123,7 +118,7 @@ public void captureBody(@Nullable Transaction transaction, Buffer requestDataBuf } } - protected void enrichRequest(HttpServerRequest httpServerRequest, Transaction transaction) { + protected void enrichRequest(HttpServerRequest httpServerRequest, Transaction transaction) { transaction.setFrameworkName(FRAMEWORK_NAME); transaction.setFrameworkVersion(VersionUtils.getVersion(HttpServerRequest.class, "io.vertx", "vertx-web")); transaction.withType(SPAN_TYPE); @@ -148,7 +143,7 @@ protected void enrichRequest(HttpServerRequest httpServerRequest, Transaction tr } - private void setResponseHeaders(Transaction transaction, HttpServerResponse httpServerResponse, Response response) { + private void setResponseHeaders(Transaction transaction, HttpServerResponse httpServerResponse, Response response) { if (transaction.isSampled() && isCaptureHeaders()) { final Set headerNames = httpServerResponse.headers().names(); if (headerNames != null) { @@ -160,7 +155,7 @@ private void setResponseHeaders(Transaction transaction, HttpServerResponse http } - private void setRequestParameters(Transaction transaction, HttpServerRequest httpServerRequest, String method, String contentType) { + private void setRequestParameters(Transaction transaction, HttpServerRequest httpServerRequest, String method, String contentType) { if (transaction.isSampled() && captureParameters(method, contentType)) { final Map parameterMap = new HashMap<>(); for (String name : httpServerRequest.params().names()) { @@ -173,7 +168,7 @@ private void setRequestParameters(Transaction transaction, HttpServerRequest htt } } - private void setRequestHeaders(Transaction transaction, HttpServerRequest httpServerRequest) { + private void setRequestHeaders(Transaction transaction, HttpServerRequest httpServerRequest) { final Request req = transaction.getContext().getRequest(); if (transaction.isSampled() && isCaptureHeaders()) { setCookies(httpServerRequest, req); diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/GenericHandlerWrapper.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/GenericHandlerWrapper.java index bff1d5c6b25..670e1800364 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/GenericHandlerWrapper.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/GenericHandlerWrapper.java @@ -18,12 +18,15 @@ */ package co.elastic.apm.agent.vertx; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Tracer; import io.vertx.core.Handler; public class GenericHandlerWrapper implements Handler { + private static final Tracer tracer = GlobalTracer.get(); + protected final Handler actualHandler; private final AbstractSpan parentSpan; @@ -48,7 +51,7 @@ public void handle(T event) { } public static Handler wrapIfActiveSpan(Handler handler) { - AbstractSpan currentSpan = GlobalTracer.get().getActive(); + AbstractSpan currentSpan = tracer.getActive(); if (currentSpan != null) { handler = new GenericHandlerWrapper<>(currentSpan, handler); diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/MultiMapHeadersGetterSetter.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/MultiMapHeadersGetterSetter.java index c5da6003f03..bb3e1395e66 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/MultiMapHeadersGetterSetter.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/MultiMapHeadersGetterSetter.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.vertx; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.plugin.spi.TextHeaderGetter; +import co.elastic.apm.plugin.spi.TextHeaderSetter; import io.vertx.core.MultiMap; import javax.annotation.Nullable; diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/SetTimerWrapper.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/SetTimerWrapper.java index 44af7ab1f2a..910112faedc 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/SetTimerWrapper.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/SetTimerWrapper.java @@ -18,12 +18,15 @@ */ package co.elastic.apm.agent.vertx; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.AbstractSpan; +import co.elastic.apm.plugin.spi.Tracer; import io.vertx.core.Handler; public class SetTimerWrapper extends GenericHandlerWrapper { + private static final Tracer tracer = GlobalTracer.get(); + /** * Use this thread local to prevent tracking of endless, recursive timer jobs */ @@ -44,7 +47,7 @@ public SetTimerWrapper(AbstractSpan parentSpan, Handler actualHandler) } public static Handler wrapTimerIfActiveSpan(Handler handler) { - AbstractSpan currentSpan = GlobalTracer.get().getActive(); + AbstractSpan currentSpan = tracer.getActive(); // do not wrap if there is no parent span or if we are in the recursive context of the same type of timer if (currentSpan != null && !handler.getClass().getName().equals(activeTimerHandlerPerThread.get())) { diff --git a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/WebHelper.java b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/WebHelper.java index f4c15b4ea3e..ef9b4fe1b63 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/WebHelper.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/WebHelper.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.vertx.v3.web; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; @@ -38,7 +38,7 @@ public class WebHelper extends AbstractVertxWebHelper { private static final WebHelper INSTANCE = new WebHelper(GlobalTracer.get()); - static final WeakMap transactionMap = WeakConcurrentProviderImpl.createWeakSpanMap(); + static final WeakMap> transactionMap = WeakConcurrentProviderImpl.createWeakSpanMap(); public static WebHelper getInstance() { return INSTANCE; @@ -53,8 +53,8 @@ public static WebHelper getInstance() { } @Nullable - public Transaction startOrGetTransaction(HttpServerRequest httpServerRequest) { - Transaction transaction = super.startOrGetTransaction(httpServerRequest); + public Transaction startOrGetTransaction(HttpServerRequest httpServerRequest) { + Transaction transaction = super.startOrGetTransaction(httpServerRequest); if (transaction != null) { mapTransaction(httpServerRequest, transaction); @@ -65,9 +65,9 @@ public Transaction startOrGetTransaction(HttpServerRequest httpServerRequest) { } @Override - public Transaction setRouteBasedNameForCurrentTransaction(RoutingContext routingContext) { + public Transaction setRouteBasedNameForCurrentTransaction(RoutingContext routingContext) { HttpServerRequest request = routingContext.request(); - Transaction transaction = getTransactionForRequest(request); + Transaction transaction = getTransactionForRequest(request); if (transaction != null) { setRouteBasedTransactionName(transaction, routingContext); @@ -76,27 +76,27 @@ public Transaction setRouteBasedNameForCurrentTransaction(RoutingContext routing return transaction; } - public void mapTransaction(Object key, Transaction transaction) { + public void mapTransaction(Object key, Transaction transaction) { transactionMap.put(key, transaction); } @Nullable - public Transaction lookupTransaction(Object key) { + public Transaction lookupTransaction(Object key) { return transactionMap.get(key); } @Nullable - public Transaction removeTransactionMapping(Object key) { + public Transaction removeTransactionMapping(Object key) { return transactionMap.remove(key); } @Nullable - public Transaction getTransactionForRequest(HttpServerRequest request) { + public Transaction getTransactionForRequest(HttpServerRequest request) { if (request.getClass().getName().equals("io.vertx.ext.web.impl.HttpServerRequestWrapper")) { request = request.endHandler(noopHandler); log.debug("VERTX-DEBUG: Vert.x request obtained through endHandler instrumentation: {}", request); } - Transaction transaction = lookupTransaction(request); + Transaction transaction = lookupTransaction(request); if (transaction != null) { log.debug("VERTX-DEBUG: transaction {} is mapped to the Vert.x request: {}", transaction, request); } else { diff --git a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/WebInstrumentation.java b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/WebInstrumentation.java index 5f712d23771..3ff3192a4da 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/WebInstrumentation.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/WebInstrumentation.java @@ -18,14 +18,12 @@ */ package co.elastic.apm.agent.vertx.v3.web; -import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.vertx.v3.Vertx3Instrumentation; -import io.vertx.core.Handler; +import co.elastic.apm.plugin.spi.Transaction; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpServerRequest; import io.vertx.ext.web.RoutingContext; import net.bytebuddy.asm.Advice; -import net.bytebuddy.asm.Advice.AssignReturned.ToFields.ToField; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -35,14 +33,7 @@ import java.util.Arrays; import java.util.Collection; -import static net.bytebuddy.matcher.ElementMatchers.declaresField; -import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; -import static net.bytebuddy.matcher.ElementMatchers.isInterface; -import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.namedOneOf; -import static net.bytebuddy.matcher.ElementMatchers.not; -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static net.bytebuddy.matcher.ElementMatchers.*; @SuppressWarnings("JavadocReference") public abstract class WebInstrumentation extends Vertx3Instrumentation { @@ -79,7 +70,7 @@ public static class RouteImplAdvice { @Nullable @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object nextEnter(@Advice.Argument(value = 0) RoutingContext routingContext) { - Transaction transaction = WebHelper.getInstance().setRouteBasedNameForCurrentTransaction(routingContext); + Transaction transaction = WebHelper.getInstance().setRouteBasedNameForCurrentTransaction(routingContext); if (transaction != null) { transaction.activate(); @@ -91,8 +82,8 @@ public static Object nextEnter(@Advice.Argument(value = 0) RoutingContext routin @Advice.OnMethodExit(suppress = Throwable.class, inline = false, onThrowable = Throwable.class) public static void nextExit(@Advice.Argument(value = 0) RoutingContext routingContext, @Nullable @Advice.Enter Object transactionObj, @Nullable @Advice.Thrown Throwable thrown) { - if (transactionObj instanceof Transaction) { - Transaction transaction = (Transaction) transactionObj; + if (transactionObj instanceof Transaction) { + Transaction transaction = (Transaction) transactionObj; transaction.captureException(thrown).deactivate(); } } @@ -138,7 +129,7 @@ public static class HandleDataAdvice { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void captureBody(@Advice.This HttpServerRequest request, @Advice.Argument(value = 0) Buffer requestDataBuffer) { - Transaction transaction = WebHelper.getInstance().getTransactionForRequest(request); + Transaction transaction = WebHelper.getInstance().getTransactionForRequest(request); helper.captureBody(transaction, requestDataBuffer); } } diff --git a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http1/Http1EndTransactionInstrumentation.java b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http1/Http1EndTransactionInstrumentation.java index ae1932b768a..cae1fbbafcb 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http1/Http1EndTransactionInstrumentation.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http1/Http1EndTransactionInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.vertx.v3.web.http1; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.vertx.v3.web.WebHelper; @@ -62,7 +62,7 @@ public static class ResponseCompleteAdvice { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void exit(@Advice.FieldValue("responseInProgress") HttpServerRequestImpl responseInProgress) { - Transaction transaction = helper.removeTransactionMapping(responseInProgress); + Transaction transaction = helper.removeTransactionMapping(responseInProgress); if (transaction != null) { HttpServerResponseImpl response = responseInProgress.response(); if (response != null) { diff --git a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http1/Http1StartTransactionInstrumentation.java b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http1/Http1StartTransactionInstrumentation.java index 84510a47fbb..10355debde4 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http1/Http1StartTransactionInstrumentation.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http1/Http1StartTransactionInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.vertx.v3.web.http1; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.vertx.v3.web.WebHelper; @@ -58,7 +58,7 @@ public static class AdviceClass { @Nullable @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object enter(@Advice.This HttpServerRequestImpl request) { - Transaction transaction = helper.startOrGetTransaction(request); + Transaction transaction = helper.startOrGetTransaction(request); if (transaction != null) { transaction.activate(); } @@ -69,8 +69,8 @@ public static Object enter(@Advice.This HttpServerRequestImpl request) { @Advice.OnMethodExit(suppress = Throwable.class, inline = false, onThrowable = Throwable.class) public static void exit(@Advice.Enter Object transactionObj, @Advice.Thrown @Nullable Throwable thrown) { - if (transactionObj instanceof Transaction) { - Transaction transaction = (Transaction) transactionObj; + if (transactionObj instanceof Transaction) { + Transaction transaction = (Transaction) transactionObj; transaction.captureException(thrown).deactivate(); } } diff --git a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http2/Http2ServerRequestImplEndInstrumentation.java b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http2/Http2ServerRequestImplEndInstrumentation.java index 92a0624d553..2cd1dcc68c6 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http2/Http2ServerRequestImplEndInstrumentation.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http2/Http2ServerRequestImplEndInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.vertx.v3.web.http2; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.vertx.v3.web.WebHelper; @@ -64,7 +64,7 @@ public static class HttpRequestEndAdvice { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void exit(@Advice.This Http2ServerRequestImpl request, @Advice.FieldValue("response") @Nullable Http2ServerResponseImpl response) { - Transaction transaction = helper.removeTransactionMapping(request); + Transaction transaction = helper.removeTransactionMapping(request); if (transaction != null) { helper.finalizeTransaction(response, transaction); log.debug("VERTX-DEBUG: ended Vert.x HTTP 2 transaction {} with details from this response: {}", transaction, response); diff --git a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http2/Http2ServerResponseImplEndInstrumentation.java b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http2/Http2ServerResponseImplEndInstrumentation.java index 7ccdb0c6fd7..24a497c9e71 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http2/Http2ServerResponseImplEndInstrumentation.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http2/Http2ServerResponseImplEndInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.vertx.v3.web.http2; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.vertx.v3.web.WebHelper; @@ -62,7 +62,7 @@ public static class WriteAdvice { public static void writeExit(@Advice.This Http2ServerResponseImpl response, @Advice.Argument(1) boolean end) { if (end) { - Transaction transaction = WebHelper.getInstance().removeTransactionMapping(response); + Transaction transaction = WebHelper.getInstance().removeTransactionMapping(response); log.debug("VERTX-DEBUG: removing transaction {} mapping to response {}", transaction, response); } } @@ -89,7 +89,7 @@ public static class CloseAdvice { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void closeExit(@Advice.This Http2ServerResponseImpl response) { - Transaction transaction = WebHelper.getInstance().removeTransactionMapping(response); + Transaction transaction = WebHelper.getInstance().removeTransactionMapping(response); log.debug("VERTX-DEBUG: removing transaction {} mapping to response {}", transaction, response); } } diff --git a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http2/Http2StartTransactionInstrumentation.java b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http2/Http2StartTransactionInstrumentation.java index 67b81b3273c..f64e4bcb36c 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http2/Http2StartTransactionInstrumentation.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/web/http2/Http2StartTransactionInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.vertx.v3.web.http2; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.vertx.v3.web.WebHelper; @@ -53,7 +53,7 @@ public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void exit(@Advice.Return Http2ServerRequestImpl request) { - Transaction transaction = WebHelper.getInstance().startOrGetTransaction(request); + Transaction transaction = WebHelper.getInstance().startOrGetTransaction(request); if (transaction != null) { // In HTTP 2, there may still be response processing after request end has ended the transaction WebHelper.getInstance().mapTransaction(request.response(), transaction); diff --git a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/webclient/WebClientInstrumentation.java b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/webclient/WebClientInstrumentation.java index 65d68e02574..cd7d952f5f4 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/webclient/WebClientInstrumentation.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/src/main/java/co/elastic/apm/agent/vertx/v3/webclient/WebClientInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.vertx.v3.webclient; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.AbstractSpan; import co.elastic.apm.agent.vertx.AbstractVertxWebClientHelper; import co.elastic.apm.agent.vertx.v3.Vertx3Instrumentation; import io.vertx.core.Context; diff --git a/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/web/WebHelper.java b/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/web/WebHelper.java index acb76bc4dfb..08995e5f449 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/web/WebHelper.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/web/WebHelper.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.vertx.v4.web; -import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.GlobalTracer; +import co.elastic.apm.plugin.spi.Tracer; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.vertx.AbstractVertxWebHelper; import io.vertx.core.Context; import io.vertx.core.http.HttpServerRequest; @@ -41,8 +41,8 @@ private WebHelper(Tracer tracer) { } @Nullable - public Transaction startOrGetTransaction(Context context, HttpServerRequest httpServerRequest) { - Transaction transaction = super.startOrGetTransaction(httpServerRequest); + public Transaction startOrGetTransaction(Context context, HttpServerRequest httpServerRequest) { + Transaction transaction = super.startOrGetTransaction(httpServerRequest); if (transaction != null) { enrichRequest(httpServerRequest, transaction); @@ -54,9 +54,9 @@ public Transaction startOrGetTransaction(Context context, HttpServerRequest http @Nullable @Override - public Transaction setRouteBasedNameForCurrentTransaction(RoutingContext routingContext) { + public Transaction setRouteBasedNameForCurrentTransaction(RoutingContext routingContext) { Context context = routingContext.vertx().getOrCreateContext(); - Transaction transaction = context.getLocal(CONTEXT_TRANSACTION_KEY); + Transaction transaction = context.getLocal(CONTEXT_TRANSACTION_KEY); if (transaction != null) { setRouteBasedTransactionName(transaction, routingContext); } diff --git a/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/web/WebInstrumentation.java b/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/web/WebInstrumentation.java index e90bab63a6b..c94c213d951 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/web/WebInstrumentation.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/web/WebInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.vertx.v4.web; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.plugin.spi.Transaction; import co.elastic.apm.agent.vertx.v4.Vertx4Instrumentation; import io.vertx.core.Context; import io.vertx.core.buffer.Buffer; @@ -155,8 +155,8 @@ public static void receiveRequest(@Advice.Argument(value = 0) Context context, @ @Nullable @Advice.Argument(value = 3) Throwable failure) { Object transactionObj = context.getLocal(WebHelper.CONTEXT_TRANSACTION_KEY); - if (transactionObj instanceof Transaction) { - Transaction transaction = (Transaction) transactionObj; + if (transactionObj instanceof Transaction) { + Transaction transaction = (Transaction) transactionObj; if (failure != null) { transaction.captureException(failure); } @@ -199,7 +199,7 @@ public static class RouteImplAdvice { @Nullable @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object nextEnter(@Advice.Argument(value = 0) RoutingContext routingContext) { - Transaction transaction = helper.setRouteBasedNameForCurrentTransaction(routingContext); + Transaction transaction = helper.setRouteBasedNameForCurrentTransaction(routingContext); if (transaction != null) { transaction.activate(); @@ -211,8 +211,8 @@ public static Object nextEnter(@Advice.Argument(value = 0) RoutingContext routin @Advice.OnMethodExit(suppress = Throwable.class, inline = false, onThrowable = Throwable.class) public static void nextExit(@Advice.Argument(value = 0) RoutingContext routingContext, @Nullable @Advice.Enter Object transactionObj, @Nullable @Advice.Thrown Throwable thrown) { - if (transactionObj instanceof Transaction) { - Transaction transaction = (Transaction) transactionObj; + if (transactionObj instanceof Transaction) { + Transaction transaction = (Transaction) transactionObj; transaction.captureException(thrown).deactivate(); } } @@ -261,7 +261,7 @@ public static class HandleDataAdvice { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void wrapHandler(@Advice.Argument(value = 0) Buffer requestDataBuffer, @Advice.FieldValue(value = "context") Context context) { - Transaction transaction = context.getLocal(WebHelper.CONTEXT_TRANSACTION_KEY); + Transaction transaction = context.getLocal(WebHelper.CONTEXT_TRANSACTION_KEY); helper.captureBody(transaction, requestDataBuffer); } } diff --git a/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/webclient/HttpContextInstrumentation.java b/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/webclient/HttpContextInstrumentation.java index 0eb51dfeb87..647de41a768 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/webclient/HttpContextInstrumentation.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/webclient/HttpContextInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.vertx.v4.webclient; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.plugin.spi.AbstractSpan; import co.elastic.apm.agent.vertx.AbstractVertxWebClientHelper; import co.elastic.apm.agent.vertx.AbstractVertxWebHelper; import co.elastic.apm.agent.vertx.v4.Vertx4Instrumentation; diff --git a/pom.xml b/pom.xml index 0d99fc58546..1f15a04bc06 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,7 @@ apm-agent-common apm-agent-cached-lookup-key apm-opentracing + apm-agent-plugin-spi