Skip to content

Commit 425d897

Browse files
committed
Factor out lifecycle listener and remove tracer arguments as those can already be read by using the GlobalTracer abstraction or the constructor.
1 parent 4ddcfc6 commit 425d897

File tree

33 files changed

+131
-92
lines changed

33 files changed

+131
-92
lines changed

apm-agent-core/src/main/java/co/elastic/apm/agent/bci/InstrumentationStatsLifecycleListener.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
package co.elastic.apm.agent.bci;
2020

2121
import co.elastic.apm.agent.bci.bytebuddy.MatcherTimer;
22-
import co.elastic.apm.agent.context.AbstractLifecycleListener;
23-
import co.elastic.apm.agent.impl.ElasticApmTracer;
22+
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
2423
import co.elastic.apm.agent.sdk.logging.Logger;
2524
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
2625

@@ -31,7 +30,7 @@ public class InstrumentationStatsLifecycleListener extends AbstractLifecycleList
3130
private static final Logger logger = LoggerFactory.getLogger(InstrumentationStatsLifecycleListener.class);
3231

3332
@Override
34-
public void init(ElasticApmTracer tracer) {
33+
public void init() {
3534
InstrumentationStats instrumentationStats = ElasticApmAgent.getInstrumentationStats();
3635
instrumentationStats.reset();
3736
instrumentationStats.setMeasureMatching(logger.isDebugEnabled());

apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapCleaner.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
*/
1919
package co.elastic.apm.agent.collections;
2020

21-
import co.elastic.apm.agent.context.AbstractLifecycleListener;
22-
import co.elastic.apm.agent.impl.ElasticApmTracer;
21+
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
2322
import co.elastic.apm.agent.util.ExecutorUtils;
2423
import co.elastic.apm.agent.sdk.logging.Logger;
2524
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
@@ -41,7 +40,7 @@ public WeakMapCleaner() {
4140
}
4241

4342
@Override
44-
public void start(ElasticApmTracer tracer) {
43+
public void start() {
4544
scheduler.scheduleWithFixedDelay(this, 1, 1, TimeUnit.SECONDS);
4645
}
4746

apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSource.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
*/
1919
package co.elastic.apm.agent.configuration;
2020

21-
import co.elastic.apm.agent.context.LifecycleListener;
21+
import co.elastic.apm.agent.tracer.GlobalTracer;
22+
import co.elastic.apm.agent.tracer.LifecycleListener;
2223
import co.elastic.apm.agent.impl.ElasticApmTracer;
2324
import co.elastic.apm.agent.report.ApmServerClient;
2425
import co.elastic.apm.agent.report.serialize.DslJsonSerializer;
@@ -111,12 +112,13 @@ public void reload() {
111112
}
112113

113114
@Override
114-
public void init(ElasticApmTracer tracer) throws Exception {
115+
public void init() throws Exception {
115116
// noop
116117
}
117118

118119
@Override
119-
public void start(final ElasticApmTracer tracer) {
120+
public void start() {
121+
final ElasticApmTracer tracer = GlobalTracer.get().require(ElasticApmTracer.class);
120122
threadPool = ExecutorUtils.createSingleThreadDaemonPool("remote-config-poller", 1);
121123
threadPool.execute(new Runnable() {
122124
@Override

apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/StartupInfo.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
*/
1919
package co.elastic.apm.agent.configuration;
2020

21+
import co.elastic.apm.agent.tracer.GlobalTracer;
2122
import co.elastic.apm.agent.tracer.configuration.TimeDuration;
22-
import co.elastic.apm.agent.context.AbstractLifecycleListener;
23+
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
2324
import co.elastic.apm.agent.impl.ElasticApmTracer;
2425
import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration;
2526
import co.elastic.apm.agent.util.VersionUtils;
@@ -56,8 +57,8 @@ private static String getJvmAndOsVersionString() {
5657
}
5758

5859
@Override
59-
public void init(ElasticApmTracer tracer) {
60-
ConfigurationRegistry configurationRegistry = tracer.getConfigurationRegistry();
60+
public void init() {
61+
ConfigurationRegistry configurationRegistry = GlobalTracer.get().require(ElasticApmTracer.class).getConfigurationRegistry();
6162
logConfiguration(configurationRegistry, logger);
6263
}
6364

apm-agent-core/src/main/java/co/elastic/apm/agent/context/ClosableLifecycleListenerAdapter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919
package co.elastic.apm.agent.context;
2020

21+
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
22+
import co.elastic.apm.agent.tracer.LifecycleListener;
23+
2124
import java.io.Closeable;
2225

2326
public class ClosableLifecycleListenerAdapter extends AbstractLifecycleListener {

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import co.elastic.apm.agent.tracer.service.ServiceInfo;
3030
import co.elastic.apm.agent.configuration.SpanConfiguration;
3131
import co.elastic.apm.agent.context.ClosableLifecycleListenerAdapter;
32-
import co.elastic.apm.agent.context.LifecycleListener;
32+
import co.elastic.apm.agent.tracer.LifecycleListener;
3333
import co.elastic.apm.agent.impl.baggage.Baggage;
3434
import co.elastic.apm.agent.impl.baggage.W3CBaggagePropagation;
3535
import co.elastic.apm.agent.impl.error.ErrorCapture;
@@ -673,7 +673,7 @@ void init(List<LifecycleListener> lifecycleListeners) {
673673
this.lifecycleListeners.addAll(lifecycleListeners);
674674
for (LifecycleListener lifecycleListener : lifecycleListeners) {
675675
try {
676-
lifecycleListener.init(this);
676+
lifecycleListener.init();
677677
} catch (Exception e) {
678678
logger.error("Failed to init " + lifecycleListener.getClass().getName(), e);
679679
}
@@ -732,7 +732,7 @@ private synchronized void startSync() {
732732
reporter.start();
733733
for (LifecycleListener lifecycleListener : lifecycleListeners) {
734734
try {
735-
lifecycleListener.start(this);
735+
lifecycleListener.start();
736736
} catch (Exception e) {
737737
logger.error("Failed to start " + lifecycleListener.getClass().getName(), e);
738738
}
@@ -944,6 +944,7 @@ public MetaDataFuture getMetaDataFuture() {
944944
return metaDataFuture;
945945
}
946946

947+
@Override
947948
public ScheduledThreadPoolExecutor getSharedSingleThreadedPool() {
948949
return sharedPool;
949950
}

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import co.elastic.apm.agent.configuration.source.ConfigSources;
2727
import co.elastic.apm.agent.configuration.source.SystemPropertyConfigurationSource;
2828
import co.elastic.apm.agent.context.ClosableLifecycleListenerAdapter;
29-
import co.elastic.apm.agent.context.LifecycleListener;
29+
import co.elastic.apm.agent.tracer.LifecycleListener;
3030
import co.elastic.apm.agent.impl.metadata.MetaData;
3131
import co.elastic.apm.agent.impl.metadata.MetaDataFuture;
3232
import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration;

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Tracer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030

3131
import javax.annotation.Nullable;
3232

33-
public interface Tracer extends co.elastic.apm.agent.tracer.service.ServiceAwareTracer, co.elastic.apm.agent.tracer.Tracer {
33+
public interface Tracer extends co.elastic.apm.agent.tracer.Tracer,
34+
co.elastic.apm.agent.tracer.reporting.ReportingTracer,
35+
co.elastic.apm.agent.tracer.service.ServiceAwareTracer {
3436

3537
@Nullable
3638
@Override

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/CircuitBreaker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
package co.elastic.apm.agent.impl.circuitbreaker;
2020

21-
import co.elastic.apm.agent.context.AbstractLifecycleListener;
21+
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
2222
import co.elastic.apm.agent.impl.ElasticApmTracer;
2323
import co.elastic.apm.agent.util.ExecutorUtils;
2424
import co.elastic.apm.agent.sdk.logging.Logger;
@@ -50,7 +50,7 @@ public CircuitBreaker(ElasticApmTracer tracer) {
5050
}
5151

5252
@Override
53-
public void start(ElasticApmTracer tracer) {
53+
public void start() {
5454
// failsafe loading of stress monitors in isolation
5555
loadGCStressMonitor(tracer);
5656
loadSystemCpuStressMonitor(tracer);

apm-agent-core/src/main/java/co/elastic/apm/agent/logging/ApmServerLogAppender.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
*/
1919
package co.elastic.apm.agent.logging;
2020

21-
import co.elastic.apm.agent.context.AbstractLifecycleListener;
22-
import co.elastic.apm.agent.context.LifecycleListener;
21+
import co.elastic.apm.agent.tracer.AbstractLifecycleListener;
22+
import co.elastic.apm.agent.tracer.GlobalTracer;
23+
import co.elastic.apm.agent.tracer.LifecycleListener;
2324
import co.elastic.apm.agent.impl.ElasticApmTracer;
2425
import co.elastic.apm.agent.report.Reporter;
2526
import co.elastic.logging.log4j2.EcsLayout;
@@ -103,7 +104,8 @@ public void append(LogEvent event) {
103104
public LifecycleListener getInitListener() {
104105
return new AbstractLifecycleListener() {
105106
@Override
106-
public void init(ElasticApmTracer tracer) throws Exception {
107+
public void init() throws Exception {
108+
ElasticApmTracer tracer = GlobalTracer.get().require(ElasticApmTracer.class);
107109
initStreaming(tracer.getConfig(LoggingConfiguration.class), tracer.getReporter());
108110
}
109111
};

0 commit comments

Comments
 (0)