diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 4f729fe6e95..b8be1a53f94 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -19,6 +19,7 @@ endif::[] //// === Unreleased +* Introduce *apm-agent-tracer* module that contains a minimal, zero-dependency `Tracer` API. [[release-notes-1.37.0]] ==== 1.37.0 - YYYY/MM/DD diff --git a/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/objectpool/impl/ThreadLocalObjectPool.java b/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/objectpool/impl/ThreadLocalObjectPool.java index 1b7058c8a05..1cba8739bae 100644 --- a/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/objectpool/impl/ThreadLocalObjectPool.java +++ b/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/objectpool/impl/ThreadLocalObjectPool.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.objectpool.impl; -import co.elastic.apm.agent.objectpool.Allocator; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.objectpool.Resetter; +import co.elastic.apm.agent.tracer.pooling.Allocator; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; diff --git a/apm-agent-core/pom.xml b/apm-agent-core/pom.xml index 50b14298dcd..30d382eb912 100644 --- a/apm-agent-core/pom.xml +++ b/apm-agent-core/pom.xml @@ -33,6 +33,11 @@ apm-agent-common ${project.version} + + ${project.groupId} + apm-agent-tracer + ${project.version} + ${project.groupId} apm-agent-cached-lookup-key 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 a7ec6623306..3f9a09a6076 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 @@ -30,10 +30,8 @@ import co.elastic.apm.agent.impl.sampling.Sampler; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.BinaryHeaderGetter; import co.elastic.apm.agent.impl.transaction.ElasticContext; import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; import co.elastic.apm.agent.impl.transaction.TraceContext; import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.logging.LoggingConfiguration; @@ -50,6 +48,9 @@ import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import co.elastic.apm.agent.util.DependencyInjectingServiceLoader; import co.elastic.apm.agent.util.ExecutorUtils; +import co.elastic.apm.agent.tracer.Scope; +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import org.stagemonitor.configuration.ConfigurationOption; import org.stagemonitor.configuration.ConfigurationOptionProvider; import org.stagemonitor.configuration.ConfigurationRegistry; @@ -290,7 +291,7 @@ public Span startSpan(AbstractSpan parent, long epochMicros) { * @param parentContext the trace context of the parent * @param epochMicros the start timestamp of the span in microseconds after epoch * @return a new started span - * @see #startSpan(TraceContext.ChildContextCreator, Object) + * @see #startSpan(ChildContextCreator, Object) */ public Span startSpan(TraceContext.ChildContextCreator childContextCreator, T parentContext, long epochMicros) { return createSpan().start(childContextCreator, parentContext, epochMicros); @@ -374,8 +375,14 @@ public ConfigurationRegistry getConfigurationRegistry() { return configurationRegistry; } - public T getConfig(Class configProvider) { - return configurationRegistry.getConfig(configProvider); + @Override + @SuppressWarnings({"unchecked", "rawtypes"}) + public T getConfig(Class configProvider) { + if (ConfigurationOptionProvider.class.isAssignableFrom(configProvider)) { + return (T) configurationRegistry.getConfig((Class) configProvider); + } else { + return null; + } } public void endTransaction(Transaction transaction) { @@ -516,6 +523,7 @@ public Sampler getSampler() { return sampler; } + @Override public ObjectPoolFactory getObjectPoolFactory() { return objectPoolFactory; } @@ -756,7 +764,7 @@ public void activate(ElasticContext context) { public Scope activateInScope(final ElasticContext context) { // already in scope if (currentContext() == context) { - return Scope.NoopScope.INSTANCE; + return NoopScope.INSTANCE; } context.activate(); @@ -837,4 +845,23 @@ public ScheduledThreadPoolExecutor getSharedSingleThreadedPool() { public void addShutdownHook(Closeable closeable) { lifecycleListeners.add(ClosableLifecycleListenerAdapter.of(closeable)); } + + @Nullable + @Override + public T probe(Class type) { + if (type.isInstance(this)) { + return type.cast(this); + } else { + return null; + } + } + + @Override + public T require(Class type) { + T cast = probe(type); + if (cast == null) { + throw new IllegalStateException(this + " does not implement " + type.getName()); + } + return cast; + } } 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 017be270c83..fb517633ba3 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 @@ -22,12 +22,13 @@ import co.elastic.apm.agent.impl.error.ErrorCapture; import co.elastic.apm.agent.impl.sampling.Sampler; import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.BinaryHeaderGetter; import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.util.PrivilegedActionUtils; import co.elastic.apm.agent.util.VersionUtils; +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.pooling.ObjectPoolFactory; import javax.annotation.Nullable; import java.io.File; @@ -231,4 +232,25 @@ public boolean isRunning() { public Span createExitChildSpan() { return tracer.createExitChildSpan(); } + + @Nullable + @Override + public T probe(Class type) { + return tracer.probe(type); + } + + @Override + public T require(Class type) { + return tracer.require(type); + } + + @Override + public T getConfig(Class configuration) { + return tracer.getConfig(configuration); + } + + @Override + public ObjectPoolFactory getObjectPoolFactory() { + return tracer.getObjectPoolFactory(); + } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopScope.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopScope.java new file mode 100644 index 00000000000..ae3d48ac93b --- /dev/null +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopScope.java @@ -0,0 +1,15 @@ +package co.elastic.apm.agent.impl; + +import co.elastic.apm.agent.tracer.Scope; + +public class NoopScope implements Scope { + + public static final Scope INSTANCE = new NoopScope(); + + private NoopScope() { + } + + @Override + public void close() { + } +} 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 b0e35cdf76e..76dc5f7db76 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 @@ -22,10 +22,11 @@ import co.elastic.apm.agent.impl.error.ErrorCapture; import co.elastic.apm.agent.impl.sampling.Sampler; import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.BinaryHeaderGetter; import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.objectpool.ObjectPoolFactory; +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import javax.annotation.Nullable; @@ -154,4 +155,25 @@ public boolean isRunning() { public Span createExitChildSpan() { return null; } + + @Nullable + @Override + public T probe(Class type) { + return null; + } + + @Override + public T require(Class type) { + throw new IllegalStateException(); + } + + @Override + public T getConfig(Class configuration) { + return null; + } + + @Override + public co.elastic.apm.agent.tracer.pooling.ObjectPoolFactory getObjectPoolFactory() { + return new ObjectPoolFactory(); + } } 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 c4b23583b82..a357ade5de6 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 @@ -22,24 +22,18 @@ import co.elastic.apm.agent.impl.error.ErrorCapture; import co.elastic.apm.agent.impl.sampling.Sampler; import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.BinaryHeaderGetter; -import co.elastic.apm.agent.impl.transaction.HeaderGetter; 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.agent.tracer.dispatch.BinaryHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import javax.annotation.Nullable; -public interface Tracer { +public interface Tracer extends co.elastic.apm.agent.tracer.Tracer { - /** - * Starts a trace-root transaction - * - * @param initiatingClassLoader the class loader corresponding to the service which initiated the creation of the transaction. - * Used to determine the service name. - * @return a transaction that will be the root of the current trace if the agent is currently RUNNING; null otherwise - */ @Nullable + @Override Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader); @Nullable @@ -58,17 +52,7 @@ public interface Tracer { @Nullable Transaction startRootTransaction(Sampler sampler, long epochMicros, @Nullable ClassLoader initiatingClassLoader); - /** - * Starts a transaction as a child of the context headers obtained through the provided {@link HeaderGetter}. - * If the created transaction cannot be started as a child transaction (for example - if no parent context header is - * available), then it will be started as the root transaction of the trace. - * - * @param headerCarrier the Object from which context headers can be obtained, typically a request or a message - * @param textHeadersGetter provides the trace context headers required in order to create a child transaction - * @param initiatingClassLoader the class loader corresponding to the service which initiated the creation of the transaction. - * Used to determine the service name. - * @return a transaction which is a child of the provided parent if the agent is currently RUNNING; null otherwise - */ + @Override @Nullable Transaction startChildTransaction(@Nullable C headerCarrier, TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader); @@ -93,17 +77,7 @@ public interface Tracer { Transaction startChildTransaction(@Nullable C headerCarrier, TextHeaderGetter textHeadersGetter, Sampler sampler, long epochMicros, @Nullable ClassLoader initiatingClassLoader); - /** - * Starts a transaction as a child of the context headers obtained through the provided {@link HeaderGetter}. - * If the created transaction cannot be started as a child transaction (for example - if no parent context header is - * available), then it will be started as the root transaction of the trace. - * - * @param headerCarrier the Object from which context headers can be obtained, typically a request or a message - * @param binaryHeadersGetter provides the trace context headers required in order to create a child transaction - * @param initiatingClassLoader the class loader corresponding to the service which initiated the creation of the transaction. - * Used to determine the service name. - * @return a transaction which is a child of the provided parent if the agent is currently RUNNING; null otherwise - */ + @Override @Nullable Transaction startChildTransaction(@Nullable C headerCarrier, BinaryHeaderGetter binaryHeadersGetter, @Nullable ClassLoader initiatingClassLoader); @@ -125,9 +99,11 @@ Transaction startChildTransaction(@Nullable C headerCarrier, TextHeaderGette Transaction startChildTransaction(@Nullable C headerCarrier, BinaryHeaderGetter binaryHeadersGetter, Sampler sampler, long epochMicros, @Nullable ClassLoader initiatingClassLoader); + @Override @Nullable Transaction currentTransaction(); + @Override @Nullable AbstractSpan getActive(); @@ -174,6 +150,7 @@ Transaction startChildTransaction(@Nullable C headerCarrier, BinaryHeaderGet */ void stop(); + @Override boolean isRunning(); @Nullable 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..afcd86a8027 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 @@ -18,14 +18,14 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.Iterator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -public abstract class AbstractContext implements Recyclable { +public abstract class AbstractContext implements Recyclable, co.elastic.apm.agent.tracer.AbstractContext { public static final String REDACTED_CONTEXT_STRING = "[REDACTED]"; @@ -72,6 +72,7 @@ public boolean hasLabels() { return !labels.isEmpty(); } + @Override public Message getMessage() { return message; } 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..3dbcd57f8b9 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 @@ -18,17 +18,11 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; -/** - * Request - *

