From bd6bf29acafddba3fb0d776499ecb96cc4cadffe Mon Sep 17 00:00:00 2001
From: Rafael Winterhalter
* Implement this interface and register it as a {@linkplain java.util.ServiceLoader service} under - * {@code src/main/resources/META-INF/services/co.elastic.apm.agent.context.LifecycleListener}. + * {@code src/main/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener}. *
*- * Implementations may have a constructor with an {@link ElasticApmTracer} argument + * Implementations may have a constructor with a {@link co.elastic.apm.agent.tracer.Tracer} argument + *
+ *+ * Listeners are instantiated before the {@link GlobalTracer} is initiated. To get hold of an instance, + * it needs to be injected via its constructor as the global tracer might neither be initialized within + * this instance's lifecycle methods. *
*/ public interface LifecycleListener { /** - * Callback for tracer initialization. As opposed to {@link LifecycleListener#start(ElasticApmTracer)}, which may - * be called in a delay, this callback is called at the bootstrap of the JVM, before anything else start. - * This may be useful for listeners that need to operate very early on, for example such that setup class loading - * requirement to support OSGi systems. - * @param tracer the tracer - * @throws Exception - */ - void init(ElasticApmTracer tracer) throws Exception; - - /** - * Callback for when the {@link ElasticApmTracer} starts. - * - * @param tracer The tracer. + * Callback for when the {@link co.elastic.apm.agent.tracer.Tracer} starts. */ - void start(ElasticApmTracer tracer) throws Exception; + void start() throws Exception; /** - * Callback for when {@link ElasticApmTracer#pause()} has been called. + * Callback for when {@link co.elastic.apm.agent.tracer.Tracer} has been paused. ** Typically, this method is used to reduce overhead on the application to a minimum. This can be done by cleaning * up resources like object pools, as well as by avoiding tracing-related overhead. @@ -65,7 +57,7 @@ public interface LifecycleListener { void pause() throws Exception; /** - * Callback for when {@link ElasticApmTracer#resume()} has been called. + * Callback for when {@link Tracer} is resumed. *
* Typically, used in order to revert the actions taken by the {@link LifecycleListener#pause()} method, allowing * the agent to restore all tracing capabilities @@ -79,7 +71,7 @@ public interface LifecycleListener { void resume() throws Exception; /** - * Callback for when {@link ElasticApmTracer#stop()} has been called. + * Callback for when {@link Tracer} is stopped. *
* Typically, this method is used to clean up resources like thread pools * so that there are no class loader leaks when a webapp is redeployed in an application server. @@ -96,17 +88,14 @@ public interface LifecycleListener { * The order in which lifecycle listeners are called is non-deterministic. * *
- * Metrics are structured into multiple {@link MetricSet}s. - * For each distinct combination of {@link Labels}, there is one {@link MetricSet}. - *
- *
* Labels allow for {@link CharSequence}s as a value,
* thus avoiding allocations for {@code transaction.name.toString()} when tracking breakdown metrics for a transaction.
* Iterations over the labels also don't allocate an Iterator, in contrast to {@code Map.entrySet().iterator()}.
diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/reporting/ReportingTracer.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/reporting/ReportingTracer.java
index 50c23f69ab..9c8577abd4 100644
--- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/reporting/ReportingTracer.java
+++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/reporting/ReportingTracer.java
@@ -20,9 +20,30 @@
import co.elastic.apm.agent.tracer.Tracer;
+import java.io.Closeable;
import java.util.concurrent.ScheduledExecutorService;
public interface ReportingTracer extends Tracer {
+ void addMetric(String name, Labels labels, DoubleSupplier metric);
+
+ void removeMetric(String name, Labels labels);
+
+ /**
+ * Reports an ECS-logging formatted log message.
+ *
+ * @param log log message generated by ecs-logging
+ */
+ void reportLog(String log);
+
+ /**
+ * Reports an ECS-logging formatted log message.
+ *
+ * @param log log message generated by ecs-logging
+ */
+ void reportLog(byte[] log);
+
ScheduledExecutorService getSharedSingleThreadedPool();
+
+ void addShutdownHook(Closeable job);
}
diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/LabelsTest.java b/apm-agent-tracer/src/test/java/co/elastic/apm/agent/tracer/reporting/LabelsTest.java
similarity index 99%
rename from apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/LabelsTest.java
rename to apm-agent-tracer/src/test/java/co/elastic/apm/agent/tracer/reporting/LabelsTest.java
index 21e55850c0..a27919baec 100644
--- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/LabelsTest.java
+++ b/apm-agent-tracer/src/test/java/co/elastic/apm/agent/tracer/reporting/LabelsTest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package co.elastic.apm.agent.metrics;
+package co.elastic.apm.agent.tracer.reporting;
import org.junit.jupiter.api.Test;
diff --git a/integration-tests/spring-boot-1-5/pom.xml b/integration-tests/spring-boot-1-5/pom.xml
index fc7bd94d42..7f5000cee3 100644
--- a/integration-tests/spring-boot-1-5/pom.xml
+++ b/integration-tests/spring-boot-1-5/pom.xml
@@ -28,6 +28,13 @@