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..149a9151268
--- /dev/null
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopScope.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package co.elastic.apm.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..98946efb03a 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