- * 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.agent.tracer.metadata.CloudOrigin { @Nullable protected String accountId; @@ -47,6 +41,7 @@ public String getAccountId() { return accountId; } + @Override public CloudOrigin withAccountId(@Nullable String accountId) { this.accountId = accountId; return this; @@ -57,6 +52,7 @@ public String getProvider() { return provider; } + @Override public CloudOrigin withProvider(@Nullable String provider) { this.provider = provider; return this; @@ -67,6 +63,7 @@ public String getRegion() { return region; } + @Override public CloudOrigin withRegion(@Nullable String region) { this.region = region; return this; @@ -77,6 +74,7 @@ public String getServiceName() { return serviceName; } + @Override public CloudOrigin withServiceName(@Nullable String serviceName) { this.serviceName = serviceName; return this; 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..7223c29614d 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 @@ -18,23 +18,19 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Allocator; import co.elastic.apm.agent.objectpool.ObjectPool; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; import co.elastic.apm.agent.objectpool.Resetter; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; +import co.elastic.apm.agent.tracer.pooling.Allocator; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.jctools.queues.atomic.MpmcAtomicArrayQueue; import javax.annotation.Nullable; import java.nio.Buffer; import java.nio.CharBuffer; - -/** - * An object containing contextual data for database spans - */ -public class Db implements Recyclable { +public class Db implements Recyclable, co.elastic.apm.agent.tracer.metadata.Db { private static final ObjectPool charBufferPool = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, new Allocator() { @@ -94,9 +90,7 @@ public String getInstance() { return instance; } - /** - * Database instance name - */ + @Override public Db withInstance(@Nullable String instance) { this.instance = instance; return this; @@ -110,25 +104,13 @@ public String getStatement() { return statement; } - /** - * A database statement (e.g. query) for the given database type - */ + @Override public Db withStatement(@Nullable String statement) { this.statement = statement; return this; } - /** - * Gets a pooled {@link CharBuffer} to record the DB statement and associates it with this instance. - *

- * Note: you may not hold a reference to the returned {@link CharBuffer} as it will be reused. - *

- *

- * Note: This method is not thread safe - *

- * - * @return a {@link CharBuffer} to record the DB statement - */ + @Override public CharBuffer withStatementBuffer() { if (this.statementBuffer == null) { this.statementBuffer = charBufferPool.createInstance(); @@ -136,14 +118,7 @@ public CharBuffer withStatementBuffer() { return this.statementBuffer; } - /** - * Returns the associated pooled {@link CharBuffer} to record the DB statement. - *

- * Note: returns {@code null} unless {@link #withStatementBuffer()} has previously been called - *

- * - * @return a {@link CharBuffer} to record the DB statement, or {@code null} - */ + @Override @Nullable public CharBuffer getStatementBuffer() { return statementBuffer; @@ -157,9 +132,7 @@ public String getType() { return type; } - /** - * Database type. For any SQL database, "sql". For others, the lower-case database category, e.g. "cassandra", "hbase", or "redis" - */ + @Override public Db withType(@Nullable String type) { this.type = type; return this; @@ -173,9 +146,7 @@ public String getUser() { return user; } - /** - * Username for accessing database - */ + @Override public Db withUser(@Nullable String user) { this.user = user; return this; @@ -204,12 +175,7 @@ public long getAffectedRowsCount(){ return affectedRowsCount; } - /** - * Sets the number of affected rows by statement execution - * - * @param count number of affected rows - * @return this - */ + @Override public Db withAffectedRowsCount(long count){ this.affectedRowsCount = count; return this; 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..2152dc2c18c 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 @@ -18,17 +18,14 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; -/** - * Context information about a destination of outgoing calls. - */ -public class Destination implements Recyclable { +public class Destination implements Recyclable, co.elastic.apm.agent.tracer.metadata.Destination { /** * An IP (v4 or v6) or a host/domain name. @@ -44,6 +41,7 @@ public class Destination implements Recyclable { private boolean portSetByUser; + @Override public Destination withAddress(@Nullable CharSequence address) { if (address != null && !addressSetByUser) { withAddress(address, 0, address.length()); @@ -65,6 +63,7 @@ public StringBuilder getAddress() { return address; } + @Override public Destination withPort(int port) { if (!portSetByUser) { this.port = port; @@ -82,10 +81,7 @@ public int getPort() { return port; } - /** - * @param addressPort host address and port in the following format 'host:3128' - * @return destination with updated address and port - */ + @Override public Destination withAddressPort(@Nullable String addressPort) { if (addressPort != null) { int separator = addressPort.lastIndexOf(':'); @@ -143,6 +139,7 @@ private void withAddress(CharSequence address, int start, int end) { private final Cloud cloud = new Cloud(); + @Override public Cloud getCloud() { return cloud; } @@ -161,6 +158,7 @@ public void resetState() { cloud.resetState(); } + @Override public Destination withSocketAddress(SocketAddress socketAddress) { if (socketAddress instanceof InetSocketAddress) { withInetSocketAddress((InetSocketAddress) socketAddress); @@ -168,6 +166,7 @@ public Destination withSocketAddress(SocketAddress socketAddress) { return this; } + @Override public Destination withInetSocketAddress(InetSocketAddress inetSocketAddress) { InetAddress inetAddress = inetSocketAddress.getAddress(); if (inetAddress != null) { @@ -179,14 +178,16 @@ public Destination withInetSocketAddress(InetSocketAddress inetSocketAddress) { return this; } + @Override public Destination withInetAddress(InetAddress inetAddress) { withAddress(inetAddress.getHostAddress()); return this; } - public static class Cloud implements Recyclable { + public static class Cloud implements Recyclable, co.elastic.apm.agent.tracer.metadata.Cloud { private final StringBuilder region = new StringBuilder(); + @Override public Cloud withRegion(@Nullable String region) { this.region.setLength(0); if (region != null) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Headers.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Headers.java index 1c2f53b3449..6fd78b77dff 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Headers.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Headers.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.util.BinaryHeaderMap; import co.elastic.apm.agent.util.NoRandomAccessMap; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.Iterator; 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..0af4652db87 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 @@ -18,11 +18,11 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; -public class Http implements Recyclable { +public class Http implements Recyclable, co.elastic.apm.agent.tracer.metadata.Http { /** * URL used by this HTTP outgoing span @@ -40,9 +40,7 @@ public class Http implements Recyclable { */ private int statusCode; - /** - * URL used for the outgoing HTTP call - */ + @Override public CharSequence getUrl() { // note: do not expose the underlying Url object, as it might not have // all it's properties set due to providing the full URL as-is @@ -56,6 +54,7 @@ public Url getInternalUrl() { return url; } + @Override @Nullable public String getMethod() { return method; @@ -65,9 +64,7 @@ public int getStatusCode() { return statusCode; } - /** - * URL used for the outgoing HTTP call - */ + @Override public Http withUrl(@Nullable String url) { if (url != null) { this.url.withFull(url); @@ -75,11 +72,13 @@ public Http withUrl(@Nullable String url) { return this; } + @Override public Http withMethod(String method) { this.method = method; return this; } + @Override public Http withStatusCode(int statusCode) { this.statusCode = statusCode; return this; 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..aa45d22ed5e 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 @@ -18,18 +18,18 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Allocator; import co.elastic.apm.agent.objectpool.ObjectPool; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; import co.elastic.apm.agent.objectpool.Resetter; +import co.elastic.apm.agent.tracer.pooling.Allocator; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.jctools.queues.atomic.MpmcAtomicArrayQueue; import javax.annotation.Nullable; 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.agent.tracer.metadata.Message { private static final ObjectPool stringBuilderPool = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, new Allocator() { @@ -70,11 +70,13 @@ public String getQueueName() { return queueName; } + @Override public Message withQueue(@Nullable String queueName) { this.queueName = queueName; return this; } + @Override public Message withRoutingKey(String routingKey) { this.routingKey = routingKey; return this; @@ -106,6 +108,7 @@ public StringBuilder getBodyForRead() { return body; } + @Override public Message withBody(@Nullable String body) { StringBuilder thisBody = getBodyForWrite(); thisBody.setLength(0); @@ -113,6 +116,7 @@ public Message withBody(@Nullable String body) { return this; } + @Override public Message appendToBody(CharSequence bodyContent) { getBodyForWrite().append(bodyContent); return this; @@ -125,11 +129,13 @@ public void redactBody() { } } + @Override public Message addHeader(@Nullable String key, @Nullable String value) { headers.add(key, value); return this; } + @Override public Message addHeader(@Nullable String key, @Nullable byte[] value) { headers.add(key, value); return this; @@ -140,6 +146,7 @@ public long getAge() { } @SuppressWarnings("UnusedReturnValue") + @Override public Message withAge(long age) { this.age = age; return this; 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..fd0860b518f 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 @@ -18,13 +18,13 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Allocator; import co.elastic.apm.agent.objectpool.ObjectPool; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.objectpool.Resetter; import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import co.elastic.apm.agent.util.PotentiallyMultiValuedMap; +import co.elastic.apm.agent.tracer.pooling.Allocator; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.jctools.queues.atomic.MpmcAtomicArrayQueue; import javax.annotation.Nullable; @@ -34,13 +34,7 @@ import static co.elastic.apm.agent.impl.context.AbstractContext.REDACTED_CONTEXT_STRING; - -/** - * Request - *

- * 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.agent.tracer.metadata.Request { private static final ObjectPool charBufferPool = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, @@ -111,11 +105,7 @@ public String getRawBody() { return rawBody; } - /** - * Sets the body as a raw string and removes any previously set {@link #postParams} or {@link #bodyBuffer}. - * - * @param rawBody the body as a raw string - */ + @Override public void setRawBody(String rawBody) { postParams.resetState(); if (bodyBuffer != null) { @@ -125,6 +115,7 @@ public void setRawBody(String rawBody) { this.rawBody = rawBody; } + @Override public void redactBody() { setRawBody(REDACTED_CONTEXT_STRING); } @@ -134,26 +125,13 @@ public Request addFormUrlEncodedParameter(String key, String value) { return this; } + @Override public Request addFormUrlEncodedParameters(String key, String[] values) { this.postParams.set(key, values); return this; } - /** - * Gets a pooled {@link CharBuffer} to record the request body and associates it with this instance. - *

- * Note: you may not hold a reference to the returned {@link CharBuffer} as it will be reused. - *

- *

- * Note: this method is not thread safe - *

- *

- * Note: In order for the value written to the body buffer to be used, you must call {@link Request#endOfBufferInput()}, - * which is the only valid way to invoke {@link CharBuffer#flip()} on the body buffer. - *

- * - * @return a {@link CharBuffer} to record the request body - */ + @Override public CharBuffer withBodyBuffer() { if (this.bodyBuffer == null) { this.bodyBuffer = charBufferPool.createInstance(); @@ -161,6 +139,7 @@ public CharBuffer withBodyBuffer() { return this.bodyBuffer; } + @Override public void endOfBufferInput() { if (bodyBuffer != null && !bodyBufferFinished) { bodyBufferFinished = true; @@ -168,14 +147,7 @@ public void endOfBufferInput() { } } - /** - * Returns the associated pooled {@link CharBuffer} to record the request body. - *

- * Note: returns {@code null} unless {@link #withBodyBuffer()} has previously been called - *

- * - * @return a {@link CharBuffer} to record the request body, or {@code null} - */ + @Override @Nullable public CharBuffer getBodyBuffer() { if (!bodyBufferFinished) { @@ -217,6 +189,7 @@ public Request addHeader(String headerName, @Nullable String headerValue) { return this; } + @Override public Request addHeader(String headerName, @Nullable Enumeration headerValues) { if (headerValues != null) { while (headerValues.hasMoreElements()) { @@ -226,9 +199,7 @@ public Request addHeader(String headerName, @Nullable Enumeration header return this; } - /** - * Should include any headers sent by the requester. - */ + @Override public PotentiallyMultiValuedMap getHeaders() { return headers; } @@ -241,6 +212,7 @@ public String getHttpVersion() { return httpVersion; } + @Override public Request withHttpVersion(@Nullable String httpVersion) { if (httpVersion != null) { this.httpVersion = getHttpVersion(httpVersion); @@ -271,32 +243,28 @@ public String getMethod() { return method; } + @Override public Request withMethod(@Nullable String method) { this.method = method; return this; } + @Override public Socket getSocket() { return socket; } - /** - * A complete Url, with scheme, host and path. - * (Required) - */ + @Override public Url getUrl() { return url; } - + @Override public Request addCookie(String cookieName, String cookieValue) { cookies.add(cookieName, cookieValue); return this; } - /** - * A parsed key-value object of cookies - */ public PotentiallyMultiValuedMap getCookies() { return cookies; } @@ -342,6 +310,7 @@ public void copyFrom(Request other) { this.rawBody = other.rawBody; } + @Override public boolean hasContent() { return method != null || headers.size() > 0 || 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..b5809c6257a 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 @@ -18,13 +18,13 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.util.PotentiallyMultiValuedMap; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.Collection; -public class Response implements Recyclable { +public class Response implements Recyclable, co.elastic.apm.agent.tracer.metadata.Response { /** * A mapping of HTTP headers of the response object @@ -47,9 +47,7 @@ public boolean isFinished() { return finished; } - /** - * A boolean indicating whether the response was finished or not - */ + @Override public Response withFinished(boolean finished) { this.finished = finished; return this; @@ -67,6 +65,7 @@ public Response addHeader(String headerName, String headerValue) { return this; } + @Override public Response addHeader(String headerName, @Nullable Collection headerValues) { if (headerValues != null) { for (String headerValue : headerValues) { @@ -76,9 +75,7 @@ public Response addHeader(String headerName, @Nullable Collection header return this; } - /** - * A mapping of HTTP headers of the response object - */ + @Override public PotentiallyMultiValuedMap getHeaders() { return headers; } @@ -88,6 +85,7 @@ public boolean isHeadersSent() { return headersSent; } + @Override public Response withHeadersSent(boolean headersSent) { this.headersSent = headersSent; return this; @@ -100,9 +98,7 @@ public int getStatusCode() { return statusCode; } - /** - * The HTTP status code of the response. - */ + @Override public Response withStatusCode(int statusCode) { this.statusCode = statusCode; return this; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceOrigin.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceOrigin.java index 64efa382c90..9927f7b66ec 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceOrigin.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceOrigin.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; 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..26433233a65 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 @@ -18,14 +18,11 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; -/** - * Represents a target service - */ -public class ServiceTarget implements Recyclable { +public class ServiceTarget implements Recyclable, co.elastic.apm.agent.tracer.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..4340dd5e4b3 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 @@ -18,11 +18,11 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; -public class Socket implements Recyclable { +public class Socket implements Recyclable, co.elastic.apm.agent.tracer.metadata.Socket { @Nullable private String remoteAddress; @@ -32,6 +32,7 @@ public String getRemoteAddress() { return remoteAddress; } + @Override public Socket withRemoteAddress(@Nullable String remoteAddress) { this.remoteAddress = remoteAddress; return this; 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..f5245d642cd 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.agent.tracer.SpanContext { /** * An object containing contextual data for database spans @@ -44,27 +44,22 @@ public class SpanContext extends AbstractContext { */ private final ServiceTarget serviceTarget = new ServiceTarget(); - /** - * An object containing contextual data for database spans - */ + @Override public Db getDb() { return db; } - /** - * An object containing contextual data for outgoing HTTP spans - */ + @Override public Http getHttp() { return http; } - /** - * An object containing contextual data for service maps - */ + @Override public Destination getDestination() { return destination; } + @Override public ServiceTarget getServiceTarget() { return serviceTarget; } 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..c4c9ea756b6 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.agent.tracer.TransactionContext { /** * A flat mapping of user-defined {@link String} keys and {@link String}, {@link Number} or {@link Boolean} values @@ -78,6 +78,7 @@ public Object getCustom(String key) { return custom.get(key); } + @Override public Response getResponse() { return response; } @@ -102,24 +103,17 @@ public boolean hasCustom() { return custom.entrySet().iterator(); } - /** - * Request - *

- * If a log record was generated as a result of a http request, the http interface can be used to collect this information. - */ + @Override public Request getRequest() { return request; } - /** - * User - *

- * Describes the authenticated User for a request. - */ + @Override public User getUser() { return user; } + @Override public CloudOrigin getCloudOrigin() { return cloudOrigin; } 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..0cb25dbb909 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 @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.net.MalformedURLException; @@ -27,10 +27,7 @@ import java.net.URL; -/** - * A complete URL, with scheme, host, port, path and query string. - */ -public class Url implements Recyclable { +public class Url implements Recyclable, co.elastic.apm.agent.tracer.metadata.Url { /** * The full, possibly agent-assembled URL of the request, e.g https://example.com:443/search?q=elasticsearch#top. @@ -69,9 +66,7 @@ public String getProtocol() { return protocol; } - /** - * The protocol of the request, e.g. 'https:'. - */ + @Override public Url withProtocol(@Nullable String protocol) { this.protocol = protocol; return this; @@ -154,9 +149,7 @@ public String getHostname() { return hostname; } - /** - * The hostname of the request, e.g. 'example.com'. - */ + @Override public Url withHostname(@Nullable String hostname) { this.hostname = hostname; return this; @@ -169,9 +162,7 @@ public int getPort() { return port; } - /** - * The port of the request, e.g. 443 - */ + @Override public Url withPort(int port) { this.port = port; return this; @@ -185,9 +176,7 @@ public String getPathname() { return pathname; } - /** - * The path of the request, e.g. '/search' - */ + @Override public Url withPathname(@Nullable String pathname) { this.pathname = pathname; return this; @@ -201,19 +190,13 @@ public String getSearch() { return search; } - /** - * The search describes the query string of the request. It is expected to have values delimited by ampersands. - */ + @Override public Url withSearch(@Nullable String search) { this.search = search; return this; } - /** - * Fills all attributes of Url from {@link URI} instance, also updates full - * - * @param uri URI - */ + @Override public void fillFrom(URI uri) { withProtocol(uri.getScheme()) .withHostname(uri.getHost()) @@ -242,6 +225,20 @@ public void fillFrom(URL url) { .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(); + } + @Deprecated public void fillFrom(CharSequence uriString) { full.setLength(0); 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..00ea8751c70 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 @@ -18,17 +18,12 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; -/** - * User - *

- * Describes the authenticated User for a request. - */ -public class User implements Recyclable { +public class User implements Recyclable, co.elastic.apm.agent.tracer.metadata.User { /** * Domain of the logged in user @@ -101,17 +96,13 @@ public User withEmail(@Nullable String email) { return this; } - /** - * The username of the logged in user - */ + @Override @Nullable public String getUsername() { return username; } - /** - * The username of the logged in user - */ + @Override public User withUsername(@Nullable String username) { this.username = username; return this; 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 83659b2f8ac..5f63869587e 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 @@ -25,9 +25,10 @@ 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.agent.objectpool.Recyclable; +import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.Collection; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/Log.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/Log.java index 031fd0c0a18..486bcd1602e 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/Log.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/Log.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.error; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; 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 4ea3d06eb38..d49977e794d 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 @@ -21,14 +21,19 @@ import co.elastic.apm.agent.collections.LongList; import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.Scope; import co.elastic.apm.agent.impl.context.AbstractContext; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.report.ReporterConfiguration; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderSetter; +import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import co.elastic.apm.agent.util.LoggerUtils; +import co.elastic.apm.agent.tracer.Scope; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.HashMap; @@ -38,7 +43,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.agent.tracer.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; @@ -131,26 +136,13 @@ public int getReferenceCount() { return references.get(); } - /** - * Requests this span to be discarded, even if it's sampled. - *

- * Whether the span can actually be discarded is determined by {@link #isDiscarded()} - *

- */ + @Override public T requestDiscarding() { this.discardRequested = true; - return (T) this; + return thiz(); } - /** - * Determines whether to discard the span. - * Only spans that return {@code false} are reported. - *

- * A span is discarded if it {@linkplain #isDiscardable() is discardable} and {@linkplain #requestDiscarding() requested to be discarded}. - *

- * - * @return {@code true}, if the span should be discarded, {@code false} otherwise. - */ + @Override public boolean isDiscarded() { return discardRequested && getTraceContext().isDiscardable(); } @@ -222,6 +214,7 @@ public boolean isReferenced() { return references.get() > 0; } + @Override public boolean isFinished() { return finished; } @@ -252,30 +245,13 @@ public CharSequence getNameForSerialization() { } } - /** - * Resets and returns the name {@link StringBuilder} if the provided priority is {@code >=} {@link #namePriority}. - * Otherwise, returns {@code null} - * - * @param namePriority the priority for the name. See also the {@code AbstractSpan#PRIO_*} constants. - * @return the name {@link StringBuilder} if the provided priority is {@code >=} {@link #namePriority}, {@code null} otherwise. - */ + @Override @Nullable public StringBuilder getAndOverrideName(int namePriority) { return getAndOverrideName(namePriority, true); } - /** - * Resets and returns the name {@link StringBuilder} if one of the following applies: - *
    - *
  • the provided priority is {@code >} {@link #namePriority}
  • - *
  • the provided priority is {@code ==} {@link #namePriority} AND {@code overrideIfSamePriority} is {@code true}
  • - *
- * Otherwise, returns {@code null} - * - * @param namePriority the priority for the name. See also the {@code AbstractSpan#PRIO_*} constants. - * @param overrideIfSamePriority specifies whether the existing name should be overridden if {@code namePriority} equals the priority used to set the current name - * @return the name {@link StringBuilder} if the provided priority is sufficient for overriding, {@code null} otherwise. - */ + @Override @Nullable public StringBuilder getAndOverrideName(int namePriority, boolean overrideIfSamePriority) { boolean shouldOverride = (overrideIfSamePriority) ? namePriority >= this.namePriority : namePriority > this.namePriority; @@ -312,24 +288,17 @@ public String getNameAsString() { return getNameForSerialization().toString(); } - /** - * Appends a string to the name. - *

- * This method helps to avoid the memory allocations of string concatenations - * as the underlying {@link StringBuilder} instance will be reused. - *

- * - * @param cs the char sequence to append to the name - * @return {@code this}, for chaining - */ + @Override public T appendToName(CharSequence cs) { return appendToName(cs, PRIO_DEFAULT); } + @Override public T appendToName(CharSequence cs, int priority) { return appendToName(cs, priority, 0, cs.length()); } + @Override public T appendToName(CharSequence cs, int priority, int startIndex, int endIndex) { if (priority >= namePriority) { this.name.append(cs, startIndex, endIndex); @@ -338,14 +307,17 @@ public T appendToName(CharSequence cs, int priority, int startIndex, int endInde return thiz(); } + @Override public T withName(@Nullable String name) { return withName(name, PRIO_DEFAULT); } + @Override public T withName(@Nullable String name, int priority) { return withName(name, priority, true); } + @Override public T withName(@Nullable String name, int priority, boolean overrideIfSamePriority) { boolean shouldOverride = (overrideIfSamePriority) ? priority >= this.namePriority : priority > this.namePriority; if (shouldOverride && name != null && !name.isEmpty()) { @@ -356,11 +328,13 @@ public T withName(@Nullable String name, int priority, boolean overrideIfSamePri return thiz(); } + @Override public T withType(@Nullable String type) { this.type = normalizeEmpty(type); return thiz(); } + @Override public T withSync(boolean sync) { this.sync = sync; return thiz(); @@ -378,6 +352,7 @@ public long getTimestamp() { return timestamp.get(); } + @Override public TraceContext getTraceContext() { return traceContext; } @@ -496,6 +471,7 @@ private void recycleSpanLinks() { spanLinks.clear(); } + @Override public Span createSpan() { return createSpan(traceContext.getClock().getEpochMicros()); } @@ -504,12 +480,7 @@ public Span createSpan(long epochMicros) { return tracer.startSpan(this, epochMicros); } - /** - * Creates a child Span representing a remote call event, unless this TraceContextHolder already represents an exit event. - * If current TraceContextHolder is representing an Exit- returns null - * - * @return an Exit span if this TraceContextHolder is not an exit span, null otherwise - */ + @Override @Nullable public Span createExitSpan() { if (isExit()) { @@ -521,7 +492,7 @@ public Span createExitSpan() { public T asExit() { isExit = true; - return (T) this; + return thiz(); } public boolean isExit() { @@ -537,11 +508,12 @@ public String captureExceptionAndGetErrorId(long epochMicros, @Nullable Throwabl return null; } + @Override 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) { @@ -571,6 +543,7 @@ public void addLabel(String key, Boolean value) { } } + @Override public abstract AbstractContext getContext(); /** @@ -583,6 +556,7 @@ protected void onAfterStart() { incrementReferences(); } + @Override public void end() { end(traceContext.getClock().getEpochMicros()); } @@ -650,13 +624,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 @@ -692,6 +666,7 @@ void onChildEnd(long epochMicros) { } } + @Override public void incrementReferences() { int referenceCount = references.incrementAndGet(); if (logger.isDebugEnabled()) { @@ -703,6 +678,7 @@ public void incrementReferences() { } } + @Override public void decrementReferences() { int referenceCount = references.decrementAndGet(); if (logger.isDebugEnabled()) { @@ -719,38 +695,21 @@ public void decrementReferences() { protected abstract void recycle(); - /** - * Sets Trace context text headers, using this context as parent, on the provided carrier using the provided setter - * - * @param carrier the text headers carrier - * @param headerSetter a setter implementing the actual addition of headers to the headers carrier - * @param the header carrier type, for example - an HTTP request - */ + @Override public void propagateTraceContext(C carrier, TextHeaderSetter headerSetter) { // the context of this span is propagated downstream so we can't discard it even if it's faster than span_min_duration setNonDiscardable(); getTraceContext().propagateTraceContext(carrier, headerSetter); } - /** - * Sets Trace context binary headers, using this context as parent, on the provided carrier using the provided setter - * - * @param carrier the binary headers carrier - * @param headerSetter a setter implementing the actual addition of headers to the headers carrier - * @param the header carrier type, for example - a Kafka record - * @return true if Trace Context headers were set; false otherwise - */ + @Override public boolean propagateTraceContext(C carrier, BinaryHeaderSetter headerSetter) { // the context of this span is propagated downstream so we can't discard it even if it's faster than span_min_duration setNonDiscardable(); return getTraceContext().propagateTraceContext(carrier, headerSetter); } - /** - * Sets this context as non-discardable, - * meaning that {@link AbstractSpan#isDiscarded()} will return {@code false}, - * even if {@link AbstractSpan#requestDiscarding()} has been called. - */ + @Override public void setNonDiscardable() { getTraceContext().setNonDiscardable(); } @@ -764,6 +723,7 @@ public boolean isDiscardable() { return getTraceContext().isDiscardable(); } + @Override public boolean isSampled() { return getTraceContext().isSampled(); } @@ -780,9 +740,7 @@ public LongList getChildIds() { protected abstract T thiz(); - /** - * @return user outcome if set, otherwise outcome value - */ + @Override public Outcome getOutcome() { if (userOutcome != null) { return userOutcome; @@ -801,6 +759,17 @@ public T withOutcome(Outcome outcome) { return thiz(); } + @Override + public T withOutcome(co.elastic.apm.agent.tracer.Outcome outcome) { + if (outcome.name().equals(Outcome.FAILURE.name())) { + return withOutcome(Outcome.FAILURE); + } else if (outcome.name().equals(Outcome.SUCCESS.name())) { + return withOutcome(Outcome.SUCCESS); + } else { + return withOutcome(Outcome.UNKNOWN); + } + } + /** * Sets user outcome, which has priority over outcome set through {@link #withOutcome(Outcome)} * @@ -838,6 +807,7 @@ public Map getOtelAttributes() { return otelAttributes; } + @Override @Nullable public String getType() { return type; @@ -854,4 +824,17 @@ private String normalizeType(@Nullable String type) { return type; } + @Override + public boolean addLink(BinaryHeaderGetter headerGetter, @Nullable C carrier) { + return addSpanLink(TraceContext.getFromTraceContextBinaryHeaders(), + headerGetter, + carrier); + } + + @Override + public boolean addLink(TextHeaderGetter headerGetter, @Nullable C carrier) { + return addSpanLink(TraceContext.getFromTraceContextTextHeaders(), + headerGetter, + carrier); + } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Composite.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Composite.java index d6440f7b5df..0370d432fc5 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Composite.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Composite.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.transaction; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/DroppedSpanStats.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/DroppedSpanStats.java index 05960ee6896..d5372e8e015 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/DroppedSpanStats.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/DroppedSpanStats.java @@ -19,11 +19,11 @@ package co.elastic.apm.agent.impl.transaction; import co.elastic.apm.agent.impl.context.ServiceTarget; -import co.elastic.apm.agent.objectpool.Allocator; import co.elastic.apm.agent.objectpool.ObjectPool; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; import co.elastic.apm.agent.util.CharSequenceUtils; +import co.elastic.apm.agent.tracer.pooling.Allocator; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.jctools.queues.atomic.MpmcAtomicArrayQueue; import javax.annotation.Nullable; 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..0ec6cb9d44f 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 @@ -18,32 +18,9 @@ */ package co.elastic.apm.agent.impl.transaction; -import co.elastic.apm.agent.impl.Scope; - import javax.annotation.Nullable; -public interface ElasticContext> { - - /** - * Makes the context active - * - * @return this - */ - T activate(); - - /** - * Deactivates context - * - * @return this - */ - T deactivate(); - - /** - * Activates context in a scope - * - * @return active scope that will deactivate context when closed - */ - Scope activateInScope(); +public interface ElasticContext> extends co.elastic.apm.agent.tracer.ElasticContext { /** * Adds a span as active within context. Might return a different context instance if required, for example diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContextWrapper.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContextWrapper.java index 4801fa64182..30e6e5091d5 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContextWrapper.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContextWrapper.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.impl.transaction; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.Scope; +import co.elastic.apm.agent.tracer.Scope; import javax.annotation.Nullable; import java.util.HashMap; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/EpochTickClock.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/EpochTickClock.java index 6573ec1cbc8..ad205eea0b1 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/EpochTickClock.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/EpochTickClock.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.transaction; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; /** * This clock makes sure that each {@link Span} and {@link Transaction} uses a consistent clock 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..9d7e73b5f8c 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 @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.transaction; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasTrigger.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasTrigger.java index 083e6dead15..6d80601634f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasTrigger.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasTrigger.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.transaction; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; 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..e76ab5513d3 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 @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.impl.transaction; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.util.HexUtils; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import com.dslplatform.json.JsonWriter; import javax.annotation.Nullable; @@ -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.agent.tracer.Id { private final byte[] data; private boolean empty = true; @@ -50,6 +50,7 @@ private Id(int idLengthBytes) { data = new byte[idLengthBytes]; } + @Override public void setToRandomValue() { setToRandomValue(ThreadLocalRandom.current()); } @@ -146,6 +147,7 @@ public String toString() { return s; } + @Override public boolean isEmpty() { return empty; } 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..bbe4743375d 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 @@ -19,6 +19,10 @@ package co.elastic.apm.agent.impl.transaction; import co.elastic.apm.agent.util.PotentiallyMultiValuedMap; +import co.elastic.apm.agent.tracer.dispatch.AbstractHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.HeaderRemover; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import javax.annotation.Nullable; @@ -43,7 +47,6 @@ public void forEach(String headerName, PotentiallyMultiValuedMap headerMap, } } - @Override public void setHeader(String headerName, String headerValue, PotentiallyMultiValuedMap headerMap) { headerMap.add(headerName, headerValue); } 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..9daf152351b 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.agent.tracer.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 cf793d33144..0086801dbc8 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 @@ -26,17 +26,17 @@ import co.elastic.apm.agent.impl.context.SpanContext; import co.elastic.apm.agent.impl.context.Url; import co.elastic.apm.agent.impl.context.web.ResultUtil; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.util.CharSequenceUtils; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.List; 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.agent.tracer.Span { private static final Logger logger = LoggerFactory.getLogger(Span.class); public static final long MAX_LOG_INTERVAL_MICRO_SECS = TimeUnit.MINUTES.toMicros(5); @@ -155,17 +155,13 @@ public Composite getComposite() { return composite; } - /** - * Sets the span's subtype, related to the (eg: 'mysql', 'postgresql', 'jsf' etc) - */ + @Override public Span withSubtype(@Nullable String subtype) { this.subtype = normalizeEmpty(subtype); return this; } - /** - * Action related to this span (eg: 'query', 'render' etc) - */ + @Override public Span withAction(@Nullable String action) { this.action = normalizeEmpty(action); return this; @@ -204,11 +200,13 @@ public Throwable getStacktrace() { return stacktrace; } + @Override @Nullable public String getSubtype() { return subtype; } + @Override @Nullable public String getAction() { return action; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/SpanCount.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/SpanCount.java index c6fd7189456..ee183b2fd12 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/SpanCount.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/SpanCount.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.transaction; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import java.util.concurrent.atomic.AtomicInteger; 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 bfd849a4e72..e24e4ff9835 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 @@ -22,11 +22,16 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.Tracer; import co.elastic.apm.agent.impl.sampling.Sampler; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderSetter; +import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.HeaderRemover; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import co.elastic.apm.agent.util.ByteUtils; import co.elastic.apm.agent.util.HexUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.nio.charset.StandardCharsets; @@ -66,7 +71,7 @@ * 2, 1] * */ -public class TraceContext implements Recyclable { +public class TraceContext implements Recyclable, co.elastic.apm.agent.tracer.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"; @@ -450,28 +455,22 @@ public void resetState() { traceState.setSizeLimit(coreConfiguration.getTracestateSizeLimit()); } - /** - * The ID of the whole trace forest - * - * @return the trace id - */ + @Override public Id getTraceId() { return traceId; } + @Override public Id getId() { return id; } - /** - * The ID of the caller span (parent) - * - * @return the parent id - */ + @Override public Id getParentId() { return parentId; } + @Override public Id getTransactionId() { return transactionId; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceState.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceState.java index 385d2ce0b1d..84032c6cda5 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceState.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceState.java @@ -19,9 +19,10 @@ package co.elastic.apm.agent.impl.transaction; import co.elastic.apm.agent.configuration.converter.RoundedDoubleConverter; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.ArrayList; 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 868c23a119c..866a5303f97 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 @@ -30,6 +30,7 @@ import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.Timer; import co.elastic.apm.agent.util.KeyListConcurrentHashMap; +import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; import org.HdrHistogram.WriterReaderPhaser; import javax.annotation.Nullable; @@ -41,7 +42,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.agent.tracer.Transaction { private static final ThreadLocal labelsThreadLocal = new ThreadLocal() { @Override @@ -179,11 +180,6 @@ public Transaction startNoop() { return this; } - /** - * Context - *

- * Any arbitrary contextual information regarding the event, captured by the agent, optionally provided by the user - */ @Override public TransactionContext getContext() { return context; @@ -209,11 +205,7 @@ public String getResult() { return result; } - /** - * The result of the transaction. HTTP status code for HTTP-related - * transactions. This sets the result only if it is not already set. should be - * used for instrumentations - */ + @Override public Transaction withResultIfUnset(@Nullable String result) { if (this.result == null) { this.result = result; @@ -221,11 +213,7 @@ public Transaction withResultIfUnset(@Nullable String result) { return this; } - /** - * The result of the transaction. HTTP status code for HTTP-related - * transactions. This sets the result regardless of an already existing value. - * should be used for user defined results - */ + @Override public Transaction withResult(@Nullable String result) { this.result = result; return this; @@ -311,13 +299,12 @@ public void resetState() { // don't clear timerBySpanTypeAndSubtype map (see field-level javadoc) } + @Override public boolean isNoop() { return noop; } - /** - * Ignores this transaction, which makes it a noop so that it will not be reported to the APM Server. - */ + @Override public void ignoreTransaction() { noop = true; } @@ -355,6 +342,7 @@ protected void recycle() { tracer.recycle(this); } + @Override public void setFrameworkName(@Nullable String frameworkName) { if (frameworkNameSetByUser) { return; @@ -376,6 +364,7 @@ public String getFrameworkName() { return this.frameworkName; } + @Override public void setFrameworkVersion(@Nullable String frameworkVersion) { this.frameworkVersion = frameworkVersion; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/Labels.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/Labels.java index cafd069dbaa..c6a2e0475d9 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/Labels.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/Labels.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.metrics; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricSet.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricSet.java index 3da092f11e8..474a3827bef 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricSet.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricSet.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.metrics; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.Map; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/Timer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/Timer.java index 7846ab94fbd..fa77c72f3a8 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/Timer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/Timer.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.metrics; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; 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..09c9a839835 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 @@ -18,27 +18,7 @@ */ package co.elastic.apm.agent.objectpool; -/** - * Object pool - * - * @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 { - - /** - * Tries to reuse any existing instance if pool has any, otherwise creates a new un-pooled instance - * - * @return object instance, either from pool or freshly allocated - */ - T createInstance(); - - /** - * Recycles an object - * - * @param obj object to recycle - */ - void recycle(T obj); +public interface ObjectPool extends co.elastic.apm.agent.tracer.pooling.ObjectPool { /** * @return number of available objects in pool @@ -49,6 +29,4 @@ public interface ObjectPool { * @return number of times that objects could not be returned to the pool because the pool was already full */ long getGarbageCreated(); - - void clear(); } 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 4939117fb28..7d3daf1b351 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 @@ -24,10 +24,13 @@ import co.elastic.apm.agent.impl.transaction.TraceContext; import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; +import co.elastic.apm.agent.tracer.pooling.Allocator; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.jctools.queues.atomic.MpmcAtomicArrayQueue; -public class ObjectPoolFactory { +public class ObjectPoolFactory implements co.elastic.apm.agent.tracer.pooling.ObjectPoolFactory { + @Override 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/Resetter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Resetter.java index a68a0c10165..8738bd82be7 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Resetter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Resetter.java @@ -18,6 +18,8 @@ */ package co.elastic.apm.agent.objectpool; +import co.elastic.apm.agent.tracer.pooling.Recyclable; + /** * Defines reset strategy to use for a given pooled object type when they are returned to pool * diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/AbstractObjectPool.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/AbstractObjectPool.java index 3e19bdb4b18..0a79244bd16 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/AbstractObjectPool.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/AbstractObjectPool.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.objectpool.impl; -import co.elastic.apm.agent.objectpool.Allocator; import co.elastic.apm.agent.objectpool.ObjectPool; import co.elastic.apm.agent.objectpool.Resetter; +import co.elastic.apm.agent.tracer.pooling.Allocator; import javax.annotation.Nullable; import java.util.concurrent.atomic.AtomicInteger; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/ListBasedObjectPool.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/ListBasedObjectPool.java index c0f928b0770..5efc18d9650 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/ListBasedObjectPool.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/ListBasedObjectPool.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.objectpool.impl; -import co.elastic.apm.agent.objectpool.Allocator; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.objectpool.Resetter; +import co.elastic.apm.agent.tracer.pooling.Allocator; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/QueueBasedObjectPool.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/QueueBasedObjectPool.java index 437214c4789..a58db30ad6c 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/QueueBasedObjectPool.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/QueueBasedObjectPool.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.objectpool.impl; -import co.elastic.apm.agent.objectpool.Allocator; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.objectpool.Resetter; +import co.elastic.apm.agent.tracer.pooling.Allocator; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.Queue; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/BinaryHeaderMap.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/BinaryHeaderMap.java index 129726f2354..3fb610014bc 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/BinaryHeaderMap.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/BinaryHeaderMap.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.util; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.nio.Buffer; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/NoRandomAccessMap.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/NoRandomAccessMap.java index f00b57b6733..3017e123538 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/NoRandomAccessMap.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/NoRandomAccessMap.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.util; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.ArrayList; 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..279a3f7f306 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 @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.util; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.ArrayList; @@ -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.agent.tracer.metadata.PotentiallyMultiValuedMap { private final List keys; private final List values; @@ -59,6 +59,7 @@ public PotentiallyMultiValuedMap(int initialSize) { * @param key The key. * @param value The value. */ + @Override public void add(String key, String value) { final int index = indexOfIgnoreCase(key); if (index >= 0) { @@ -102,6 +103,7 @@ private int indexOfIgnoreCase(String key) { * @param key The key you want to get the associated value for. * @return The first value which is associated with a given key. */ + @Override @Nullable public String getFirst(String key) { Object valueOrValueList = get(key); @@ -112,6 +114,7 @@ public String getFirst(String key) { } } + @Override @Nullable public Object get(String key) { final int index = indexOfIgnoreCase(key); @@ -155,6 +158,7 @@ private void convertValueToMultiValue(int index, String previousValue, String va values.set(index, valueList); } + @Override public boolean isEmpty() { return keys.isEmpty(); } @@ -194,6 +198,7 @@ public void set(int index, String value) { values.set(index, value); } + @Override public boolean containsIgnoreCase(String key) { return indexOfIgnoreCase(key) != -1; } 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..29c6a5fb5e4 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 @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.impl; -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.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderSetter; +import co.elastic.apm.agent.tracer.dispatch.HeaderRemover; import javax.annotation.Nullable; import java.util.HashMap; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerTest.java index cf3b7b6da4d..33167e50545 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerTest.java @@ -37,6 +37,7 @@ import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import co.elastic.apm.agent.report.ApmServerClient; import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.tracer.Scope; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/TextHeaderMapAccessor.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/TextHeaderMapAccessor.java index e66e8766787..37f0ee1f3bc 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/TextHeaderMapAccessor.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/TextHeaderMapAccessor.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.impl; -import co.elastic.apm.agent.impl.transaction.AbstractHeaderGetter; -import co.elastic.apm.agent.impl.transaction.HeaderRemover; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.agent.tracer.dispatch.AbstractHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.HeaderRemover; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import javax.annotation.Nullable; import java.util.Map; 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..92ee7e5af47 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.agent.tracer.dispatch.TextHeaderGetter; import org.junit.jupiter.api.Test; import java.util.ArrayList; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContextTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContextTest.java index 1888f158651..853586115d9 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContextTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContextTest.java @@ -31,6 +31,7 @@ import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import co.elastic.apm.agent.util.HexUtils; import co.elastic.apm.agent.util.PotentiallyMultiValuedMap; +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderSetter; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/NoopObjectPool.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/NoopObjectPool.java index 32f5ebc2517..d7e6544cb44 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/NoopObjectPool.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/NoopObjectPool.java @@ -19,6 +19,8 @@ package co.elastic.apm.agent.objectpool; import co.elastic.apm.agent.objectpool.impl.AbstractObjectPool; +import co.elastic.apm.agent.tracer.pooling.Allocator; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/TestObjectPoolFactory.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/TestObjectPoolFactory.java index bd3363dc2ab..eb5b121e4f0 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/TestObjectPoolFactory.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/TestObjectPoolFactory.java @@ -24,6 +24,8 @@ import co.elastic.apm.agent.impl.transaction.TraceContext; import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.objectpool.impl.BookkeeperObjectPool; +import co.elastic.apm.agent.tracer.pooling.Allocator; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import java.util.ArrayList; import java.util.Collection; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/TestRecyclable.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/TestRecyclable.java index 6d84c4d0e5d..372ee75ece7 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/TestRecyclable.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/TestRecyclable.java @@ -18,6 +18,8 @@ */ package co.elastic.apm.agent.objectpool; +import co.elastic.apm.agent.tracer.pooling.Recyclable; + public class TestRecyclable implements Recyclable { private int state; 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..a9f9e5ca26f 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.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.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/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 f6f051fe2dd..4c9e6692590 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 @@ -21,9 +21,9 @@ 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.agent.tracer.pooling.Allocator; import org.apache.http.concurrent.FutureCallback; import org.apache.http.nio.protocol.HttpAsyncRequestProducer; import org.apache.http.protocol.HttpContext; 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..428c7f8a64c 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 @@ -20,7 +20,7 @@ import co.elastic.apm.agent.impl.transaction.Outcome; import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.concurrent.FutureCallback; 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..b01bf02b6ad 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 @@ -22,7 +22,7 @@ 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.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; 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..1f7677858c6 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.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.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/HeaderExtractorBridge.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/HeaderExtractorBridge.java index fb86e718e2f..dde4a042b24 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,10 +18,10 @@ */ 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.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.dispatch.AbstractHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import javax.annotation.Nullable; import java.lang.invoke.MethodHandle; 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..bafe9a018df 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,9 +18,9 @@ */ package co.elastic.apm.agent.pluginapi; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import javax.annotation.Nullable; import java.lang.invoke.MethodHandle; 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..ea3a260d8c7 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,9 +18,9 @@ */ package co.elastic.apm.agent.pluginapi; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import javax.annotation.Nullable; import java.lang.invoke.MethodHandle; diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java index bb4ed04e091..3739d397998 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java @@ -20,7 +20,6 @@ import co.elastic.apm.AbstractApiTest; import co.elastic.apm.agent.configuration.ServiceInfo; -import co.elastic.apm.agent.impl.Scope; import co.elastic.apm.agent.impl.TextHeaderMapAccessor; import co.elastic.apm.agent.impl.TracerInternalApiUtils; import co.elastic.apm.agent.impl.transaction.AbstractSpan; @@ -148,13 +147,13 @@ void testAutomaticAndManualTransactions() { void testGetId_distributedTracingEnabled() { co.elastic.apm.agent.impl.transaction.Transaction transaction = tracer.startRootTransaction(null).withType(Transaction.TYPE_REQUEST); - try (Scope scope = transaction.activateInScope()) { + try (co.elastic.apm.agent.tracer.Scope scope = transaction.activateInScope()) { assertThat(ElasticApm.currentTransaction().getId()).isEqualTo(transaction.getTraceContext().getId().toString()); assertThat(ElasticApm.currentTransaction().getTraceId()).isEqualTo(transaction.getTraceContext().getTraceId().toString()); assertThat(ElasticApm.currentSpan().getId()).isEqualTo(transaction.getTraceContext().getId().toString()); assertThat(ElasticApm.currentSpan().getTraceId()).isEqualTo(transaction.getTraceContext().getTraceId().toString()); co.elastic.apm.agent.impl.transaction.Span span = transaction.createSpan().withType("db").withSubtype("mysql").withName("SELECT"); - try (Scope spanScope = span.activateInScope()) { + try (co.elastic.apm.agent.tracer.Scope spanScope = span.activateInScope()) { assertThat(ElasticApm.currentSpan().getId()).isEqualTo(span.getTraceContext().getId().toString()); assertThat(ElasticApm.currentSpan().getTraceId()).isEqualTo(span.getTraceContext().getTraceId().toString()); } finally { 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..5f474277915 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.agent.tracer.dispatch.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/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 4abd688d61f..b0c26d3f30b 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 @@ -24,9 +24,9 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.GlobalTracer; 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.agent.common.util.WildcardMatcher; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import com.amazonaws.AmazonWebServiceRequest; import com.amazonaws.Request; import com.amazonaws.http.ExecutionContext; diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/SQSJmsClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/SQSJmsClientIT.java index c78d443339d..9bbcb8fe7b2 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/SQSJmsClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/SQSJmsClientIT.java @@ -22,11 +22,11 @@ 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.Scope; 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.Transaction; +import co.elastic.apm.agent.tracer.Scope; import com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper; import com.amazon.sqs.javamessaging.ProviderConfiguration; import com.amazon.sqs.javamessaging.SQSConnection; 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 4ba86288bc2..c2f70d0fd04 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 @@ -22,8 +22,8 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.GlobalTracer; 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.agent.tracer.dispatch.TextHeaderSetter; import software.amazon.awssdk.core.SdkRequest; import software.amazon.awssdk.core.SdkResponse; import software.amazon.awssdk.core.client.handler.ClientExecutionParams; @@ -46,7 +46,7 @@ @SuppressWarnings({"rawtypes", "unchecked"}) public class SQSHelper extends AbstractSQSInstrumentationHelper implements TextHeaderSetter> { - + private static final SQSHelper INSTANCE = new SQSHelper(GlobalTracer.requireTracerImpl()); public static SQSHelper getInstance() { diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/SQSJmsClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/SQSJmsClientIT.java index 9457bcefec0..b2c23b8d20e 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/SQSJmsClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/SQSJmsClientIT.java @@ -22,11 +22,11 @@ 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.Scope; 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.Transaction; +import co.elastic.apm.agent.tracer.Scope; import com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper; import com.amazon.sqs.javamessaging.ProviderConfiguration; import com.amazon.sqs.javamessaging.SQSConnection; 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 6745039144e..30ece2f6809 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 @@ -21,8 +21,8 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; 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.agent.tracer.dispatch.TextHeaderGetter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 a6cacbee6b5..dbc2273973e 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 @@ -19,7 +19,7 @@ package co.elastic.apm.agent.awssdk.common; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.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/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 35a8cab07c1..6e2f121f147 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 @@ -24,13 +24,13 @@ import co.elastic.apm.agent.impl.context.Message; import co.elastic.apm.agent.impl.transaction.AbstractSpan; 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.common.util.WildcardMatcher; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.util.PrivilegedActionUtils; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import javax.annotation.Nullable; import java.net.URI; diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/main/java/co/elastic/apm/agent/awslambda/MapTextHeaderGetter.java b/apm-agent-plugins/apm-awslambda-plugin/src/main/java/co/elastic/apm/agent/awslambda/MapTextHeaderGetter.java index 2f08066bae7..222cfff053d 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/main/java/co/elastic/apm/agent/awslambda/MapTextHeaderGetter.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/main/java/co/elastic/apm/agent/awslambda/MapTextHeaderGetter.java @@ -18,14 +18,15 @@ */ package co.elastic.apm.agent.awslambda; -import co.elastic.apm.agent.impl.transaction.AbstractHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; + +import co.elastic.apm.agent.tracer.dispatch.AbstractHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import javax.annotation.Nullable; import java.util.Map; public class MapTextHeaderGetter extends AbstractHeaderGetter> implements - TextHeaderGetter> { + TextHeaderGetter> { public static final MapTextHeaderGetter INSTANCE = new MapTextHeaderGetter(); diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/main/java/co/elastic/apm/agent/awslambda/SNSMessageAttributesGetter.java b/apm-agent-plugins/apm-awslambda-plugin/src/main/java/co/elastic/apm/agent/awslambda/SNSMessageAttributesGetter.java index f13442a5eae..846f2d3170a 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/main/java/co/elastic/apm/agent/awslambda/SNSMessageAttributesGetter.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/main/java/co/elastic/apm/agent/awslambda/SNSMessageAttributesGetter.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.awslambda; -import co.elastic.apm.agent.impl.transaction.AbstractHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.AbstractHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import com.amazonaws.services.lambda.runtime.events.SNSEvent; import javax.annotation.Nullable; diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/main/java/co/elastic/apm/agent/awslambda/SQSMessageAttributesGetter.java b/apm-agent-plugins/apm-awslambda-plugin/src/main/java/co/elastic/apm/agent/awslambda/SQSMessageAttributesGetter.java index e7e877f6da9..93a18bb89f5 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/main/java/co/elastic/apm/agent/awslambda/SQSMessageAttributesGetter.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/main/java/co/elastic/apm/agent/awslambda/SQSMessageAttributesGetter.java @@ -18,14 +18,14 @@ */ package co.elastic.apm.agent.awslambda; -import co.elastic.apm.agent.impl.transaction.AbstractHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.AbstractHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import com.amazonaws.services.lambda.runtime.events.SQSEvent; import javax.annotation.Nullable; public class SQSMessageAttributesGetter extends AbstractHeaderGetter implements - TextHeaderGetter { + TextHeaderGetter { public static final SQSMessageAttributesGetter INSTANCE = new SQSMessageAttributesGetter(); 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..3ef7b6518ca 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.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.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..0bcda9d57cb 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.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import org.apache.dubbo.rpc.RpcContext; import javax.annotation.Nullable; 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 b071200946f..0a67e20e88d 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 @@ -24,12 +24,12 @@ 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.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.util.IOUtils; import co.elastic.apm.agent.util.LoggerUtils; +import co.elastic.apm.agent.tracer.pooling.Allocator; import org.apache.http.HttpEntity; import org.apache.http.HttpHost; import org.elasticsearch.client.Response; 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..369ed0c2174 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 @@ -21,7 +21,7 @@ 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.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseListener; 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..0169579079b 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.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import com.twitter.finagle.http.Request; import scala.Option; import scala.collection.Iterator; diff --git a/apm-agent-plugins/apm-grails-plugin/src/test/java/co/elastic/apm/agent/grails/GrailsTransactionNameInstrumentationTest.java b/apm-agent-plugins/apm-grails-plugin/src/test/java/co/elastic/apm/agent/grails/GrailsTransactionNameInstrumentationTest.java index 1793cc771fe..225ef4c222c 100644 --- a/apm-agent-plugins/apm-grails-plugin/src/test/java/co/elastic/apm/agent/grails/GrailsTransactionNameInstrumentationTest.java +++ b/apm-agent-plugins/apm-grails-plugin/src/test/java/co/elastic/apm/agent/grails/GrailsTransactionNameInstrumentationTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.grails; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.Scope; import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.tracer.Scope; import grails.core.GrailsControllerClass; import grails.web.mapping.UrlMappingInfo; import org.grails.web.mapping.mvc.GrailsControllerUrlMappingInfo; 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..84cd71b62a9 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 @@ -21,17 +21,16 @@ 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.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; +import co.elastic.apm.agent.tracer.dispatch.AbstractHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import io.grpc.CallOptions; import io.grpc.ClientCall; import io.grpc.Metadata; 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..974c9ba66c8 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,15 @@ 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.tracer.dispatch.TextHeaderGetter; import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.http.HttpHeader; diff --git a/apm-agent-plugins/apm-jaxws-plugin/src/test/java/co/elastic/apm/agent/jaxws/AbstractJaxWsInstrumentationTest.java b/apm-agent-plugins/apm-jaxws-plugin/src/test/java/co/elastic/apm/agent/jaxws/AbstractJaxWsInstrumentationTest.java index 8bf71c5952f..55f5e6b06ee 100644 --- a/apm-agent-plugins/apm-jaxws-plugin/src/test/java/co/elastic/apm/agent/jaxws/AbstractJaxWsInstrumentationTest.java +++ b/apm-agent-plugins/apm-jaxws-plugin/src/test/java/co/elastic/apm/agent/jaxws/AbstractJaxWsInstrumentationTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.jaxws; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.Scope; import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.tracer.Scope; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; 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..566c1be7977 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.agent.tracer.dispatch.TextHeaderSetter; import java.util.Collections; import java.util.List; 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..a91239d4b71 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.agent.tracer.dispatch.AbstractHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import com.sun.net.httpserver.Headers; import javax.annotation.Nullable; 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..292a4d7756c 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,12 +18,12 @@ */ 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.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.dispatch.AbstractHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import javax.annotation.Nonnull; import javax.annotation.Nullable; 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..58215f38ca1 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 @@ -19,7 +19,7 @@ package co.elastic.apm.agent.kafka.helper; import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.apache.kafka.clients.producer.Callback; import org.apache.kafka.clients.producer.RecordMetadata; 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 8239e6bf67b..39a47ddb328 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 @@ -23,10 +23,10 @@ import co.elastic.apm.agent.impl.GlobalTracer; import co.elastic.apm.agent.impl.transaction.Span; 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 co.elastic.apm.agent.tracer.pooling.Allocator; import org.apache.kafka.clients.producer.Callback; import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.ProducerRecord; 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..450512df574 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.agent.tracer.dispatch.BinaryHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderSetter; +import co.elastic.apm.agent.tracer.dispatch.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-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/correlation/CorrelationIdMapAdapterTest.java b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/correlation/CorrelationIdMapAdapterTest.java index 638315755ca..cf43081db32 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/correlation/CorrelationIdMapAdapterTest.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/correlation/CorrelationIdMapAdapterTest.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.GlobalTracer; -import co.elastic.apm.agent.impl.Scope; import co.elastic.apm.agent.impl.transaction.Span; import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.tracer.Scope; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; 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..fd7b5a45eb2 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.agent.tracer.dispatch.AbstractHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.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..340f4927def 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.agent.tracer.dispatch.TextHeaderSetter; import okhttp3.Request; @SuppressWarnings("unused") 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..7f4ebbda43e 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.agent.tracer.dispatch.AbstractHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.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..603f223a12e 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.agent.tracer.dispatch.TextHeaderSetter; import com.squareup.okhttp.Request; @SuppressWarnings("unused") diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelBridgeContext.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelBridgeContext.java index 0cbb8c95f5c..09e5893fdfe 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelBridgeContext.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelBridgeContext.java @@ -107,7 +107,7 @@ public OTelBridgeContext activate() { } @Override - public co.elastic.apm.agent.impl.Scope activateInScope() { + public co.elastic.apm.agent.tracer.Scope activateInScope() { return tracer.activateInScope(this); } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/ElasticOpenTelemetryTest.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/ElasticOpenTelemetryTest.java index 3912233ef1b..8fb9f626a7f 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/ElasticOpenTelemetryTest.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/ElasticOpenTelemetryTest.java @@ -340,7 +340,7 @@ public void contextActivationFromElastic() { ElasticContext bridgedContext = checkBridgedContext(context); // activate context from elastic API using a bridged context - try (co.elastic.apm.agent.impl.Scope scope = bridgedContext.activateInScope()) { + try (co.elastic.apm.agent.tracer.Scope scope = bridgedContext.activateInScope()) { checkCurrentContext(context, "elastic and otel contexts should be the same"); @@ -481,7 +481,7 @@ public void elasticSpanOverOtelSpan() { assertThat(transaction).isNotNull(); co.elastic.apm.agent.impl.transaction.Span elasticSpan = transaction.createSpan(); - try (co.elastic.apm.agent.impl.Scope elasticScope = elasticSpan.activateInScope()) { + try (co.elastic.apm.agent.tracer.Scope elasticScope = elasticSpan.activateInScope()) { assertThat(tracer.getActiveSpan()).isNotNull(); tracer.getActiveSpan().withName("elastic span"); } finally { diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/specs/OTelBridgeStepsDefinitions.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/specs/OTelBridgeStepsDefinitions.java index d86040f188a..f9518627880 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/specs/OTelBridgeStepsDefinitions.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/specs/OTelBridgeStepsDefinitions.java @@ -18,7 +18,6 @@ */ package specs; -import co.elastic.apm.agent.impl.Scope; import co.elastic.apm.agent.impl.context.ServiceTarget; import co.elastic.apm.agent.impl.transaction.AbstractSpan; import co.elastic.apm.agent.impl.transaction.OTelSpanKind; @@ -28,6 +27,7 @@ import co.elastic.apm.agent.opentelemetry.global.ElasticOpenTelemetry; import co.elastic.apm.agent.opentelemetry.tracing.ElasticOpenTelemetryTest; import co.elastic.apm.agent.opentelemetry.tracing.OTelSpan; +import co.elastic.apm.agent.tracer.Scope; import io.cucumber.java.Before; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; 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..ec5b3d1ecfe 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,8 +18,8 @@ */ package co.elastic.apm.agent.opentracingimpl; -import co.elastic.apm.agent.impl.transaction.TextHeaderGetter; -import co.elastic.apm.agent.impl.transaction.TextHeaderSetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import javax.annotation.Nullable; import java.util.Map; 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 d532f0da64f..58fb78f584c 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 @@ -25,10 +25,10 @@ import co.elastic.apm.agent.impl.transaction.StackFrame; import co.elastic.apm.agent.impl.transaction.TraceContext; import co.elastic.apm.agent.objectpool.ObjectPool; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.profiler.collections.LongHashSet; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.io.IOException; 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 f58a90aa592..9f9ba665965 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 @@ -26,13 +26,13 @@ import co.elastic.apm.agent.impl.transaction.StackFrame; import co.elastic.apm.agent.impl.transaction.TraceContext; 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.objectpool.impl.ListBasedObjectPool; import co.elastic.apm.agent.profiler.asyncprofiler.AsyncProfiler; import co.elastic.apm.agent.profiler.asyncprofiler.JfrParser; import co.elastic.apm.agent.profiler.collections.Long2ObjectHashMap; import co.elastic.apm.agent.util.ExecutorUtils; +import co.elastic.apm.agent.tracer.pooling.Allocator; import com.lmax.disruptor.EventFactory; import com.lmax.disruptor.EventPoller; import com.lmax.disruptor.EventTranslatorTwoArg; diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/BufferedFile.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/BufferedFile.java index 08952235244..29aab3cce9e 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/BufferedFile.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/BufferedFile.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.profiler.asyncprofiler; -import co.elastic.apm.agent.objectpool.Recyclable; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.io.File; diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/JfrParser.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/JfrParser.java index 6239871f6eb..c28e76c64a9 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/JfrParser.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/asyncprofiler/JfrParser.java @@ -20,13 +20,13 @@ import co.elastic.apm.agent.impl.transaction.StackFrame; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.profiler.collections.Int2IntHashMap; import co.elastic.apm.agent.profiler.collections.Int2ObjectHashMap; import co.elastic.apm.agent.profiler.collections.Long2LongHashMap; import co.elastic.apm.agent.profiler.collections.Long2ObjectHashMap; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.io.File; diff --git a/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerTest.java b/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerTest.java index 374b4b644e4..6ae8b853e95 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerTest.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerTest.java @@ -23,11 +23,11 @@ import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.configuration.converter.TimeDuration; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.Scope; import co.elastic.apm.agent.impl.transaction.Span; import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.testutils.DisabledOnAppleSilicon; +import co.elastic.apm.agent.tracer.Scope; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; 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..9470e2e9443 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.agent.tracer.dispatch.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..8ced8023f35 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.agent.tracer.dispatch.TextHeaderSetter; import java.util.HashMap; diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/test/java/co/elastic/apm/agent/rabbitmq/header/RabbitMQTextHeaderGetterTest.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/test/java/co/elastic/apm/agent/rabbitmq/header/RabbitMQTextHeaderGetterTest.java index 3aad1ceb6a3..c5417a1f152 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/test/java/co/elastic/apm/agent/rabbitmq/header/RabbitMQTextHeaderGetterTest.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/test/java/co/elastic/apm/agent/rabbitmq/header/RabbitMQTextHeaderGetterTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.rabbitmq.header; import co.elastic.apm.agent.impl.transaction.AbstractTextHeaderGetterTest; -import co.elastic.apm.agent.impl.transaction.HeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; import com.rabbitmq.client.AMQP; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; 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 c18555e94fc..77a06cb2b5c 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 @@ -21,7 +21,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.Scope; import co.elastic.apm.agent.impl.context.Request; import co.elastic.apm.agent.impl.context.Response; import co.elastic.apm.agent.impl.transaction.AbstractSpan; @@ -33,9 +32,9 @@ import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.servlet.adapter.ServletApiAdapter; import co.elastic.apm.agent.util.TransactionNameUtils; +import co.elastic.apm.agent.tracer.Scope; import javax.annotation.Nullable; -import java.security.Principal; import java.util.Arrays; import java.util.Enumeration; import java.util.List; 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..64c4aab47fe 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 @@ -19,8 +19,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.agent.servlet.helper.JakartaServletRequestHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import jakarta.servlet.DispatcherType; import jakarta.servlet.FilterConfig; import jakarta.servlet.RequestDispatcher; 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..4911660b2f1 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 @@ -19,8 +19,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.agent.servlet.helper.JavaxServletRequestHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import javax.annotation.Nullable; import javax.servlet.DispatcherType; 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..5a4b3040ecd 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 @@ -19,8 +19,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.agent.sdk.state.GlobalState; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import javax.annotation.Nullable; import java.security.Principal; 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..08af6e580c2 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.agent.tracer.dispatch.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..2e0947ba2ef 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 @@ -20,10 +20,11 @@ import co.elastic.apm.agent.impl.context.Response; import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.servlet.ServletTransactionHelper; import javax.annotation.Nullable; + +import co.elastic.apm.agent.tracer.pooling.Recyclable; import jakarta.servlet.AsyncContext; import jakarta.servlet.AsyncEvent; import jakarta.servlet.AsyncListener; 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 d14348df586..7b3d07ab319 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 @@ -21,9 +21,9 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; 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.agent.servlet.ServletTransactionHelper; +import co.elastic.apm.agent.tracer.pooling.Allocator; import jakarta.servlet.AsyncContext; import jakarta.servlet.ServletRequest; 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..7e03fa2d984 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.agent.tracer.dispatch.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..0a86b6ff831 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 @@ -20,8 +20,8 @@ import co.elastic.apm.agent.impl.context.Response; import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.objectpool.Recyclable; import co.elastic.apm.agent.servlet.ServletTransactionHelper; +import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import javax.servlet.AsyncContext; 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 4d23ecdbf63..7384f2a0a37 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 @@ -21,9 +21,9 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; 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.agent.servlet.ServletTransactionHelper; +import co.elastic.apm.agent.tracer.pooling.Allocator; import javax.servlet.AsyncContext; import javax.servlet.ServletRequest; 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..4a917a505fb 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.agent.tracer.dispatch.TextHeaderGetter; import javax.servlet.http.HttpServletRequest; import java.util.Enumeration; 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..ff04b829bcb 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.agent.tracer.dispatch.TextHeaderSetter; import org.springframework.http.HttpRequest; public class SpringRestRequestHeaderSetter implements TextHeaderSetter { 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..9422b41253e 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.agent.tracer.dispatch.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-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..e4e146d691b 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.agent.tracer.dispatch.TextHeaderGetter; import org.springframework.http.HttpHeaders; import javax.annotation.Nullable; 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..b90c1d533ae 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,10 +18,10 @@ */ 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.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import javax.annotation.Nullable; import java.net.HttpURLConnection; diff --git a/apm-agent-plugins/apm-urlconnection-plugin/src/test/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentationTest.java b/apm-agent-plugins/apm-urlconnection-plugin/src/test/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentationTest.java index b17231d5cad..323ff2f0713 100644 --- a/apm-agent-plugins/apm-urlconnection-plugin/src/test/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentationTest.java +++ b/apm-agent-plugins/apm-urlconnection-plugin/src/test/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentationTest.java @@ -19,10 +19,10 @@ package co.elastic.apm.agent.urlconnection; import co.elastic.apm.agent.httpclient.AbstractHttpClientInstrumentationTest; -import co.elastic.apm.agent.impl.Scope; import co.elastic.apm.agent.impl.context.Http; import co.elastic.apm.agent.impl.transaction.AbstractSpan; import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.tracer.Scope; import org.junit.Ignore; import org.junit.Test; @@ -134,7 +134,7 @@ public void testGetResponseCodeWithUnhandledException() { } assertThat(reporter.getErrors()).hasSize(1); - + assertThat(reporter.getFirstSpan(500)).isNotNull(); assertThat(reporter.getSpans()).hasSize(1); 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..107f751c8c3 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 @@ -22,7 +22,7 @@ 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.agent.tracer.dispatch.TextHeaderSetter; import io.vertx.core.http.HttpClientRequest; import io.vertx.ext.web.client.HttpResponse; import io.vertx.ext.web.client.impl.HttpContext; 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..bd3141ff905 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.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; import io.vertx.core.MultiMap; import javax.annotation.Nullable; diff --git a/apm-agent-tracer/pom.xml b/apm-agent-tracer/pom.xml new file mode 100644 index 00000000000..f668f9cacf3 --- /dev/null +++ b/apm-agent-tracer/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + co.elastic.apm + apm-agent-parent + 1.36.1-SNAPSHOT + + + apm-agent-tracer + ${project.groupId}:${project.artifactId} + + + ${project.basedir}/.. + + + diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/AbstractContext.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/AbstractContext.java new file mode 100644 index 00000000000..47871671d9f --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/AbstractContext.java @@ -0,0 +1,26 @@ +/* + * 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.agent.tracer; + +import co.elastic.apm.agent.tracer.metadata.Message; + +public interface AbstractContext { + + Message getMessage(); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/AbstractSpan.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/AbstractSpan.java new file mode 100644 index 00000000000..2bc6570b17d --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/AbstractSpan.java @@ -0,0 +1,167 @@ +/* + * 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.agent.tracer; + +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderSetter; +import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; + +import javax.annotation.Nullable; + +public interface AbstractSpan> extends ElasticContext { + + AbstractContext getContext(); + + TraceContext getTraceContext(); + + /** + * Sets Trace context binary headers, using this context as parent, on the provided carrier using the provided setter + * + * @param carrier the binary headers carrier + * @param headerSetter a setter implementing the actual addition of headers to the headers carrier + * @param the header carrier type, for example - a Kafka record + * @return true if Trace Context headers were set; false otherwise + */ + boolean propagateTraceContext(C carrier, BinaryHeaderSetter headerSetter); + + /** + * Sets Trace context text headers, using this context as parent, on the provided carrier using the provided setter + * + * @param carrier the text headers carrier + * @param headerSetter a setter implementing the actual addition of headers to the headers carrier + * @param the header carrier type, for example - an HTTP request + */ + void propagateTraceContext(C carrier, TextHeaderSetter headerSetter); + + Span createSpan(); + + /** + * Creates a child Span representing a remote call event, unless this TraceContextHolder already represents an exit event. + * If current TraceContextHolder is representing an Exit- returns null + * + * @return an Exit span if this TraceContextHolder is not an exit span, null otherwise + */ + @Nullable + Span createExitSpan(); + + void end(); + + T captureException(@Nullable Throwable t); + + @Nullable + String getType(); + + T withType(@Nullable String type); + + /** + * Determines whether to discard the span. + * Only spans that return {@code false} are reported. + *

+ * A span is discarded if it is discardable and {@linkplain #requestDiscarding() requested to be discarded}. + *

+ * + * @return {@code true}, if the span should be discarded, {@code false} otherwise. + */ + boolean isDiscarded(); + + /** + * Requests this span to be discarded, even if it's sampled. + *

+ * Whether the span can actually be discarded is determined by {@link #isDiscarded()} + *

+ */ + T requestDiscarding(); + + /** + * Sets this context as non-discardable, + * meaning that {@link AbstractSpan#isDiscarded()} will return {@code false}, + * even if {@link AbstractSpan#requestDiscarding()} has been called. + */ + void setNonDiscardable(); + + boolean isFinished(); + + boolean isSampled(); + + boolean addLink(BinaryHeaderGetter headerGetter, @Nullable C carrier); + + boolean addLink(TextHeaderGetter headerGetter, @Nullable C carrier); + + /** + * Appends a string to the name. + *

+ * This method helps to avoid the memory allocations of string concatenations + * as the underlying {@link StringBuilder} instance will be reused. + *

+ * + * @param cs the char sequence to append to the name + * @return {@code this}, for chaining + */ + 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); + + /** + * Resets and returns the name {@link StringBuilder} if the provided priority is {@code >=} the current priority. + * Otherwise, returns {@code null} + * + * @param namePriority the priority for the name. See also the {@code AbstractSpan#PRIO_*} constants. + * @return the name {@link StringBuilder} if the provided priority is {@code >=} the current priority, {@code null} otherwise. + */ + @Nullable + StringBuilder getAndOverrideName(int namePriority); + + /** + * Resets and returns the name {@link StringBuilder} if one of the following applies: + *
    + *
  • the provided priority is {@code >} the current priority
  • + *
  • the provided priority is {@code ==} the current priority AND {@code overrideIfSamePriority} is {@code true}
  • + *
+ * Otherwise, returns {@code null} + * + * @param namePriority the priority for the name. See also the {@code AbstractSpan#PRIO_*} constants. + * @param overrideIfSamePriority specifies whether the existing name should be overridden if {@code namePriority} equals the priority used to set the current name + * @return the name {@link StringBuilder} if the provided priority is sufficient for overriding, {@code null} otherwise. + */ + @Nullable + StringBuilder getAndOverrideName(int namePriority, boolean overrideIfSamePriority); + + /** + * @return user outcome if set, otherwise outcome value + */ + Outcome getOutcome(); + + T withOutcome(Outcome outcome); + + T withSync(boolean sync); + + void incrementReferences(); + + void decrementReferences(); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/ElasticContext.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/ElasticContext.java new file mode 100644 index 00000000000..7d03eab939a --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/ElasticContext.java @@ -0,0 +1,43 @@ +/* + * 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.agent.tracer; + +public interface ElasticContext> { + + /** + * Makes the context active + * + * @return this + */ + T activate(); + + /** + * Deactivates context + * + * @return this + */ + T deactivate(); + + /** + * Activates context in a scope + * + * @return active scope that will deactivate context when closed + */ + Scope activateInScope(); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Id.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Id.java new file mode 100644 index 00000000000..7024fa50cb0 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Id.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.agent.tracer; + +public interface Id { + boolean isEmpty(); + + void setToRandomValue(); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Outcome.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Outcome.java new file mode 100644 index 00000000000..2f23852a13c --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/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.agent.tracer; + +public interface Outcome { + + String name(); +} diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Scope.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Scope.java similarity index 76% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Scope.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Scope.java index 81ee98d916c..faa03a30d3b 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Scope.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Scope.java @@ -16,15 +16,13 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.impl; - -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +package co.elastic.apm.agent.tracer; /** * Within a scope, a {@link AbstractSpan} is active on the current thread. * Calling {@link #close()} detaches them from the active thread. * In a scope, you can get the currently active {@link AbstractSpan} via - * {@link ElasticApmTracer#getActive()}. + * {@link Tracer#getActive()}. *

* During the duration of a {@link AbstractSpan}, * it can be active multiple times on multiple threads. @@ -34,24 +32,15 @@ * These types of application still might find it useful to scope a {@link AbstractSpan} on the currently processing thread. * For example, an instrumentation for {@link java.util.concurrent.ExecutorService} might want to propagate the currently * active {@link AbstractSpan} to thread which runs {@link java.util.concurrent.ExecutorService#execute(Runnable)}, - * so that {@link ElasticApmTracer#getActive()} returns the expected {@link AbstractSpan}. + * so that {@link Tracer#getActive()} returns the expected {@link AbstractSpan}. *

*

- * Note: {@link #close() closing} a scope does not {@link co.elastic.apm.agent.impl.transaction.AbstractSpan#end() end} it's active - * {@link co.elastic.apm.agent.impl.transaction.AbstractSpan}. + * Note: {@link #close() closing} a scope does not {@link AbstractSpan#end() end} it's active + * {@link AbstractSpan}. *

*/ public interface Scope extends AutoCloseable { @Override void close(); - - enum NoopScope implements Scope { - INSTANCE; - - @Override - public void close() { - // noop - } - } } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/ServiceTarget.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/ServiceTarget.java new file mode 100644 index 00000000000..b6a3648c6b7 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/ServiceTarget.java @@ -0,0 +1,37 @@ +/* + * 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.agent.tracer; + +import javax.annotation.Nullable; + +/** + * Represents a target service + */ +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-tracer/src/main/java/co/elastic/apm/agent/tracer/Span.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Span.java new file mode 100644 index 00000000000..3f9a8fee7b3 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Span.java @@ -0,0 +1,45 @@ +/* + * 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.agent.tracer; + +import javax.annotation.Nullable; + +public interface Span> extends AbstractSpan { + + @Override + SpanContext getContext(); + + @Nullable + String getSubtype(); + + /** + * Sets the span's subtype, related to the (eg: 'mysql', 'postgresql', 'jsf' etc) + */ + T withSubtype(@Nullable String subtype); + + boolean isExit(); + + @Nullable + String getAction(); + + /** + * Action related to this span (eg: 'query', 'render' etc) + */ + T withAction(@Nullable String action); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/SpanContext.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/SpanContext.java new file mode 100644 index 00000000000..b70f78df54f --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/SpanContext.java @@ -0,0 +1,43 @@ +/* + * 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.agent.tracer; + +import co.elastic.apm.agent.tracer.metadata.Db; +import co.elastic.apm.agent.tracer.metadata.Destination; +import co.elastic.apm.agent.tracer.metadata.Http; + +public interface SpanContext extends AbstractContext { + + ServiceTarget getServiceTarget(); + + /** + * An object containing contextual data for service maps + */ + Destination getDestination(); + + /** + * An object containing contextual data for database spans + */ + Db getDb(); + + /** + * An object containing contextual data for outgoing HTTP spans + */ + Http getHttp(); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/TraceContext.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/TraceContext.java new file mode 100644 index 00000000000..06389fad7e6 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/TraceContext.java @@ -0,0 +1,40 @@ +/* + * 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.agent.tracer; + +public interface TraceContext { + + Id getId(); + + Id getTransactionId(); + + /** + * The ID of the whole trace forest + * + * @return the trace id + */ + Id getTraceId(); + + /** + * The ID of the caller span (parent) + * + * @return the parent id + */ + Id getParentId(); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Tracer.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Tracer.java new file mode 100644 index 00000000000..abb6373bbe4 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Tracer.java @@ -0,0 +1,84 @@ +/* + * 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.agent.tracer; + +import co.elastic.apm.agent.tracer.dispatch.BinaryHeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.pooling.ObjectPoolFactory; + +import javax.annotation.Nullable; + +public interface Tracer { + + boolean isRunning(); + + @Nullable + T probe(Class type); + + T require(Class type); + + T getConfig(Class configuration); + + ObjectPoolFactory getObjectPoolFactory(); + + @Nullable + AbstractSpan getActive(); + + @Nullable + Transaction currentTransaction(); + + /** + * Starts a trace-root transaction + * + * @param initiatingClassLoader the class loader corresponding to the service which initiated the creation of the transaction. + * Used to determine the service name. + * @return a transaction that will be the root of the current trace if the agent is currently RUNNING; null otherwise + */ + @Nullable + Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader); + + /** + * Starts a transaction as a child of the context headers obtained through the provided {@link HeaderGetter}. + * If the created transaction cannot be started as a child transaction (for example - if no parent context header is + * available), then it will be started as the root transaction of the trace. + * + * @param headerCarrier the Object from which context headers can be obtained, typically a request or a message + * @param textHeadersGetter provides the trace context headers required in order to create a child transaction + * @param initiatingClassLoader the class loader corresponding to the service which initiated the creation of the transaction. + * Used to determine the service name. + * @return a transaction which is a child of the provided parent if the agent is currently RUNNING; null otherwise + */ + @Nullable + Transaction startChildTransaction(@Nullable C headerCarrier, TextHeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader); + + /** + * Starts a transaction as a child of the context headers obtained through the provided {@link HeaderGetter}. + * If the created transaction cannot be started as a child transaction (for example - if no parent context header is + * available), then it will be started as the root transaction of the trace. + * + * @param headerCarrier the Object from which context headers can be obtained, typically a request or a message + * @param binaryHeadersGetter provides the trace context headers required in order to create a child transaction + * @param initiatingClassLoader the class loader corresponding to the service which initiated the creation of the transaction. + * Used to determine the service name. + * @return a transaction which is a child of the provided parent if the agent is currently RUNNING; null otherwise + */ + @Nullable + Transaction startChildTransaction(@Nullable C headerCarrier, BinaryHeaderGetter binaryHeadersGetter, @Nullable ClassLoader initiatingClassLoader); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Transaction.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Transaction.java new file mode 100644 index 00000000000..32174d1e69a --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Transaction.java @@ -0,0 +1,57 @@ +/* + * 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.agent.tracer; + +import javax.annotation.Nullable; + +public interface Transaction> extends AbstractSpan { + + /** + * Context + *

+ * Any arbitrary contextual information regarding the event, captured by the agent, optionally provided by the user + */ + @Override + TransactionContext getContext(); + + boolean isNoop(); + + /** + * The result of the transaction. HTTP status code for HTTP-related + * transactions. This sets the result regardless of an already existing value. + * should be used for user defined results + */ + T withResult(@Nullable String result); + + /** + * The result of the transaction. HTTP status code for HTTP-related + * transactions. This sets the result only if it is not already set. should be + * used for instrumentations + */ + T withResultIfUnset(@Nullable String result); + + /** + * Ignores this transaction, which makes it a noop so that it will not be reported to the APM Server. + */ + void ignoreTransaction(); + + void setFrameworkName(@Nullable String frameworkName); + + void setFrameworkVersion(@Nullable String frameworkVersion); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/TransactionContext.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/TransactionContext.java new file mode 100644 index 00000000000..baafaacb96b --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/TransactionContext.java @@ -0,0 +1,46 @@ +/* + * 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.agent.tracer; + +import co.elastic.apm.agent.tracer.metadata.CloudOrigin; +import co.elastic.apm.agent.tracer.metadata.Request; +import co.elastic.apm.agent.tracer.metadata.Response; +import co.elastic.apm.agent.tracer.metadata.User; + +public interface TransactionContext extends AbstractContext { + + + /** + * Request + *

+ * If a log record was generated as a result of a http request, the http interface can be used to collect this information. + */ + Request getRequest(); + + Response getResponse(); + + /** + * User + *

+ * Describes the authenticated User for a request. + */ + User getUser(); + + CloudOrigin getCloudOrigin(); +} diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractHeaderGetter.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/AbstractHeaderGetter.java similarity index 96% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractHeaderGetter.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/AbstractHeaderGetter.java index f48e06135a8..4ca6af60933 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractHeaderGetter.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/AbstractHeaderGetter.java @@ -16,9 +16,10 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.impl.transaction; +package co.elastic.apm.agent.tracer.dispatch; public abstract class AbstractHeaderGetter implements HeaderGetter { + @Override public void forEach(String headerName, C carrier, S state, HeaderConsumer consumer) { T firstHeader = getFirstHeader(headerName, carrier); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderGetter.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/BinaryHeaderGetter.java similarity index 94% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderGetter.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/BinaryHeaderGetter.java index 7f348044edf..f0ce2b33921 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderGetter.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/BinaryHeaderGetter.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.impl.transaction; +package co.elastic.apm.agent.tracer.dispatch; public interface BinaryHeaderGetter extends HeaderGetter { } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderSetter.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/BinaryHeaderSetter.java similarity index 59% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderSetter.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/BinaryHeaderSetter.java index 8efccc96a42..d98ba2841cb 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/BinaryHeaderSetter.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/BinaryHeaderSetter.java @@ -16,23 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.impl.transaction; +package co.elastic.apm.agent.tracer.dispatch; import javax.annotation.Nullable; public interface BinaryHeaderSetter extends HeaderSetter { - /** - * Since the implementation itself knows the intrinsics of the headers and carrier lifecycle and handling, it should - * be responsible for providing a byte array. This enables the implementation to cache byte arrays wherever required - * and possible. - *

- * NOTE: if this method returns null, the tracer will allocate a buffer for each header. - * - * @param headerName the header name for which the byte array is required - * @param length the length of the required byte array - * @return a byte array with the requested length, or null if header-value-buffer is not supported. - */ @Nullable byte[] getFixedLengthByteArray(String headerName, int length); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderGetter.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/HeaderGetter.java similarity index 58% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderGetter.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/HeaderGetter.java index c973af101b6..7989e86b9e5 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderGetter.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/HeaderGetter.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.impl.transaction; +package co.elastic.apm.agent.tracer.dispatch; import javax.annotation.Nullable; @@ -25,20 +25,6 @@ public interface HeaderGetter { @Nullable T getFirstHeader(String headerName, C carrier); - /** - * Calls the consumer for each header value with the given key - * until all entries have been processed or the action throws an exception. - *

- * The third parameter lets callers pass in a stateful object to be modified with header values, - * so the {@link HeaderConsumer} implementation itself can be stateless and potentially reusable. - *

- * - * @param headerName the name of the header - * @param carrier the object containing the headers - * @param state the object to be passed as the second parameter to each invocation on the specified consumer - * @param consumer the action to be performed for each header value - * @param the type of the state object - */ void forEach(String headerName, C carrier, S state, HeaderConsumer consumer); interface HeaderConsumer { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderRemover.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/HeaderRemover.java similarity index 94% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderRemover.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/HeaderRemover.java index e0f3a2251f9..68ffbdd7ae4 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderRemover.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/HeaderRemover.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.impl.transaction; +package co.elastic.apm.agent.tracer.dispatch; public interface HeaderRemover { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderSetter.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/HeaderSetter.java similarity index 95% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderSetter.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/HeaderSetter.java index be369d3cf0e..1b59c432510 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/HeaderSetter.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/HeaderSetter.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.impl.transaction; +package co.elastic.apm.agent.tracer.dispatch; public interface HeaderSetter { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderGetter.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/TextHeaderGetter.java similarity index 94% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderGetter.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/TextHeaderGetter.java index 88ca8ee8395..6f42a9f0f29 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderGetter.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/TextHeaderGetter.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.impl.transaction; +package co.elastic.apm.agent.tracer.dispatch; public interface TextHeaderGetter extends HeaderGetter { } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderSetter.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/TextHeaderSetter.java similarity index 94% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderSetter.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/TextHeaderSetter.java index 051165e44ad..5f1a184ce1c 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TextHeaderSetter.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/dispatch/TextHeaderSetter.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.impl.transaction; +package co.elastic.apm.agent.tracer.dispatch; public interface TextHeaderSetter extends HeaderSetter { } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Cloud.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Cloud.java new file mode 100644 index 00000000000..eba8de8c086 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Cloud.java @@ -0,0 +1,26 @@ +/* + * 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.agent.tracer.metadata; + +import javax.annotation.Nullable; + +public interface Cloud { + + Cloud withRegion(@Nullable String region); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/CloudOrigin.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/CloudOrigin.java new file mode 100644 index 00000000000..9ef91c58a60 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/CloudOrigin.java @@ -0,0 +1,38 @@ +/* + * 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.agent.tracer.metadata; + +import javax.annotation.Nullable; + +/** + * Request + *

+ * 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 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-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Db.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Db.java new file mode 100644 index 00000000000..ec32af52ea6 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Db.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.agent.tracer.metadata; + +import javax.annotation.Nullable; +import java.nio.CharBuffer; + +/** + * An object containing contextual data for database spans + */ +public interface Db { + + /** + * Database instance name + */ + Db withInstance(@Nullable String instance); + + /** + * Database type. For any SQL database, "sql". For others, the lower-case database category, e.g. "cassandra", "hbase", or "redis" + */ + Db withType(@Nullable String type); + + /** + * A database statement (e.g. query) for the given database type + */ + Db withStatement(@Nullable String statement); + + /** + * Username for accessing database + */ + Db withUser(@Nullable String user); + + /** + * Sets the number of affected rows by statement execution + * + * @param count number of affected rows + * @return this + */ + Db withAffectedRowsCount(long count); + + /** + * Returns the associated pooled {@link CharBuffer} to record the DB statement. + *

+ * Note: returns {@code null} unless {@link #withStatementBuffer()} has previously been called + *

+ * + * @return a {@link CharBuffer} to record the DB statement, or {@code null} + */ + @Nullable + CharBuffer getStatementBuffer(); + + /** + * Gets a pooled {@link CharBuffer} to record the DB statement and associates it with this instance. + *

+ * Note: you may not hold a reference to the returned {@link CharBuffer} as it will be reused. + *

+ *

+ * Note: This method is not thread safe + *

+ * + * @return a {@link CharBuffer} to record the DB statement + */ + CharBuffer withStatementBuffer(); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Destination.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Destination.java new file mode 100644 index 00000000000..ac6bfa7f78a --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Destination.java @@ -0,0 +1,48 @@ +/* + * 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.agent.tracer.metadata; + +import javax.annotation.Nullable; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketAddress; + +/** + * Context information about a destination of outgoing calls. + */ +public interface Destination { + + Destination withAddress(@Nullable CharSequence address); + + Destination withInetAddress(InetAddress address); + + Destination withPort(int port); + + /** + * @param addressPort host address and port in the following format 'host:3128' + * @return destination with updated address and port + */ + Destination withAddressPort(@Nullable String addressPort); + + Destination withInetSocketAddress(InetSocketAddress remoteAddress); + + Destination withSocketAddress(SocketAddress socketAddress); + + Cloud getCloud(); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Http.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Http.java new file mode 100644 index 00000000000..d4d614c039e --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Http.java @@ -0,0 +1,42 @@ +/* + * 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.agent.tracer.metadata; + +import javax.annotation.Nullable; + +public interface Http { + + /** + * URL used for the outgoing HTTP call + */ + Http withUrl(@Nullable String url); + + Http withMethod(String method); + + Http withStatusCode(int statusCode); + + /** + * URL used for the outgoing HTTP call + */ + @Nullable + CharSequence getUrl(); + + @Nullable + String getMethod(); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Message.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Message.java new file mode 100644 index 00000000000..949236c0829 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Message.java @@ -0,0 +1,38 @@ +/* + * 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.agent.tracer.metadata; + +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-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/PotentiallyMultiValuedMap.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/PotentiallyMultiValuedMap.java new file mode 100644 index 00000000000..ada83ed1e89 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/PotentiallyMultiValuedMap.java @@ -0,0 +1,37 @@ +/* + * 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.agent.tracer.metadata; + +import javax.annotation.Nullable; +import java.util.List; + +public interface PotentiallyMultiValuedMap { + + void add(String key, String value); + + @Nullable + String getFirst(String key); + + @Nullable + Object get(String key); + + boolean isEmpty(); + + boolean containsIgnoreCase(String key); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Request.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Request.java new file mode 100644 index 00000000000..ff676869255 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Request.java @@ -0,0 +1,101 @@ +/* + * 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.agent.tracer.metadata; + +import javax.annotation.Nullable; +import java.nio.CharBuffer; +import java.util.Enumeration; + +/** + * Request + *

+ * If a log record was generated as a result of a http request, the http interface can be used to collect this information. + */ +public interface Request { + + boolean hasContent(); + + Request withMethod(@Nullable String method); + + Socket getSocket(); + + /** + * A complete Url, with scheme, host and path. + * (Required) + */ + Url getUrl(); + + /** + * Should include any headers sent by the requester. + */ + PotentiallyMultiValuedMap getHeaders(); + + /** + * A parsed key-value object of cookies + */ + PotentiallyMultiValuedMap getCookies(); + + Request withHttpVersion(@Nullable String httpVersion); + + /** + * Gets a pooled {@link CharBuffer} to record the request body and associates it with this instance. + *

+ * Note: you may not hold a reference to the returned {@link CharBuffer} as it will be reused. + *

+ *

+ * Note: this method is not thread safe + *

+ *

+ * Note: In order for the value written to the body buffer to be used, you must call {@link Request#endOfBufferInput()}, + * which is the only valid way to invoke {@link CharBuffer#flip()} on the body buffer. + *

+ * + * @return a {@link CharBuffer} to record the request body + */ + @Nullable + CharBuffer withBodyBuffer(); + + void redactBody(); + + Request addFormUrlEncodedParameters(String key, String[] values); + + Request addHeader(String headerName, @Nullable Enumeration headerValues); + + Request addCookie(String cookieName, String cookieValue); + + /** + * Returns the associated pooled {@link CharBuffer} to record the request body. + *

+ * Note: returns {@code null} unless {@link #withBodyBuffer()} has previously been called + *

+ * + * @return a {@link CharBuffer} to record the request body, or {@code null} + */ + @Nullable + CharBuffer getBodyBuffer(); + + void endOfBufferInput(); + + /** + * Sets the body as a raw string and removes any previously set {@link #postParams} or {@link #bodyBuffer}. + * + * @param rawBody the body as a raw string + */ + void setRawBody(String rawBody); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Response.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Response.java new file mode 100644 index 00000000000..e87a517a8a1 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Response.java @@ -0,0 +1,44 @@ +/* + * 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.agent.tracer.metadata; + +import javax.annotation.Nullable; +import java.util.Collection; + +public interface Response { + + /** + * A mapping of HTTP headers of the response object + */ + PotentiallyMultiValuedMap getHeaders(); + + /** + * A boolean indicating whether the response was finished or not + */ + Response withFinished(boolean finished); + + /** + * The HTTP status code of the response. + */ + Response withStatusCode(int statusCode); + + Response withHeadersSent(boolean headersSent); + + Response addHeader(String headerName, @Nullable Collection headerValues); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Socket.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Socket.java new file mode 100644 index 00000000000..151c9a3902f --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Socket.java @@ -0,0 +1,26 @@ +/* + * 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.agent.tracer.metadata; + +import javax.annotation.Nullable; + +public interface Socket { + + Socket withRemoteAddress(@Nullable String remoteAddress); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Url.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Url.java new file mode 100644 index 00000000000..6092833fd29 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Url.java @@ -0,0 +1,62 @@ +/* + * 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.agent.tracer.metadata; + +import javax.annotation.Nullable; +import java.net.URI; + +/** + * A complete URL, with scheme, host, port, path and query string. + */ +public interface Url { + + /** + * Fills all attributes of Url from {@link URI} instance, also updates full + * + * @param uri URI + */ + void fillFrom(URI uri); + + void fillFrom(@Nullable String scheme, @Nullable String serverName, int serverPort, @Nullable String requestURI, @Nullable String queryString); + + /** + * The protocol of the request, e.g. 'https:'. + */ + Url withProtocol(@Nullable String protocol); + + /** + * The hostname of the request, e.g. 'example.com'. + */ + Url withHostname(@Nullable String hostname); + + /** + * The port of the request, e.g. 443 + */ + Url withPort(int port); + + /** + * The path of the request, e.g. '/search' + */ + Url withPathname(@Nullable String pathname); + + /** + * The search describes the query string of the request. It is expected to have values delimited by ampersands. + */ + Url withSearch(@Nullable String search); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/User.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/User.java new file mode 100644 index 00000000000..3524cd7653d --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/User.java @@ -0,0 +1,40 @@ +/* + * 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.agent.tracer.metadata; + +import javax.annotation.Nullable; + +/** + * User + *

+ * Describes the authenticated User for a request. + */ +public interface User { + + /** + * The username of the logged in user + */ + @Nullable + String getUsername(); + + /** + * The username of the logged in user + */ + User withUsername(String userName); +} diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Allocator.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/pooling/Allocator.java similarity index 95% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Allocator.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/pooling/Allocator.java index 87ebd0287b7..e5bdcb75062 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Allocator.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/pooling/Allocator.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.objectpool; +package co.elastic.apm.agent.tracer.pooling; /** * Defines pooled object factory diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/pooling/ObjectPool.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/pooling/ObjectPool.java new file mode 100644 index 00000000000..73e86d4acce --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/pooling/ObjectPool.java @@ -0,0 +1,44 @@ +/* + * 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.agent.tracer.pooling; + +/** + * Object pool + * + * @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 { + + /** + * Tries to reuse any existing instance if pool has any, otherwise creates a new un-pooled instance + * + * @return object instance, either from pool or freshly allocated + */ + T createInstance(); + + /** + * Recycles an object + * + * @param obj object to recycle + */ + void recycle(T obj); + + void clear(); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/pooling/ObjectPoolFactory.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/pooling/ObjectPoolFactory.java new file mode 100644 index 00000000000..df031e386ab --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/pooling/ObjectPoolFactory.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.agent.tracer.pooling; + +public interface ObjectPoolFactory { + + ObjectPool createRecyclableObjectPool(int maxCapacity, Allocator allocator); +} diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Recyclable.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/pooling/Recyclable.java similarity index 95% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Recyclable.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/pooling/Recyclable.java index ce517f851f0..e393dd97baf 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/Recyclable.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/pooling/Recyclable.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.objectpool; +package co.elastic.apm.agent.tracer.pooling; public interface Recyclable { diff --git a/pom.xml b/pom.xml index 0d99fc58546..c5bcb22e881 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,7 @@ apm-agent-common apm-agent-cached-lookup-key apm-opentracing + apm-agent-tracer