From cd170c1d1e307e24a81800a1170be001fe9f7dfa Mon Sep 17 00:00:00 2001
From: Rafael Winterhalter
Date: Mon, 9 Oct 2023 22:40:50 +0200
Subject: [PATCH] Refactor according to feedback.
---
.../agent/bci/InstrumentationStatsLifecycleListener.java | 4 ++--
.../agent/configuration/ApmServerConfigurationSource.java | 4 ++--
.../co/elastic/apm/agent/configuration/StartupInfo.java | 4 ++--
...leLifecycleListener.java => InitLifecycleListener.java} | 4 ++--
.../java/co/elastic/apm/agent/impl/ElasticApmTracer.java | 6 +++---
.../co/elastic/apm/agent/logging/ApmServerLogAppender.java | 7 +++----
.../test/java/co/elastic/apm/agent/impl/LifecycleTest.java | 4 ++--
.../co/elastic/apm/agent/tracer/LifecycleListener.java | 6 +++---
8 files changed, 19 insertions(+), 20 deletions(-)
rename apm-agent-core/src/main/java/co/elastic/apm/agent/context/{InitializableLifecycleListener.java => InitLifecycleListener.java} (91%)
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/InstrumentationStatsLifecycleListener.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/InstrumentationStatsLifecycleListener.java
index 1429e79ae1..2e5e022870 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/InstrumentationStatsLifecycleListener.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/InstrumentationStatsLifecycleListener.java
@@ -19,7 +19,7 @@
package co.elastic.apm.agent.bci;
import co.elastic.apm.agent.bci.bytebuddy.MatcherTimer;
-import co.elastic.apm.agent.context.InitializableLifecycleListener;
+import co.elastic.apm.agent.context.InitLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.sdk.logging.Logger;
@@ -28,7 +28,7 @@
import java.util.ArrayList;
import java.util.Collections;
-public class InstrumentationStatsLifecycleListener extends AbstractLifecycleListener implements InitializableLifecycleListener {
+public class InstrumentationStatsLifecycleListener extends AbstractLifecycleListener implements InitLifecycleListener {
private static final Logger logger = LoggerFactory.getLogger(InstrumentationStatsLifecycleListener.class);
@Override
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSource.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSource.java
index 604bb59f52..7afda0b25b 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSource.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSource.java
@@ -18,7 +18,7 @@
*/
package co.elastic.apm.agent.configuration;
-import co.elastic.apm.agent.context.InitializableLifecycleListener;
+import co.elastic.apm.agent.context.InitLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.report.ApmServerClient;
import co.elastic.apm.agent.report.serialize.DslJsonSerializer;
@@ -44,7 +44,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-public class ApmServerConfigurationSource extends AbstractConfigurationSource implements InitializableLifecycleListener {
+public class ApmServerConfigurationSource extends AbstractConfigurationSource implements InitLifecycleListener {
// log correlation is enabled by default in Java agent, thus removing it from warnings
private static final Set IGNORED_REMOTE_KEYS = Collections.singleton("enable_log_correlation");
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/StartupInfo.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/StartupInfo.java
index 9033a82c35..27882d7610 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/StartupInfo.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/StartupInfo.java
@@ -18,7 +18,7 @@
*/
package co.elastic.apm.agent.configuration;
-import co.elastic.apm.agent.context.InitializableLifecycleListener;
+import co.elastic.apm.agent.context.InitLifecycleListener;
import co.elastic.apm.agent.tracer.configuration.TimeDuration;
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
@@ -39,7 +39,7 @@
* under Apache license 2.0.
*
*/
-public class StartupInfo extends AbstractLifecycleListener implements InitializableLifecycleListener {
+public class StartupInfo extends AbstractLifecycleListener implements InitLifecycleListener {
private static final Logger logger = LoggerFactory.getLogger(StartupInfo.class);
private final String elasticApmVersion;
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/context/InitializableLifecycleListener.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/context/InitLifecycleListener.java
similarity index 91%
rename from apm-agent-core/src/main/java/co/elastic/apm/agent/context/InitializableLifecycleListener.java
rename to apm-agent-core/src/main/java/co/elastic/apm/agent/context/InitLifecycleListener.java
index 47c3f6e33d..b92227e4d3 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/context/InitializableLifecycleListener.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/context/InitLifecycleListener.java
@@ -21,11 +21,11 @@
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.tracer.LifecycleListener;
-public interface InitializableLifecycleListener extends LifecycleListener {
+public interface InitLifecycleListener extends LifecycleListener {
/**
* Callback for tracer initialization. As opposed to {@link LifecycleListener#start()}, which may
- * be called in a delay, this callback is called at the bootstrap of the JVM, before anything else start.
+ * be called in a delay, this callback is called at the bootstrap of the JVM, before anything else starts.
* 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.
*/
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 7ce38364cc..c36ac51f67 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
@@ -26,7 +26,7 @@
import co.elastic.apm.agent.configuration.CoreConfiguration;
import co.elastic.apm.agent.configuration.MetricsConfiguration;
import co.elastic.apm.agent.configuration.ServerlessConfiguration;
-import co.elastic.apm.agent.context.InitializableLifecycleListener;
+import co.elastic.apm.agent.context.InitLifecycleListener;
import co.elastic.apm.agent.report.serialize.DslJsonDataWriter;
import co.elastic.apm.agent.tracer.reporting.DataWriter;
import co.elastic.apm.agent.tracer.reporting.DoubleSupplier;
@@ -680,9 +680,9 @@ public List getActivationListeners() {
void init(List lifecycleListeners) {
this.lifecycleListeners.addAll(lifecycleListeners);
for (LifecycleListener lifecycleListener : lifecycleListeners) {
- if (lifecycleListener instanceof InitializableLifecycleListener) {
+ if (lifecycleListener instanceof InitLifecycleListener) {
try {
- ((InitializableLifecycleListener) lifecycleListener).init(this);
+ ((InitLifecycleListener) lifecycleListener).init(this);
} catch (Exception e) {
logger.error("Failed to init " + lifecycleListener.getClass().getName(), e);
}
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/ApmServerLogAppender.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/ApmServerLogAppender.java
index a7d35ac1fb..5cf4fa486c 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/ApmServerLogAppender.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/ApmServerLogAppender.java
@@ -18,9 +18,8 @@
*/
package co.elastic.apm.agent.logging;
-import co.elastic.apm.agent.context.InitializableLifecycleListener;
+import co.elastic.apm.agent.context.InitLifecycleListener;
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
-import co.elastic.apm.agent.tracer.LifecycleListener;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.report.Reporter;
import co.elastic.logging.log4j2.EcsLayout;
@@ -101,8 +100,8 @@ public void append(LogEvent event) {
sendLogEvent(event);
}
- public InitializableLifecycleListener getInitListener() {
- class InitListener extends AbstractLifecycleListener implements InitializableLifecycleListener {
+ public InitLifecycleListener getInitListener() {
+ class InitListener extends AbstractLifecycleListener implements InitLifecycleListener {
@Override
public void init(ElasticApmTracer tracer) {
initStreaming(tracer.getConfig(LoggingConfiguration.class), tracer.getReporter());
diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/LifecycleTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/LifecycleTest.java
index 2281ae3cab..e2f4ec032f 100644
--- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/LifecycleTest.java
+++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/LifecycleTest.java
@@ -21,7 +21,7 @@
import co.elastic.apm.agent.MockReporter;
import co.elastic.apm.agent.bci.ElasticApmAgent;
import co.elastic.apm.agent.configuration.SpyConfiguration;
-import co.elastic.apm.agent.context.InitializableLifecycleListener;
+import co.elastic.apm.agent.context.InitLifecycleListener;
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
import co.elastic.apm.agent.objectpool.TestObjectPoolFactory;
import net.bytebuddy.agent.ByteBuddyAgent;
@@ -141,7 +141,7 @@ void testStartDisabled() throws Exception {
ConfigurationRegistry configRegistry = SpyConfiguration.createSpyConfig(SimpleSource.forTest("enabled", "false"));
final AtomicBoolean initialized = new AtomicBoolean();
final AtomicBoolean started = new AtomicBoolean();
- class TestListener extends AbstractLifecycleListener implements InitializableLifecycleListener {
+ class TestListener extends AbstractLifecycleListener implements InitLifecycleListener {
@Override
public void init(ElasticApmTracer tracer) {
initialized.set(true);
diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/LifecycleListener.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/LifecycleListener.java
index fe905248d1..57f175b3fa 100644
--- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/LifecycleListener.java
+++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/LifecycleListener.java
@@ -27,7 +27,7 @@
* {@code src/main/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener}.
*
*
- * Implementations may have a constructor with a {@link co.elastic.apm.agent.tracer.Tracer} argument
+ * Implementations may have a constructor with a {@link Tracer} argument
*
*
* Listeners are instantiated before the {@link GlobalTracer} is initiated. To get hold of an instance,
@@ -38,12 +38,12 @@
public interface LifecycleListener {
/**
- * Callback for when the {@link co.elastic.apm.agent.tracer.Tracer} starts.
+ * Callback for when the {@link Tracer} starts.
*/
void start() throws Exception;
/**
- * Callback for when {@link co.elastic.apm.agent.tracer.Tracer} has been paused.
+ * Callback for when {@link 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.