diff --git a/apm-agent-core/pom.xml b/apm-agent-core/pom.xml index 52c81eda23..a3ed72483d 100644 --- a/apm-agent-core/pom.xml +++ b/apm-agent-core/pom.xml @@ -149,11 +149,6 @@ ${version.jetty-server} test - - com.dslplatform - dsl-json - 1.9.3 - commons-math 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 a7f096ad59..c16d18c80d 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,10 +19,10 @@ package co.elastic.apm.agent.bci; import co.elastic.apm.agent.bci.bytebuddy.MatcherTimer; -import co.elastic.apm.agent.context.AbstractLifecycleListener; -import co.elastic.apm.agent.impl.ElasticApmTracer; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.Tracer; import java.util.ArrayList; import java.util.Collections; @@ -31,7 +31,7 @@ public class InstrumentationStatsLifecycleListener extends AbstractLifecycleList private static final Logger logger = LoggerFactory.getLogger(InstrumentationStatsLifecycleListener.class); @Override - public void init(ElasticApmTracer tracer) { + public void init(Tracer tracer) { InstrumentationStats instrumentationStats = ElasticApmAgent.getInstrumentationStats(); instrumentationStats.reset(); instrumentationStats.setMeasureMatching(logger.isDebugEnabled()); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapCleaner.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapCleaner.java index 3755d8b26b..be6ea5fd98 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapCleaner.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/collections/WeakMapCleaner.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.collections; -import co.elastic.apm.agent.context.AbstractLifecycleListener; -import co.elastic.apm.agent.impl.ElasticApmTracer; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.util.ExecutorUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -41,7 +41,7 @@ public WeakMapCleaner() { } @Override - public void start(ElasticApmTracer tracer) { + public void start(Tracer tracer) { scheduler.scheduleWithFixedDelay(this, 1, 1, TimeUnit.SECONDS); } 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 662810e4b7..0f63ac2d0c 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,12 +18,13 @@ */ package co.elastic.apm.agent.configuration; -import co.elastic.apm.agent.context.LifecycleListener; +import co.elastic.apm.agent.tracer.LifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.report.ApmServerClient; 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.Tracer; import co.elastic.apm.agent.util.ExecutorUtils; import com.dslplatform.json.DslJson; import com.dslplatform.json.JsonReader; @@ -111,17 +112,17 @@ public void reload() { } @Override - public void init(ElasticApmTracer tracer) throws Exception { + public void init(Tracer tracer) throws Exception { // noop } @Override - public void start(final ElasticApmTracer tracer) { + public void start(final Tracer tracer) { threadPool = ExecutorUtils.createSingleThreadDaemonPool("remote-config-poller", 1); threadPool.execute(new Runnable() { @Override public void run() { - pollConfig(tracer.getConfigurationRegistry()); + pollConfig(tracer.require(ElasticApmTracer.class).getConfigurationRegistry()); } }); } 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 f75d4807ab..4de8761af2 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,8 +18,9 @@ */ package co.elastic.apm.agent.configuration; +import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.tracer.configuration.TimeDuration; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; import co.elastic.apm.agent.util.VersionUtils; @@ -56,8 +57,8 @@ private static String getJvmAndOsVersionString() { } @Override - public void init(ElasticApmTracer tracer) { - ConfigurationRegistry configurationRegistry = tracer.getConfigurationRegistry(); + public void init(Tracer tracer) { + ConfigurationRegistry configurationRegistry = tracer.require(ElasticApmTracer.class).getConfigurationRegistry(); logConfiguration(configurationRegistry, logger); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/context/ClosableLifecycleListenerAdapter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/context/ClosableLifecycleListenerAdapter.java index 10ba08a7ed..d784743219 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/context/ClosableLifecycleListenerAdapter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/context/ClosableLifecycleListenerAdapter.java @@ -18,17 +18,18 @@ */ package co.elastic.apm.agent.context; -import java.io.Closeable; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.LifecycleListener; public class ClosableLifecycleListenerAdapter extends AbstractLifecycleListener { - private final Closeable closeable; + private final AutoCloseable closeable; - public static LifecycleListener of(Closeable closeable) { + public static LifecycleListener of(AutoCloseable closeable) { return new ClosableLifecycleListenerAdapter(closeable); } - private ClosableLifecycleListenerAdapter(Closeable closeable) { + private ClosableLifecycleListenerAdapter(AutoCloseable closeable) { this.closeable = closeable; } 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 08cb977c59..711601c319 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 @@ -35,11 +35,13 @@ import co.elastic.apm.agent.impl.metadata.NameAndIdField; import co.elastic.apm.agent.impl.metadata.ServiceFactory; import co.elastic.apm.agent.sdk.internal.util.LoggerUtils; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.tracer.service.Service; import co.elastic.apm.agent.tracer.service.ServiceInfo; import co.elastic.apm.agent.configuration.SpanConfiguration; import co.elastic.apm.agent.context.ClosableLifecycleListenerAdapter; -import co.elastic.apm.agent.context.LifecycleListener; +import co.elastic.apm.agent.tracer.LifecycleListener; import co.elastic.apm.agent.impl.baggage.Baggage; import co.elastic.apm.agent.impl.baggage.W3CBaggagePropagation; import co.elastic.apm.agent.impl.error.ErrorCapture; @@ -71,12 +73,12 @@ import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; import co.elastic.apm.agent.util.DependencyInjectingServiceLoader; import co.elastic.apm.agent.util.ExecutorUtils; +import com.dslplatform.json.JsonWriter; import org.stagemonitor.configuration.ConfigurationOption; import org.stagemonitor.configuration.ConfigurationOptionProvider; import org.stagemonitor.configuration.ConfigurationRegistry; import javax.annotation.Nullable; -import java.io.Closeable; import java.io.File; import java.util.ArrayList; import java.util.Collections; @@ -954,7 +956,8 @@ public ScheduledThreadPoolExecutor getSharedSingleThreadedPool() { return sharedPool; } - public void addShutdownHook(Closeable closeable) { + @Override + public void addShutdownHook(AutoCloseable closeable) { lifecycleListeners.add(ClosableLifecycleListenerAdapter.of(closeable)); } @@ -1044,4 +1047,30 @@ public void completeMetaData(String name, String version, String id, String regi region )); } + + @Override + public void removeGauge(String name, Labels.Immutable labels) { + metricRegistry.removeGauge(name, labels); + } + + @Override + public void addGauge(String name, Labels.Immutable labels, DoubleSupplier supplier) { + metricRegistry.add(name, labels, supplier); + } + + @Override + public void submit(Runnable job) { + sharedPool.submit(job); + } + + @Override + public void schedule(Runnable job, long interval, TimeUnit timeUnit) { + sharedPool.scheduleAtFixedRate(job, 0, interval, timeUnit); + } + + @Override + public void reportMetric(JsonWriter metrics) { + reporter.reportMetrics(metrics); + } + } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilder.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilder.java index 86c93a3353..b68faae5dd 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilder.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilder.java @@ -26,7 +26,7 @@ import co.elastic.apm.agent.configuration.source.ConfigSources; import co.elastic.apm.agent.configuration.source.SystemPropertyConfigurationSource; import co.elastic.apm.agent.context.ClosableLifecycleListenerAdapter; -import co.elastic.apm.agent.context.LifecycleListener; +import co.elastic.apm.agent.tracer.LifecycleListener; import co.elastic.apm.agent.impl.metadata.MetaData; import co.elastic.apm.agent.impl.metadata.MetaDataFuture; import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/CircuitBreaker.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/CircuitBreaker.java index f17e20876c..b90c539011 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/CircuitBreaker.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/CircuitBreaker.java @@ -18,8 +18,9 @@ */ package co.elastic.apm.agent.impl.circuitbreaker; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; +import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.util.ExecutorUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -50,7 +51,7 @@ public CircuitBreaker(ElasticApmTracer tracer) { } @Override - public void start(ElasticApmTracer tracer) { + public void start(Tracer tracer) { // failsafe loading of stress monitors in isolation loadGCStressMonitor(tracer); loadSystemCpuStressMonitor(tracer); @@ -63,7 +64,7 @@ public void run() { }); } - private void loadGCStressMonitor(ElasticApmTracer tracer) { + private void loadGCStressMonitor(Tracer tracer) { try { stressMonitors.add(new GCStressMonitor(tracer)); } catch (Throwable throwable) { @@ -71,7 +72,7 @@ private void loadGCStressMonitor(ElasticApmTracer tracer) { } } - private void loadSystemCpuStressMonitor(ElasticApmTracer tracer) { + private void loadSystemCpuStressMonitor(Tracer tracer) { try { stressMonitors.add(new SystemCpuStressMonitor(tracer)); } catch (Throwable throwable) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/GCStressMonitor.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/GCStressMonitor.java index 62405dadd6..a325e2632b 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/GCStressMonitor.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/GCStressMonitor.java @@ -21,6 +21,7 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.Tracer; import java.lang.management.ManagementFactory; import java.lang.management.MemoryPoolMXBean; @@ -35,7 +36,7 @@ class GCStressMonitor extends StressMonitor { private final List heapMBeans = new ArrayList<>(); private final StringBuilder latestStressDetectionInfo = new StringBuilder("No stress has been detected so far."); - GCStressMonitor(ElasticApmTracer tracer) { + GCStressMonitor(Tracer tracer) { super(tracer); discoverMBeans(); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/StressMonitor.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/StressMonitor.java index 992bb89344..a6db804364 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/StressMonitor.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/StressMonitor.java @@ -18,13 +18,13 @@ */ package co.elastic.apm.agent.impl.circuitbreaker; -import co.elastic.apm.agent.impl.ElasticApmTracer; +import co.elastic.apm.agent.tracer.Tracer; abstract class StressMonitor { protected final CircuitBreakerConfiguration circuitBreakerConfiguration; - public StressMonitor(ElasticApmTracer tracer) { + public StressMonitor(Tracer tracer) { circuitBreakerConfiguration = tracer.getConfig(CircuitBreakerConfiguration.class); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/SystemCpuStressMonitor.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/SystemCpuStressMonitor.java index cb0b6536aa..fd0d5e8fe6 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/SystemCpuStressMonitor.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/circuitbreaker/SystemCpuStressMonitor.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.circuitbreaker; -import co.elastic.apm.agent.impl.ElasticApmTracer; +import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.util.JmxUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -45,7 +45,7 @@ public class SystemCpuStressMonitor extends StressMonitor { @Nullable private final Method systemCpuUsageMethod; - SystemCpuStressMonitor(ElasticApmTracer tracer) { + SystemCpuStressMonitor(Tracer tracer) { super(tracer); operatingSystemBean = ManagementFactory.getOperatingSystemMXBean(); systemCpuUsageMethod = JmxUtils.getOperatingSystemMBeanMethod(operatingSystemBean, "getSystemCpuLoad"); 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 aab38dddd2..ff3ca395c7 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 @@ -27,7 +27,7 @@ import co.elastic.apm.agent.impl.context.Response; import co.elastic.apm.agent.impl.context.TransactionContext; import co.elastic.apm.agent.impl.sampling.Sampler; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.Timer; import co.elastic.apm.agent.tracer.Outcome; 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 59328be609..97074fe210 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,10 +18,11 @@ */ package co.elastic.apm.agent.logging; -import co.elastic.apm.agent.context.AbstractLifecycleListener; -import co.elastic.apm.agent.context.LifecycleListener; +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.apm.agent.tracer.Tracer; import co.elastic.logging.log4j2.EcsLayout; import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Core; @@ -103,8 +104,8 @@ public void append(LogEvent event) { public LifecycleListener getInitListener() { return new AbstractLifecycleListener() { @Override - public void init(ElasticApmTracer tracer) throws Exception { - initStreaming(tracer.getConfig(LoggingConfiguration.class), tracer.getReporter()); + public void init(Tracer tracer) throws Exception { + initStreaming(tracer.getConfig(LoggingConfiguration.class), tracer.require(ElasticApmTracer.class).getReporter()); } }; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricCollector.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricCollector.java index b8ccd561f4..199899b787 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricCollector.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricCollector.java @@ -18,6 +18,8 @@ */ package co.elastic.apm.agent.metrics; +import co.elastic.apm.agent.tracer.metrics.Labels; + public interface MetricCollector { void addMetricValue(String metric, Labels labels, double value); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricRegistry.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricRegistry.java index 2df93faa7f..9c1cdeb285 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricRegistry.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricRegistry.java @@ -23,6 +23,8 @@ 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.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.metrics.Labels; import org.HdrHistogram.WriterReaderPhaser; import javax.annotation.Nonnull; 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 474a3827be..8bb1bc6f85 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,6 +18,8 @@ */ package co.elastic.apm.agent.metrics; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.metrics.Labels; 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/metrics/builtin/AgentOverheadMetrics.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetrics.java index c0a06ab921..3413f95f8a 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetrics.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetrics.java @@ -19,9 +19,10 @@ package co.elastic.apm.agent.metrics.builtin; import co.elastic.apm.agent.configuration.MetricsConfiguration; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.Tracer; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricCollector; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.MetricsProvider; @@ -113,8 +114,8 @@ public AgentOverheadMetrics() { } @Override - public void start(ElasticApmTracer tracer) throws Exception { - MetricRegistry metricRegistry = tracer.getMetricRegistry(); + public void start(Tracer tracer) throws Exception { + MetricRegistry metricRegistry = tracer.require(ElasticApmTracer.class).getMetricRegistry(); MetricsConfiguration config = tracer.getConfig(MetricsConfiguration.class); bindTo(metricRegistry, config); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetrics.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetrics.java index 6970d114ae..e946bb90e1 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetrics.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetrics.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.metrics.builtin; import co.elastic.apm.agent.configuration.MetricsConfiguration; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricCollector; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.MetricsProvider; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/CGroupMetrics.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/CGroupMetrics.java index 9f64ed14cc..e89ee39ef5 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/CGroupMetrics.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/CGroupMetrics.java @@ -18,10 +18,11 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.metrics.DoubleSupplier; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.Tracer; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -213,8 +214,8 @@ private File getMaxMemoryFile(File maxMemoryFile, String cgroupUnlimitedConstant } @Override - public void start(ElasticApmTracer tracer) { - bindTo(tracer.getMetricRegistry()); + public void start(Tracer tracer) { + bindTo(tracer.require(ElasticApmTracer.class).getMetricRegistry()); } void bindTo(MetricRegistry metricRegistry) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmFdMetrics.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmFdMetrics.java index 4a0764fe35..08d95586bf 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmFdMetrics.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmFdMetrics.java @@ -18,10 +18,11 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.metrics.DoubleSupplier; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.Tracer; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import javax.annotation.Nullable; @@ -40,8 +41,8 @@ public class JvmFdMetrics extends AbstractLifecycleListener { private static final MethodHandle getMaxFileDescriptorCount = getMethodHandle("getMaxFileDescriptorCount"); @Override - public void start(ElasticApmTracer tracer) { - bindTo(tracer.getMetricRegistry()); + public void start(Tracer tracer) { + bindTo(tracer.require(ElasticApmTracer.class).getMetricRegistry()); } void bindTo(final MetricRegistry registry) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmGcMetrics.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmGcMetrics.java index 4cd140aced..089c2df2d0 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmGcMetrics.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmGcMetrics.java @@ -18,10 +18,11 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.metrics.DoubleSupplier; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.Tracer; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import com.sun.management.ThreadMXBean; import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement; @@ -35,8 +36,8 @@ public class JvmGcMetrics extends AbstractLifecycleListener { private final List garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans(); @Override - public void start(ElasticApmTracer tracer) { - bindTo(tracer.getMetricRegistry()); + public void start(Tracer tracer) { + bindTo(tracer.require(ElasticApmTracer.class).getMetricRegistry()); } void bindTo(final MetricRegistry registry) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetrics.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetrics.java index b83fbf2eff..272c1e7a31 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetrics.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetrics.java @@ -18,10 +18,11 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.metrics.DoubleSupplier; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.Tracer; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -36,8 +37,8 @@ public class JvmMemoryMetrics extends AbstractLifecycleListener { private static final Logger logger = LoggerFactory.getLogger(JvmMemoryMetrics.class); @Override - public void start(ElasticApmTracer tracer) { - bindTo(tracer.getMetricRegistry()); + public void start(Tracer tracer) { + bindTo(tracer.require(ElasticApmTracer.class).getMetricRegistry()); } void bindTo(final MetricRegistry registry) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/SystemMetrics.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/SystemMetrics.java index 3659938a5f..a6e79439d8 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/SystemMetrics.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/SystemMetrics.java @@ -18,11 +18,12 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.metrics.DoubleSupplier; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.Tracer; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.util.JmxUtils; import org.stagemonitor.util.StringUtils; @@ -88,8 +89,8 @@ public SystemMetrics() { } @Override - public void start(ElasticApmTracer tracer) { - bindTo(tracer.getMetricRegistry()); + public void start(Tracer tracer) { + bindTo(tracer.require(ElasticApmTracer.class).getMetricRegistry()); } void bindTo(MetricRegistry metricRegistry) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/ThreadMetrics.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/ThreadMetrics.java index 52c5203555..cf3314c0ea 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/ThreadMetrics.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/ThreadMetrics.java @@ -18,10 +18,11 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.metrics.DoubleSupplier; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.Tracer; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import java.lang.management.ManagementFactory; @@ -30,8 +31,8 @@ public class ThreadMetrics extends AbstractLifecycleListener { @Override - public void start(ElasticApmTracer tracer) { - bindTo(tracer.getMetricRegistry()); + public void start(Tracer tracer) { + bindTo(tracer.require(ElasticApmTracer.class).getMetricRegistry()); } void bindTo(final MetricRegistry registry) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonSerializer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonSerializer.java index 6ec3676c4b..e56bb1b1e3 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonSerializer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonSerializer.java @@ -59,13 +59,14 @@ import co.elastic.apm.agent.impl.transaction.StackFrame; import co.elastic.apm.agent.impl.transaction.TraceContext; import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.report.ApmServerClient; import co.elastic.apm.agent.sdk.internal.collections.LongList; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap; import co.elastic.apm.agent.tracer.pooling.Recyclable; +import co.elastic.apm.agent.tracer.metrics.DslJsonUtil; import com.dslplatform.json.BoolConverter; import com.dslplatform.json.DslJson; import com.dslplatform.json.JsonWriter; @@ -98,7 +99,6 @@ public class DslJsonSerializer { private static final byte NEW_LINE = (byte) '\n'; private static final Logger logger = LoggerFactory.getLogger(DslJsonSerializer.class); - private static final String[] DISALLOWED_IN_PROPERTY_NAME = new String[]{".", "*", "\""}; private static final List excludedStackFramesPrefixes = Arrays.asList("java.lang.reflect.", "com.sun.", "sun.", "jdk.internal."); @@ -165,16 +165,16 @@ static void serializeMetadata(MetaData metaData, private static void serializeGlobalLabels(ArrayList globalLabelKeys, ArrayList globalLabelValues, final StringBuilder replaceBuilder, JsonWriter jw) { if (!globalLabelKeys.isEmpty()) { - writeFieldName("labels", jw); + DslJsonUtil.writeFieldName("labels", jw); jw.writeByte(OBJECT_START); - writeStringValue(sanitizePropertyName(globalLabelKeys.get(0), replaceBuilder), replaceBuilder, jw); + DslJsonUtil.writeStringValue(DslJsonUtil.sanitizePropertyName(globalLabelKeys.get(0), replaceBuilder), replaceBuilder, jw); jw.writeByte(JsonWriter.SEMI); - writeStringValue(globalLabelValues.get(0), replaceBuilder, jw); + DslJsonUtil.writeStringValue(globalLabelValues.get(0), replaceBuilder, jw); for (int i = 1; i < globalLabelKeys.size(); i++) { jw.writeByte(COMMA); - writeStringValue(sanitizePropertyName(globalLabelKeys.get(i), replaceBuilder), replaceBuilder, jw); + DslJsonUtil.writeStringValue(DslJsonUtil.sanitizePropertyName(globalLabelKeys.get(i), replaceBuilder), replaceBuilder, jw); jw.writeByte(JsonWriter.SEMI); - writeStringValue(globalLabelValues.get(i), replaceBuilder, jw); + DslJsonUtil.writeStringValue(globalLabelValues.get(i), replaceBuilder, jw); } jw.writeByte(OBJECT_END); jw.writeByte(COMMA); @@ -182,7 +182,7 @@ private static void serializeGlobalLabels(ArrayList globalLabelKeys, Arr } private static void serializeService(final Service service, final StringBuilder replaceBuilder, final JsonWriter jw, boolean supportsAgentActivationMethod) { - writeFieldName("service", jw); + DslJsonUtil.writeFieldName("service", jw); jw.writeByte(JsonWriter.OBJECT_START); writeField("name", service.getName(), replaceBuilder, jw); @@ -224,17 +224,17 @@ private static void serializeService(@Nullable final CharSequence serviceName, @ return; } - writeFieldName("service", jw); + DslJsonUtil.writeFieldName("service", jw); jw.writeByte(OBJECT_START); if (serviceName != null) { - writeFieldName("name", jw); - writeStringValue(serviceName, replaceBuilder, jw); + DslJsonUtil.writeFieldName("name", jw); + DslJsonUtil.writeStringValue(serviceName, replaceBuilder, jw); if (serviceVersion != null) { jw.writeByte(COMMA); - writeFieldName("version", jw); - writeStringValue(serviceVersion, replaceBuilder, jw); + DslJsonUtil.writeFieldName("version", jw); + DslJsonUtil.writeStringValue(serviceVersion, replaceBuilder, jw); } } @@ -242,22 +242,22 @@ private static void serializeService(@Nullable final CharSequence serviceName, @ if (serviceName != null) { jw.writeByte(COMMA); } - writeFieldName("target", jw); + DslJsonUtil.writeFieldName("target", jw); jw.writeByte(OBJECT_START); CharSequence targetType = serviceTarget.getType(); CharSequence targetName = serviceTarget.getName(); if (targetType != null) { - writeFieldName("type", jw); - writeStringValue(targetType, replaceBuilder, jw); + DslJsonUtil.writeFieldName("type", jw); + DslJsonUtil.writeStringValue(targetType, replaceBuilder, jw); } if (targetName != null) { if (targetType != null) { jw.writeByte(COMMA); } - writeFieldName("name", jw); - writeStringValue(targetName, replaceBuilder, jw); + DslJsonUtil.writeFieldName("name", jw); + DslJsonUtil.writeStringValue(targetName, replaceBuilder, jw); } jw.writeByte(OBJECT_END); @@ -271,7 +271,7 @@ private static void serializeService(@Nullable String name, @Nullable String ver } private static void serializeAgent(final Agent agent, final StringBuilder replaceBuilder, final JsonWriter jw, boolean supportsAgentActivationMethod) { - writeFieldName("agent", jw); + DslJsonUtil.writeFieldName("agent", jw); jw.writeByte(JsonWriter.OBJECT_START); if (supportsAgentActivationMethod) { writeField("activation_method", agent.getActivationMethod(), replaceBuilder, jw); @@ -284,7 +284,7 @@ private static void serializeAgent(final Agent agent, final StringBuilder replac } private static void serializeLanguage(final Language language, final StringBuilder replaceBuilder, final JsonWriter jw) { - writeFieldName("language", jw); + DslJsonUtil.writeFieldName("language", jw); jw.writeByte(JsonWriter.OBJECT_START); writeField("name", language.getName(), replaceBuilder, jw); writeLastField("version", language.getVersion(), replaceBuilder, jw); @@ -293,7 +293,7 @@ private static void serializeLanguage(final Language language, final StringBuild } private static void serializeFramework(final Framework framework, final StringBuilder replaceBuilder, final JsonWriter jw) { - writeFieldName("framework", jw); + DslJsonUtil.writeFieldName("framework", jw); jw.writeByte(JsonWriter.OBJECT_START); writeField("name", framework.getName(), replaceBuilder, jw); writeLastField("version", framework.getVersion(), replaceBuilder, jw); @@ -302,7 +302,7 @@ private static void serializeFramework(final Framework framework, final StringBu } private static void serializeNode(final Node node, final StringBuilder replaceBuilder, final JsonWriter jw) { - writeFieldName("node", jw); + DslJsonUtil.writeFieldName("node", jw); jw.writeByte(JsonWriter.OBJECT_START); writeLastField("configured_name", node.getName(), replaceBuilder, jw); jw.writeByte(JsonWriter.OBJECT_END); @@ -310,7 +310,7 @@ private static void serializeNode(final Node node, final StringBuilder replaceBu } private static void serializeRuntime(final RuntimeInfo runtime, final StringBuilder replaceBuilder, final JsonWriter jw) { - writeFieldName("runtime", jw); + DslJsonUtil.writeFieldName("runtime", jw); jw.writeByte(JsonWriter.OBJECT_START); writeField("name", runtime.getName(), replaceBuilder, jw); writeLastField("version", runtime.getVersion(), replaceBuilder, jw); @@ -319,7 +319,7 @@ private static void serializeRuntime(final RuntimeInfo runtime, final StringBuil } private static void serializeProcess(final ProcessInfo process, final StringBuilder replaceBuilder, final JsonWriter jw) { - writeFieldName("process", jw); + DslJsonUtil.writeFieldName("process", jw); jw.writeByte(JsonWriter.OBJECT_START); writeField("pid", process.getPid(), jw); if (process.getPpid() != null) { @@ -337,7 +337,7 @@ private static void serializeSystem(SystemInfo system, JsonWriter jw, boolean supportsConfiguredAndDetectedHostname) { - writeFieldName("system", jw); + DslJsonUtil.writeFieldName("system", jw); jw.writeByte(JsonWriter.OBJECT_START); serializeContainerInfo(system.getContainerInfo(), replaceBuilder, jw); serializeKubernetesInfo(system.getKubernetesInfo(), replaceBuilder, jw); @@ -360,13 +360,13 @@ private static void serializeSystem(SystemInfo system, } private static void serializeCloudProvider(final CloudProviderInfo cloudProviderInfo, final StringBuilder replaceBuilder, final JsonWriter jw) { - writeFieldName("cloud", jw); + DslJsonUtil.writeFieldName("cloud", jw); jw.writeByte(OBJECT_START); serializeNameAndIdField(cloudProviderInfo.getAccount(), "account", replaceBuilder, jw); serializeNameAndIdField(cloudProviderInfo.getInstance(), "instance", replaceBuilder, jw); serializeNameAndIdField(cloudProviderInfo.getProject(), "project", replaceBuilder, jw); if (cloudProviderInfo.getMachine() != null) { - writeFieldName("machine", jw); + DslJsonUtil.writeFieldName("machine", jw); jw.writeByte(JsonWriter.OBJECT_START); writeLastField("type", cloudProviderInfo.getMachine().getType(), replaceBuilder, jw); jw.writeByte(JsonWriter.OBJECT_END); @@ -375,7 +375,7 @@ private static void serializeCloudProvider(final CloudProviderInfo cloudProvider writeField("availability_zone", cloudProviderInfo.getAvailabilityZone(), replaceBuilder, jw); writeField("region", cloudProviderInfo.getRegion(), replaceBuilder, jw); if (null != cloudProviderInfo.getService()) { - writeFieldName("service", jw); + DslJsonUtil.writeFieldName("service", jw); jw.writeByte(JsonWriter.OBJECT_START); writeLastField("name", cloudProviderInfo.getService().getName(), replaceBuilder, jw); jw.writeByte(JsonWriter.OBJECT_END); @@ -388,13 +388,13 @@ private static void serializeCloudProvider(final CloudProviderInfo cloudProvider private static void serializeNameAndIdField(@Nullable NameAndIdField nameAndIdField, String fieldName, StringBuilder replaceBuilder, JsonWriter jw) { if (nameAndIdField != null && !nameAndIdField.isEmpty()) { - writeFieldName(fieldName, jw); + DslJsonUtil.writeFieldName(fieldName, jw); jw.writeByte(JsonWriter.OBJECT_START); boolean idWritten = false; String id = nameAndIdField.getId(); if (id != null) { - writeFieldName("id", jw); - writeStringValue(id, replaceBuilder, jw); + DslJsonUtil.writeFieldName("id", jw); + DslJsonUtil.writeStringValue(id, replaceBuilder, jw); idWritten = true; } String name = nameAndIdField.getName(); @@ -402,8 +402,8 @@ private static void serializeNameAndIdField(@Nullable NameAndIdField nameAndIdFi if (idWritten) { jw.writeByte(COMMA); } - writeFieldName("name", jw); - writeStringValue(name, replaceBuilder, jw); + DslJsonUtil.writeFieldName("name", jw); + DslJsonUtil.writeStringValue(name, replaceBuilder, jw); } jw.writeByte(JsonWriter.OBJECT_END); jw.writeByte(COMMA); @@ -412,7 +412,7 @@ private static void serializeNameAndIdField(@Nullable NameAndIdField nameAndIdFi private static void serializeContainerInfo(@Nullable SystemInfo.Container container, final StringBuilder replaceBuilder, final JsonWriter jw) { if (container != null) { - writeFieldName("container", jw); + DslJsonUtil.writeFieldName("container", jw); jw.writeByte(JsonWriter.OBJECT_START); writeLastField("id", container.getId(), replaceBuilder, jw); jw.writeByte(JsonWriter.OBJECT_END); @@ -422,7 +422,7 @@ private static void serializeContainerInfo(@Nullable SystemInfo.Container contai private static void serializeKubernetesInfo(@Nullable SystemInfo.Kubernetes kubernetes, final StringBuilder replaceBuilder, final JsonWriter jw) { if (kubernetes != null && kubernetes.hasContent()) { - writeFieldName("kubernetes", jw); + DslJsonUtil.writeFieldName("kubernetes", jw); jw.writeByte(JsonWriter.OBJECT_START); serializeKubeNodeInfo(kubernetes.getNode(), replaceBuilder, jw); serializeKubePodInfo(kubernetes.getPod(), replaceBuilder, jw); @@ -434,7 +434,7 @@ private static void serializeKubernetesInfo(@Nullable SystemInfo.Kubernetes kube private static void serializeKubePodInfo(@Nullable SystemInfo.Kubernetes.Pod pod, final StringBuilder replaceBuilder, final JsonWriter jw) { if (pod != null) { - writeFieldName("pod", jw); + DslJsonUtil.writeFieldName("pod", jw); jw.writeByte(JsonWriter.OBJECT_START); String podName = pod.getName(); if (podName != null) { @@ -448,7 +448,7 @@ private static void serializeKubePodInfo(@Nullable SystemInfo.Kubernetes.Pod pod private static void serializeKubeNodeInfo(@Nullable SystemInfo.Kubernetes.Node node, final StringBuilder replaceBuilder, final JsonWriter jw) { if (node != null) { - writeFieldName("node", jw); + DslJsonUtil.writeFieldName("node", jw); jw.writeByte(JsonWriter.OBJECT_START); writeLastField("name", node.getName(), replaceBuilder, jw); jw.writeByte(JsonWriter.OBJECT_END); @@ -476,13 +476,13 @@ private static void serializeStringKeyScalarValueMap(Iterator kv = it.next(); - writeStringValue(sanitizePropertyName(kv.getKey(), replaceBuilder), replaceBuilder, jw); + DslJsonUtil.writeStringValue(DslJsonUtil.sanitizePropertyName(kv.getKey(), replaceBuilder), replaceBuilder, jw); jw.writeByte(JsonWriter.SEMI); serializeScalarValue(replaceBuilder, jw, kv.getValue(), extendedStringLimit, supportsNonStringValues); while (it.hasNext()) { jw.writeByte(COMMA); kv = it.next(); - writeStringValue(sanitizePropertyName(kv.getKey(), replaceBuilder), replaceBuilder, jw); + DslJsonUtil.writeStringValue(DslJsonUtil.sanitizePropertyName(kv.getKey(), replaceBuilder), replaceBuilder, jw); jw.writeByte(JsonWriter.SEMI); serializeScalarValue(replaceBuilder, jw, kv.getValue(), extendedStringLimit, supportsNonStringValues); } @@ -498,7 +498,7 @@ static void serializeLabels(Labels labels, final String serviceName, final Strin } if (!labels.isEmpty()) { if (labels.getTransactionName() != null || labels.getTransactionType() != null) { - writeFieldName("transaction", jw); + DslJsonUtil.writeFieldName("transaction", jw); jw.writeByte(OBJECT_START); writeField("name", labels.getTransactionName(), replaceBuilder, jw); writeLastField("type", labels.getTransactionType(), replaceBuilder, jw); @@ -507,7 +507,7 @@ static void serializeLabels(Labels labels, final String serviceName, final Strin } if (labels.getSpanType() != null || labels.getSpanSubType() != null) { - writeFieldName("span", jw); + DslJsonUtil.writeFieldName("span", jw); jw.writeByte(OBJECT_START); writeField("type", labels.getSpanType(), replaceBuilder, jw); writeLastField("subtype", labels.getSpanSubType(), replaceBuilder, jw); @@ -515,7 +515,7 @@ static void serializeLabels(Labels labels, final String serviceName, final Strin jw.writeByte(COMMA); } - writeFieldName("tags", jw); + DslJsonUtil.writeFieldName("tags", jw); jw.writeByte(OBJECT_START); serialize(labels, replaceBuilder, jw); jw.writeByte(OBJECT_END); @@ -528,7 +528,7 @@ private static void serialize(Labels labels, final StringBuilder replaceBuilder, if (i > 0) { jw.writeByte(COMMA); } - writeStringValue(sanitizePropertyName(labels.getKey(i), replaceBuilder), replaceBuilder, jw); + DslJsonUtil.writeStringValue(DslJsonUtil.sanitizePropertyName(labels.getKey(i), replaceBuilder), replaceBuilder, jw); jw.writeByte(JsonWriter.SEMI); serializeScalarValue(replaceBuilder, jw, labels.getValue(i), false, false); } @@ -539,7 +539,7 @@ private static void serializeScalarValue(final StringBuilder replaceBuilder, fin if (extendedStringLimit) { writeLongStringValue((String) value, replaceBuilder, jw); } else { - writeStringValue((String) value, replaceBuilder, jw); + DslJsonUtil.writeStringValue((String) value, replaceBuilder, jw); } } else if (value instanceof Number) { if (supportsNonStringValues) { @@ -559,25 +559,6 @@ private static void serializeScalarValue(final StringBuilder replaceBuilder, fin } } - public static CharSequence sanitizePropertyName(String key, StringBuilder replaceBuilder) { - for (int i = 0; i < DISALLOWED_IN_PROPERTY_NAME.length; i++) { - if (key.contains(DISALLOWED_IN_PROPERTY_NAME[i])) { - return replaceAll(key, DISALLOWED_IN_PROPERTY_NAME, "_", replaceBuilder); - } - } - return key; - } - - private static CharSequence replaceAll(String s, String[] stringsToReplace, String replacement, StringBuilder replaceBuilder) { - // uses a instance variable StringBuilder to avoid allocations - replaceBuilder.setLength(0); - replaceBuilder.append(s); - for (String toReplace : stringsToReplace) { - replace(replaceBuilder, toReplace, replacement, 0); - } - return replaceBuilder; - } - static void replace(StringBuilder replaceBuilder, String toReplace, String replacement, int fromIndex) { for (int i = replaceBuilder.indexOf(toReplace, fromIndex); i != -1; i = replaceBuilder.indexOf(toReplace, fromIndex)) { replaceBuilder.replace(i, i + toReplace.length(), replacement); @@ -601,13 +582,13 @@ static void writeField(final String fieldName, if (value == null) { if (writeNull) { - writeFieldName(fieldName, jw); + DslJsonUtil.writeFieldName(fieldName, jw); jw.writeNull(); jw.writeByte(COMMA); } } else { - writeFieldName(fieldName, jw); - writeStringValue(value, replaceBuilder, jw); + DslJsonUtil.writeFieldName(fieldName, jw); + DslJsonUtil.writeStringValue(value, replaceBuilder, jw); jw.writeByte(COMMA); } } @@ -620,16 +601,6 @@ private static void writeStringBuilderValue(StringBuilder value, JsonWriter jw) jw.writeString(value); } - public static void writeStringValue(CharSequence value, final StringBuilder replaceBuilder, final JsonWriter jw) { - if (value.length() > SerializationConstants.MAX_VALUE_LENGTH) { - replaceBuilder.setLength(0); - replaceBuilder.append(value, 0, Math.min(value.length(), SerializationConstants.MAX_VALUE_LENGTH + 1)); - writeStringBuilderValue(replaceBuilder, jw); - } else { - jw.writeString(value); - } - } - private static void writeLongStringBuilderValue(StringBuilder value, JsonWriter jw) { if (value.length() > SerializationConstants.getMaxLongStringValueLength()) { value.setLength(SerializationConstants.getMaxLongStringValueLength() - 1); @@ -649,30 +620,23 @@ private static void writeLongStringValue(CharSequence value, final StringBuilder } static void writeField(final String fieldName, final long value, final JsonWriter jw) { - writeFieldName(fieldName, jw); + DslJsonUtil.writeFieldName(fieldName, jw); NumberConverter.serialize(value, jw); jw.writeByte(COMMA); } public static void writeLastField(final String fieldName, @Nullable final CharSequence value, StringBuilder replaceBuilder, final JsonWriter jw) { - writeFieldName(fieldName, jw); + DslJsonUtil.writeFieldName(fieldName, jw); if (value != null && value.length() > 0) { - writeStringValue(value, replaceBuilder, jw); + DslJsonUtil.writeStringValue(value, replaceBuilder, jw); } else { jw.writeNull(); } } - public static void writeFieldName(final String fieldName, final JsonWriter jw) { - jw.writeByte(JsonWriter.QUOTE); - jw.writeAscii(fieldName); - jw.writeByte(JsonWriter.QUOTE); - jw.writeByte(JsonWriter.SEMI); - } - static void writeField(final String fieldName, final List values, final JsonWriter jw) { if (values.size() > 0) { - writeFieldName(fieldName, jw); + DslJsonUtil.writeFieldName(fieldName, jw); jw.writeByte(ARRAY_START); jw.writeString(values.get(0)); for (int i = 1; i < values.size(); i++) { @@ -1142,7 +1106,7 @@ private void serializeNumber(Number n, JsonWriter jw) { } private void serializeComposite(Composite composite) { - DslJsonSerializer.writeFieldName("composite", jw); + DslJsonUtil.writeFieldName("composite", jw); jw.writeByte(OBJECT_START); writeField("count", composite.getCount()); writeField("sum", composite.getSumMs()); @@ -1342,7 +1306,7 @@ private void serializeStackTraceElement(StackFrame frame, StringBuilder replaceB frame.appendFileName(replaceBuilder); writeField("filename", replaceBuilder); writeField("function", frame.getMethodName()); - writeField("library_frame", isLibraryFrame(frame.getClassName())); + writeField("library_frame", frame.getClassName() != null && isLibraryFrame(frame.getClassName())); writeLastField("lineno", -1); jw.writeByte(OBJECT_END); } @@ -1675,7 +1639,7 @@ void serializeUrl(final Url url) { } else { // serialize as a string for compatibility // doing it in low-level to avoid allocation - DslJsonSerializer.writeFieldName("port", jw); + DslJsonUtil.writeFieldName("port", jw); jw.writeByte(QUOTE); NumberConverter.serialize(port, jw); jw.writeByte(QUOTE); @@ -1787,7 +1751,7 @@ private void writeStringBuilderValue(StringBuilder value) { } private void writeStringValue(CharSequence value) { - DslJsonSerializer.writeStringValue(value, replaceBuilder, jw); + DslJsonUtil.writeStringValue(value, replaceBuilder, jw); } private void writeLongStringValue(CharSequence value) { @@ -1836,7 +1800,7 @@ void writeLastField(final String fieldName, @Nullable final CharSequence value) } private void writeFieldName(final String fieldName) { - DslJsonSerializer.writeFieldName(fieldName, jw); + DslJsonUtil.writeFieldName(fieldName, jw); } private void writeNonLastIdField(String fieldName, Id id) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/MetricRegistryReporter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/MetricRegistryReporter.java index aa1a9347a9..04327f4f0f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/MetricRegistryReporter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/MetricRegistryReporter.java @@ -18,10 +18,11 @@ */ package co.elastic.apm.agent.report.serialize; +import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.tracer.service.ServiceInfo; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.MetricSet; import co.elastic.apm.agent.report.Reporter; @@ -47,10 +48,12 @@ public MetricRegistryReporter(ElasticApmTracer tracer) { } @Override - public void start(ElasticApmTracer tracer) { + public void start(Tracer tracer) { long intervalMs = tracer.getConfig(ReporterConfiguration.class).getMetricsIntervalMs(); if (intervalMs > 0) { - tracer.getSharedSingleThreadedPool().scheduleAtFixedRate(this, intervalMs, intervalMs, TimeUnit.MILLISECONDS); + tracer.require(ElasticApmTracer.class) + .getSharedSingleThreadedPool() + .scheduleAtFixedRate(this, intervalMs, intervalMs, TimeUnit.MILLISECONDS); } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/MetricRegistrySerializer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/MetricRegistrySerializer.java index e5b3700f39..afcf9133e1 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/MetricRegistrySerializer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/MetricRegistrySerializer.java @@ -19,9 +19,10 @@ package co.elastic.apm.agent.report.serialize; import co.elastic.apm.agent.tracer.service.ServiceInfo; -import co.elastic.apm.agent.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; import co.elastic.apm.agent.metrics.MetricSet; import co.elastic.apm.agent.metrics.Timer; +import co.elastic.apm.agent.tracer.metrics.DslJsonUtil; import com.dslplatform.json.DslJson; import com.dslplatform.json.JsonWriter; import com.dslplatform.json.NumberConverter; @@ -80,14 +81,14 @@ private static boolean serialize(MetricSet metricSet, long epochMicros, String s boolean hasSamples; jw.writeByte(JsonWriter.OBJECT_START); { - DslJsonSerializer.writeFieldName("metricset", jw); + DslJsonUtil.writeFieldName("metricset", jw); jw.writeByte(JsonWriter.OBJECT_START); { - DslJsonSerializer.writeFieldName("timestamp", jw); + DslJsonUtil.writeFieldName("timestamp", jw); NumberConverter.serialize(epochMicros, jw); jw.writeByte(JsonWriter.COMMA); DslJsonSerializer.serializeLabels(metricSet.getLabels(), serviceName, serviceVersion, replaceBuilder, jw); - DslJsonSerializer.writeFieldName("samples", jw); + DslJsonUtil.writeFieldName("samples", jw); jw.writeByte(JsonWriter.OBJECT_START); hasSamples = serializeGauges(metricSet.getGauges(), jw); hasSamples |= serializeTimers(metricSet.getTimers(), hasSamples, jw); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/SerializationConstants.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/SerializationConstants.java index 8f5e4d2db0..bd927d1b8f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/SerializationConstants.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/SerializationConstants.java @@ -19,6 +19,7 @@ package co.elastic.apm.agent.report.serialize; import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.tracer.metrics.DslJsonUtil; import javax.annotation.Nullable; @@ -31,7 +32,7 @@ public class SerializationConstants { */ public static final int BUFFER_SIZE = 16384; - public static final int MAX_VALUE_LENGTH = 1024; + public static final int MAX_VALUE_LENGTH = DslJsonUtil.MAX_VALUE_LENGTH; @Nullable private static volatile SerializationConstants INSTANCE; diff --git a/apm-agent-core/src/main/resources/META-INF/services/co.elastic.apm.agent.context.LifecycleListener b/apm-agent-core/src/main/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener similarity index 100% rename from apm-agent-core/src/main/resources/META-INF/services/co.elastic.apm.agent.context.LifecycleListener rename to apm-agent-core/src/main/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerTest.java index b2771cfd8a..b365039737 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerTest.java @@ -34,7 +34,7 @@ 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.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import co.elastic.apm.agent.report.ApmServerClient; import co.elastic.apm.agent.tracer.Outcome; 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 9ba0dbc469..ddf693bd5e 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.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import net.bytebuddy.agent.ByteBuddyAgent; import org.junit.jupiter.api.AfterEach; @@ -145,12 +145,12 @@ void testStartDisabled() throws Exception { .reporter(new MockReporter()) .withLifecycleListener(new AbstractLifecycleListener() { @Override - public void init(ElasticApmTracer tracer) { + public void init(co.elastic.apm.agent.tracer.Tracer tracer) { initialized.set(true); } @Override - public void start(ElasticApmTracer tracer) throws Exception { + public void start(co.elastic.apm.agent.tracer.Tracer tracer) throws Exception { started.set(true); } }) @@ -163,7 +163,7 @@ public void start(ElasticApmTracer tracer) throws Exception { /* * Has an entry in - * src/test/resources/META-INF/services/co.elastic.apm.agent.context.LifecycleListener + * src/test/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener */ public static class TestLifecycleListener extends AbstractLifecycleListener { @@ -178,7 +178,7 @@ public TestLifecycleListener() { } @Override - public void start(ElasticApmTracer tracer) { + public void start(co.elastic.apm.agent.tracer.Tracer tracer) { start.incrementAndGet(); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/SpanTypeBreakdownTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/SpanTypeBreakdownTest.java index a090c71566..d8147bdf33 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/SpanTypeBreakdownTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/SpanTypeBreakdownTest.java @@ -26,7 +26,7 @@ import co.elastic.apm.agent.impl.transaction.AbstractSpan; import co.elastic.apm.agent.impl.transaction.Span; import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricSet; import co.elastic.apm.agent.metrics.Timer; import org.junit.jupiter.api.AfterEach; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/MetricRegistryTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/MetricRegistryTest.java index 2b445c9e54..5590fea3cc 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/MetricRegistryTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/MetricRegistryTest.java @@ -21,6 +21,8 @@ import co.elastic.apm.agent.configuration.MetricsConfiguration; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.metrics.Labels; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetricsTest.java index 814bc84cfc..093782f979 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetricsTest.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.configuration.MetricsConfiguration; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.MetricSet; import co.elastic.apm.agent.report.ReporterConfiguration; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetricsTest.java index bc86fd0cda..83527ffe6b 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetricsTest.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.configuration.MetricsConfiguration; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.MetricSet; import co.elastic.apm.agent.report.ReporterConfiguration; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/CGroupMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/CGroupMetricsTest.java index a8d80db1e0..5dd24ae174 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/CGroupMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/CGroupMetricsTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.metrics.builtin; import co.elastic.apm.agent.configuration.MetricsConfiguration; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.report.ReporterConfiguration; import org.junit.jupiter.api.Test; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmFdMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmFdMetricsTest.java index dc15f3874c..3f87b5c70c 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmFdMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmFdMetricsTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.metrics.builtin; import co.elastic.apm.agent.configuration.MetricsConfiguration; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.report.ReporterConfiguration; import org.junit.jupiter.api.condition.DisabledOnOs; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetricsTest.java index 05c4fe4348..413b148d5c 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetricsTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.metrics.builtin; import co.elastic.apm.agent.configuration.MetricsConfiguration; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.report.ReporterConfiguration; import org.assertj.core.api.AbstractDoubleAssert; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/SystemMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/SystemMetricsTest.java index dea7de26c2..3226241264 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/SystemMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/SystemMetricsTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.metrics.builtin; import co.elastic.apm.agent.configuration.MetricsConfiguration; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.report.ReporterConfiguration; import org.junit.jupiter.api.Test; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/ThreadMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/ThreadMetricsTest.java index 287047b2ea..4fec12cf1a 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/ThreadMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/ThreadMetricsTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.metrics.builtin; import co.elastic.apm.agent.configuration.MetricsConfiguration; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.report.ReporterConfiguration; import org.junit.jupiter.api.Test; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/MetricSetSerializationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/MetricSetSerializationTest.java index 7f696af5f1..1abc82a114 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/MetricSetSerializationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/MetricSetSerializationTest.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.configuration.MetricsConfiguration; import co.elastic.apm.agent.tracer.service.ServiceInfo; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricCollector; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.MetricsProvider; diff --git a/apm-agent-core/src/test/resources/META-INF/services/co.elastic.apm.agent.context.LifecycleListener b/apm-agent-core/src/test/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener similarity index 100% rename from apm-agent-core/src/test/resources/META-INF/services/co.elastic.apm.agent.context.LifecycleListener rename to apm-agent-core/src/test/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener diff --git a/apm-agent-plugins/apm-jmx-plugin/pom.xml b/apm-agent-plugins/apm-jmx-plugin/pom.xml index 64af345431..8dddd765b6 100644 --- a/apm-agent-plugins/apm-jmx-plugin/pom.xml +++ b/apm-agent-plugins/apm-jmx-plugin/pom.xml @@ -15,13 +15,4 @@ ${project.basedir}/../.. - - - - ${project.groupId} - apm-agent-core - ${project.version} - - - diff --git a/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetric.java b/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetric.java index 9fa1b4da6d..9409e810af 100644 --- a/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetric.java +++ b/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetric.java @@ -18,12 +18,11 @@ */ package co.elastic.apm.agent.jmx; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import org.stagemonitor.configuration.converter.AbstractValueConverter; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import java.util.ArrayList; diff --git a/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetricTracker.java b/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetricTracker.java index 5560f338a1..5c3733a639 100644 --- a/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetricTracker.java +++ b/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetricTracker.java @@ -18,16 +18,15 @@ */ package co.elastic.apm.agent.jmx; -import co.elastic.apm.agent.context.AbstractLifecycleListener; -import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.metrics.DoubleSupplier; -import co.elastic.apm.agent.metrics.Labels; -import co.elastic.apm.agent.metrics.MetricRegistry; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.Tracer; +import co.elastic.apm.agent.tracer.metrics.Labels; +import co.elastic.apm.agent.tracer.GlobalLocks; import co.elastic.apm.agent.sdk.internal.util.ExecutorUtils; import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; -import co.elastic.apm.agent.tracer.GlobalLocks; import co.elastic.apm.agent.tracer.configuration.TimeDuration; import org.stagemonitor.configuration.ConfigurationOption; @@ -66,8 +65,8 @@ public class JmxMetricTracker extends AbstractLifecycleListener { private volatile Thread logManagerPropertyPoller; @Nullable private volatile MBeanServer server; + private final Tracer tracer; private final JmxConfiguration jmxConfiguration; - private final MetricRegistry metricRegistry; @Nullable private volatile NotificationListener listener; @@ -76,16 +75,16 @@ public class JmxMetricTracker extends AbstractLifecycleListener { @Nullable private ScheduledExecutorService retryExecutor; - public JmxMetricTracker(ElasticApmTracer tracer) { + public JmxMetricTracker(Tracer tracer) { + this.tracer = tracer; jmxConfiguration = tracer.getConfig(JmxConfiguration.class); - metricRegistry = tracer.getMetricRegistry(); // using a synchronized list so adding to the list does not require synchronization failedMetrics = Collections.synchronizedList(new ArrayList()); } @Override - public void start(ElasticApmTracer tracer) { + public void start(Tracer tracer) { ConfigurationOption.ChangeListener> captureJmxListener = new ConfigurationOption.ChangeListener>() { @Override public void onChange(ConfigurationOption configurationOption, List oldValue, List newValue) { @@ -197,10 +196,10 @@ public void onChange(ConfigurationOption configurationOption, List for (JmxMetricRegistration addedRegistration : removeAll(oldRegistrations, newRegistrations)) { - addedRegistration.register(platformMBeanServer, metricRegistry); + addedRegistration.register(platformMBeanServer, tracer); } for (JmxMetricRegistration deletedRegistration : removeAll(newRegistrations, oldRegistrations)) { - deletedRegistration.unregister(metricRegistry); + deletedRegistration.unregister(tracer); } } }); @@ -326,7 +325,7 @@ private static List removeAll(List removeFromThis, List toRemove) { private void register(List jmxMetrics, MBeanServer server, List failedMetrics) { for (JmxMetricRegistration registration : compileJmxMetricRegistrations(jmxMetrics, server, failedMetrics)) { - registration.register(server, metricRegistry); + registration.register(server, tracer); } } @@ -474,9 +473,9 @@ private JmxMetricRegistration(String metricName, Labels labels, String jmxAttrib } - void register(final MBeanServer server, final MetricRegistry metricRegistry) { + void register(final MBeanServer server, final Tracer tracer) { logger.debug("Registering JMX metric {} {}.{} as metric_name: {} labels: {}", objectName, jmxAttribute, compositeDataKey, metricName, labels); - metricRegistry.add(metricName, labels, new DoubleSupplier() { + tracer.addGauge(metricName, labels, new DoubleSupplier() { @Override public double get() { try { @@ -489,7 +488,7 @@ public double get() { return value; } catch (InstanceNotFoundException | AttributeNotFoundException e) { if (unsubscribeOnError) { - unregister(metricRegistry); + unregister(tracer); } return Double.NaN; } catch (Exception e) { @@ -499,9 +498,9 @@ public double get() { }); } - void unregister(MetricRegistry metricRegistry) { + void unregister(Tracer tracer) { logger.debug("Unregistering JMX metric {} {}.{} metric_name: {} labels: {}", objectName, jmxAttribute, compositeDataKey, metricName, labels); - metricRegistry.removeGauge(metricName, labels); + tracer.removeGauge(metricName, labels); } @Override diff --git a/apm-agent-plugins/apm-jmx-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.context.LifecycleListener b/apm-agent-plugins/apm-jmx-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener similarity index 100% rename from apm-agent-plugins/apm-jmx-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.context.LifecycleListener rename to apm-agent-plugins/apm-jmx-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener diff --git a/apm-agent-plugins/apm-jmx-plugin/src/test/java/co/elastic/apm/agent/jmx/JmxMetricTrackerTest.java b/apm-agent-plugins/apm-jmx-plugin/src/test/java/co/elastic/apm/agent/jmx/JmxMetricTrackerTest.java index cc8eeca851..640a374bde 100644 --- a/apm-agent-plugins/apm-jmx-plugin/src/test/java/co/elastic/apm/agent/jmx/JmxMetricTrackerTest.java +++ b/apm-agent-plugins/apm-jmx-plugin/src/test/java/co/elastic/apm/agent/jmx/JmxMetricTrackerTest.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.metrics.Labels; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.report.serialize.MetricRegistrySerializer; import org.junit.jupiter.api.AfterEach; diff --git a/apm-agent-plugins/apm-micrometer-plugin/pom.xml b/apm-agent-plugins/apm-micrometer-plugin/pom.xml index 8ff7909d41..13b891a786 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/pom.xml +++ b/apm-agent-plugins/apm-micrometer-plugin/pom.xml @@ -20,12 +20,6 @@ - - - ${project.groupId} - apm-agent-core - ${project.version} - io.micrometer micrometer-core diff --git a/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/AbstractMicrometerInstrumentation.java b/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/AbstractMicrometerInstrumentation.java index f9ac5ef254..056daf8df2 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/AbstractMicrometerInstrumentation.java +++ b/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/AbstractMicrometerInstrumentation.java @@ -18,7 +18,6 @@ */ package co.elastic.apm.agent.micrometer; -import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Tracer; @@ -30,7 +29,7 @@ public abstract class AbstractMicrometerInstrumentation extends ElasticApmInstru private static final Tracer tracer = GlobalTracer.get(); - static final MicrometerMetricsReporter reporter = new MicrometerMetricsReporter(tracer.require(ElasticApmTracer.class)); + static final MicrometerMetricsReporter reporter = new MicrometerMetricsReporter(tracer); public Collection getInstrumentationGroupNames() { return Collections.singletonList("micrometer"); diff --git a/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializer.java b/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializer.java index 683df9632f..58048dde12 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializer.java +++ b/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializer.java @@ -18,13 +18,13 @@ */ package co.elastic.apm.agent.micrometer; -import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakSet; import co.elastic.apm.agent.tracer.configuration.MetricsConfiguration; +import co.elastic.apm.agent.tracer.metrics.DslJsonUtil; import com.dslplatform.json.DslJson; import com.dslplatform.json.JsonWriter; import com.dslplatform.json.NumberConverter; @@ -100,14 +100,14 @@ boolean serializeMetricSet(List tags, List meters, long epochMicros, boolean dedotMetricName = config.isDedotCustomMetrics(); jw.writeByte(JsonWriter.OBJECT_START); { - DslJsonSerializer.writeFieldName("metricset", jw); + DslJsonUtil.writeFieldName("metricset", jw); jw.writeByte(JsonWriter.OBJECT_START); { - DslJsonSerializer.writeFieldName("timestamp", jw); + DslJsonUtil.writeFieldName("timestamp", jw); NumberConverter.serialize(epochMicros, jw); jw.writeByte(JsonWriter.COMMA); serializeTags(tags, replaceBuilder, jw); - DslJsonSerializer.writeFieldName("samples", jw); + DslJsonUtil.writeFieldName("samples", jw); jw.writeByte(JsonWriter.OBJECT_START); ClassLoader originalContextCL = PrivilegedActionUtils.getContextClassLoader(Thread.currentThread()); @@ -167,16 +167,16 @@ private static void serializeTags(List tags, StringBuilder replaceBuilder, if (tags.isEmpty()) { return; } - DslJsonSerializer.writeFieldName("tags", jw); + DslJsonUtil.writeFieldName("tags", jw); jw.writeByte(OBJECT_START); for (int i = 0, tagsSize = tags.size(); i < tagsSize; i++) { Tag tag = tags.get(i); if (i > 0) { jw.writeByte(COMMA); } - DslJsonSerializer.writeStringValue(DslJsonSerializer.sanitizePropertyName(tag.getKey(), replaceBuilder), replaceBuilder, jw); + DslJsonUtil.writeStringValue(DslJsonUtil.sanitizePropertyName(tag.getKey(), replaceBuilder), replaceBuilder, jw); jw.writeByte(JsonWriter.SEMI); - DslJsonSerializer.writeStringValue(tag.getValue(), replaceBuilder, jw); + DslJsonUtil.writeStringValue(tag.getValue(), replaceBuilder, jw); } jw.writeByte(OBJECT_END); jw.writeByte(COMMA); @@ -320,7 +320,7 @@ private static void serializeValueStart(String key, String suffix, JsonWriter jw private static void serializeObjectStart(String key, String objectName, String suffix, JsonWriter jw, StringBuilder replaceBuilder, boolean dedotMetricName) { replaceBuilder.setLength(0); if (dedotMetricName) { - DslJsonSerializer.sanitizePropertyName(key, replaceBuilder); + DslJsonUtil.sanitizePropertyName(key, replaceBuilder); } else { replaceBuilder.append(key); } diff --git a/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMetricsReporter.java b/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMetricsReporter.java index 3379ce66cd..6ec9e2cbaa 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMetricsReporter.java +++ b/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMetricsReporter.java @@ -18,14 +18,12 @@ */ package co.elastic.apm.agent.micrometer; -import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.Tracer; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.report.Reporter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; +import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.tracer.configuration.MetricsConfiguration; import co.elastic.apm.agent.tracer.configuration.ReporterConfiguration; import com.dslplatform.json.JsonWriter; @@ -90,19 +88,17 @@ public class MicrometerMetricsReporter implements Runnable, Closeable { private final WeakMap meterRegistries = WeakConcurrent.buildMap(); private final WeakMap configMap = WeakConcurrent.buildMap(); private final MicrometerMeterRegistrySerializer serializer; - private final Reporter reporter; - private final ElasticApmTracer tracer; + private final Tracer tracer; private final AtomicBoolean scheduledReporting = new AtomicBoolean(); private final boolean disableScheduler; - public MicrometerMetricsReporter(ElasticApmTracer tracer) { + public MicrometerMetricsReporter(Tracer tracer) { this(tracer, false); } //constructor split up to have this available for testing - MicrometerMetricsReporter(ElasticApmTracer tracer, boolean disableSchedulerThread) { + MicrometerMetricsReporter(Tracer tracer, boolean disableSchedulerThread) { this.tracer = tracer; - this.reporter = tracer.getReporter(); tracer.addShutdownHook(this); serializer = new MicrometerMeterRegistrySerializer(tracer.getConfig(MetricsConfiguration.class)); this.disableScheduler = disableSchedulerThread; @@ -135,7 +131,7 @@ private synchronized void scheduleReporting() { // called for every class loader that loaded micrometer // that's because a new MicrometerMetricsReporter instance is created in every IndyPluginClassLoader // for example if multiple webapps use potentially different versions of Micrometer - tracer.getSharedSingleThreadedPool().scheduleAtFixedRate(this, 0, INTERVAL_BETWEEN_CHECKS_IN_MILLISECONDS, TimeUnit.MILLISECONDS); + tracer.schedule(this, INTERVAL_BETWEEN_CHECKS_IN_MILLISECONDS, TimeUnit.MILLISECONDS); } } @@ -147,7 +143,7 @@ public void run() { //run split up to have this available for testing void run(final long now) { - if (tracer.getState() != Tracer.TracerState.RUNNING) { + if (!tracer.isRunning()) { return; } long metricsIntervalMs = tracer.getConfig(ReporterConfiguration.class).getMetricsIntervalMs(); @@ -190,7 +186,7 @@ void run(final long now) { } logger.debug("Reporting {} meters", meterConsumer.meters.size()); for (JsonWriter serializedMetricSet : serializer.serialize(meterConsumer.meters, now * 1000)) { - reporter.reportMetrics(serializedMetricSet); + tracer.reportMetric(serializedMetricSet); } } @@ -220,7 +216,7 @@ private long getStep(MeterRegistry meterRegistry) { public void close() { // flushing out metrics before shutting down // this is especially important for counters as the counts that were accumulated between the last report and the shutdown would otherwise get lost - tracer.getSharedSingleThreadedPool().submit(this); + tracer.submit(this); } private static class MeterMapConsumer implements Consumer { diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/java/co/elastic/apm/agent/embeddedotel/EmbeddedSdkManager.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/java/co/elastic/apm/agent/embeddedotel/EmbeddedSdkManager.java index 9793bbbe76..95c57c60c3 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/java/co/elastic/apm/agent/embeddedotel/EmbeddedSdkManager.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/java/co/elastic/apm/agent/embeddedotel/EmbeddedSdkManager.java @@ -18,11 +18,11 @@ */ package co.elastic.apm.agent.embeddedotel; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.embeddedotel.proxy.ProxyMeterProvider; -import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.Tracer; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; @@ -40,14 +40,14 @@ public class EmbeddedSdkManager extends AbstractLifecycleListener { private static final Logger logger = LoggerFactory.getLogger(EmbeddedSdkManager.class); @Nullable - private ElasticApmTracer tracer; + private Tracer tracer; @Nullable private volatile SdkMeterProvider sdkInstance; private boolean isShutdown = false; @Override - public synchronized void start(ElasticApmTracer tracer) throws Exception { + public synchronized void start(Tracer tracer) throws Exception { this.tracer = tracer; } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/resources/META-INF/services/co.elastic.apm.agent.context.LifecycleListener b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener similarity index 100% rename from apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/resources/META-INF/services/co.elastic.apm.agent.context.LifecycleListener rename to apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/main/java/co/elastic/apm/agent/otelmetricsdk/MetricSetSerializer.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/main/java/co/elastic/apm/agent/otelmetricsdk/MetricSetSerializer.java index de8021c3bd..6484e08906 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/main/java/co/elastic/apm/agent/otelmetricsdk/MetricSetSerializer.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/main/java/co/elastic/apm/agent/otelmetricsdk/MetricSetSerializer.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.otelmetricsdk; import co.elastic.apm.agent.report.Reporter; -import co.elastic.apm.agent.report.serialize.DslJsonSerializer; +import co.elastic.apm.agent.tracer.metrics.DslJsonUtil; import com.dslplatform.json.BoolConverter; import com.dslplatform.json.DslJson; import com.dslplatform.json.JsonWriter; @@ -56,14 +56,14 @@ public MetricSetSerializer(Attributes attributes, CharSequence instrumentationSc jw = DSL_JSON.newWriter(INITIAL_BUFFER_SIZE); jw.writeByte(JsonWriter.OBJECT_START); { - DslJsonSerializer.writeFieldName("metricset", jw); + DslJsonUtil.writeFieldName("metricset", jw); jw.writeByte(JsonWriter.OBJECT_START); { - DslJsonSerializer.writeFieldName("timestamp", jw); + DslJsonUtil.writeFieldName("timestamp", jw); NumberConverter.serialize(epochMicros, jw); jw.writeByte(JsonWriter.COMMA); serializeAttributes(instrumentationScopeName, attributes); - DslJsonSerializer.writeFieldName("samples", jw); + DslJsonUtil.writeFieldName("samples", jw); jw.writeByte(JsonWriter.OBJECT_START); } } @@ -188,7 +188,7 @@ private void serializeAttributes(CharSequence instrumentationScopeName, Attribut if (attributeMap.isEmpty() && instrumentationScopeName.length() == 0) { return; } - DslJsonSerializer.writeFieldName("tags", jw); + DslJsonUtil.writeFieldName("tags", jw); jw.writeByte(OBJECT_START); boolean anyWritten = false; if (instrumentationScopeName.length() > 0) { @@ -210,7 +210,7 @@ private boolean serializeAttribute(AttributeKey key, @Nullable Object value, if (prependComma) { jw.writeByte(COMMA); } - DslJsonSerializer.writeStringValue(DslJsonSerializer.sanitizePropertyName(key.getKey(), replaceBuilder), replaceBuilder, jw); + DslJsonUtil.writeStringValue(DslJsonUtil.sanitizePropertyName(key.getKey(), replaceBuilder), replaceBuilder, jw); jw.writeByte(JsonWriter.SEMI); AttributeType type = key.getType(); diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingFactory.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingFactory.java index 400e28623c..e7ddcb77a4 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingFactory.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingFactory.java @@ -18,8 +18,9 @@ */ package co.elastic.apm.agent.profiler; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; +import co.elastic.apm.agent.tracer.Tracer; public class ProfilingFactory extends AbstractLifecycleListener { @@ -35,9 +36,10 @@ public ProfilingFactory(ElasticApmTracer tracer) { } @Override - public void start(ElasticApmTracer tracer) { + public void start(Tracer tracer) throws Exception { profiler.start(tracer); - tracer.registerSpanListener(new ProfilingActivationListener(tracer, profiler)); + ElasticApmTracer elasticApmTracer = tracer.require(ElasticApmTracer.class); + elasticApmTracer.registerSpanListener(new ProfilingActivationListener(elasticApmTracer, profiler)); } @Override diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java index 1a33248b5a..0c8cb3f674 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.profiler; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.context.AbstractLifecycleListener; +import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.transaction.Span; import co.elastic.apm.agent.impl.transaction.StackFrame; @@ -30,6 +30,7 @@ import co.elastic.apm.agent.sdk.internal.util.ExecutorUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.tracer.configuration.CoreConfiguration; import co.elastic.apm.agent.tracer.configuration.TimeDuration; import co.elastic.apm.agent.tracer.pooling.Allocator; @@ -697,7 +698,7 @@ void copyFromFiles(Path activationEvents, Path traces) throws IOException { } @Override - public void start(ElasticApmTracer tracer) { + public void start(Tracer tracer) { scheduler.submit(this); } diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.context.LifecycleListener b/apm-agent-plugins/apm-profiling-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener similarity index 100% rename from apm-agent-plugins/apm-profiling-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.context.LifecycleListener rename to apm-agent-plugins/apm-profiling-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.tracer.LifecycleListener diff --git a/apm-agent-tracer/pom.xml b/apm-agent-tracer/pom.xml index dccd4562ed..096102758d 100644 --- a/apm-agent-tracer/pom.xml +++ b/apm-agent-tracer/pom.xml @@ -24,6 +24,11 @@ apm-agent-common ${project.version} + + com.dslplatform + dsl-json + 1.9.3 + net.bytebuddy diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/context/AbstractLifecycleListener.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/AbstractLifecycleListener.java similarity index 83% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/context/AbstractLifecycleListener.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/AbstractLifecycleListener.java index 02c4f0c0be..6489ae1441 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/context/AbstractLifecycleListener.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/AbstractLifecycleListener.java @@ -16,17 +16,15 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.context; - -import co.elastic.apm.agent.impl.ElasticApmTracer; +package co.elastic.apm.agent.tracer; public abstract class AbstractLifecycleListener implements LifecycleListener { @Override - public void init(ElasticApmTracer tracer) throws Exception { + public void init(Tracer tracer) throws Exception { } @Override - public void start(ElasticApmTracer tracer) throws Exception { + public void start(Tracer tracer) throws Exception { } @Override diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/GlobalTracer.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/GlobalTracer.java index 9cae3d1b20..692ffdca5e 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/GlobalTracer.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/GlobalTracer.java @@ -19,13 +19,17 @@ package co.elastic.apm.agent.tracer; import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.tracer.pooling.ObjectPoolFactory; import co.elastic.apm.agent.tracer.reference.ReferenceCounted; import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; import co.elastic.apm.agent.tracer.service.Service; +import com.dslplatform.json.JsonWriter; import javax.annotation.Nullable; import java.util.Set; +import java.util.concurrent.TimeUnit; public class GlobalTracer implements Tracer { @@ -166,4 +170,35 @@ public void flush() { public void completeMetaData(String name, String version, String id, String region) { tracer.completeMetaData(name, version, id, region); } + + @Override + public void removeGauge(String name, Labels.Immutable labels) { + tracer.removeGauge(name, labels); + } + + @Override + public void addGauge(String name, Labels.Immutable labels, DoubleSupplier supplier) { + tracer.addGauge(name, labels, supplier); + } + + @Override + public void submit(Runnable job) { + tracer.submit(job); + } + + @Override + public void schedule(Runnable job, long interval, TimeUnit timeUnit) { + tracer.schedule(job, interval, timeUnit); + } + + @Override + public void addShutdownHook(AutoCloseable hook) { + tracer.addShutdownHook(hook); + } + + @Override + public void reportMetric(JsonWriter metrics) { + tracer.reportMetric(metrics); + } + } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/context/LifecycleListener.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/LifecycleListener.java similarity index 74% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/context/LifecycleListener.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/LifecycleListener.java index 3b4716518c..a1b55634c4 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/context/LifecycleListener.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/LifecycleListener.java @@ -16,42 +16,39 @@ * specific language governing permissions and limitations * under the License. */ -package co.elastic.apm.agent.context; - -import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.Tracer; +package co.elastic.apm.agent.tracer; /** - * A {@link LifecycleListener} notifies about the start and stop event of the {@link ElasticApmTracer}. + * A {@link LifecycleListener} notifies about the start and stop event of the {@link Tracer}. *

* 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 an {@link Tracer} argument *

*/ public interface LifecycleListener { /** - * Callback for tracer initialization. As opposed to {@link LifecycleListener#start(ElasticApmTracer)}, which may + * Callback for tracer initialization. As opposed to {@link LifecycleListener#start(Tracer)}, 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; + void init(Tracer tracer) throws Exception; /** - * Callback for when the {@link ElasticApmTracer} starts. + * Callback for when the {@link Tracer} starts. * * @param tracer The tracer. */ - void start(ElasticApmTracer tracer) throws Exception; + void start(Tracer tracer) throws Exception; /** - * Callback for when {@link ElasticApmTracer#pause()} has been called. + * Callback for when the {@link Tracer} is 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 +62,7 @@ public interface LifecycleListener { void pause() throws Exception; /** - * Callback for when {@link ElasticApmTracer#resume()} has been called. + * Callback for when {@link Tracer} resumes. *

* 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 +76,7 @@ public interface LifecycleListener { void resume() throws Exception; /** - * Callback for when {@link ElasticApmTracer#stop()} has been called. + * Callback for when the {@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 +93,14 @@ public interface LifecycleListener { * The order in which lifecycle listeners are called is non-deterministic. * *

  • - * The {@link ElasticApmTracer#getSharedSingleThreadedPool()} is shut down gracefully, + * Any {@link Tracer}-managed thread pool is shut down gracefully, * waiting a moment for the already scheduled tasks to be completed. * This means that implementations of this method can schedule a last command to this pool that is executed before shutdown. - * The {@link Tracer#getState()} will still be {@link Tracer.TracerState#RUNNING} in the tasks scheduled to - * {@link ElasticApmTracer#getSharedSingleThreadedPool()} within this method. - *
  • - *
  • - * The tracer state is set to {@link co.elastic.apm.agent.impl.Tracer.TracerState#STOPPED}. + * The {@link Tracer#isRunning()} will still be {@code true} in the tasks scheduled to + * complete within {@link Tracer}-managed threads within this method. *
  • *
  • - * The {@link co.elastic.apm.agent.report.Reporter} is closed. + * The tracer state is set to {@link Tracer#isRunning()} being {@code false}. *
  • * * diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopTracer.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopTracer.java index ac1610f99d..85fab5a76a 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopTracer.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopTracer.java @@ -19,15 +19,18 @@ package co.elastic.apm.agent.tracer; import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.tracer.pooling.ObjectPoolFactory; import co.elastic.apm.agent.tracer.reference.ReferenceCounted; import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; import co.elastic.apm.agent.tracer.service.Service; +import com.dslplatform.json.JsonWriter; import javax.annotation.Nullable; -import java.io.IOException; import java.util.Collections; import java.util.Set; +import java.util.concurrent.TimeUnit; class NoopTracer implements Tracer { @@ -140,4 +143,28 @@ public void flush() { @Override public void completeMetaData(String name, String version, String id, String region) { } + + @Override + public void addGauge(String name, Labels.Immutable labels, DoubleSupplier supplier) { + } + + @Override + public void removeGauge(String name, Labels.Immutable labels) { + } + + @Override + public void submit(Runnable job) { + } + + @Override + public void schedule(Runnable job, long interval, TimeUnit timeUnit) { + } + + @Override + public void addShutdownHook(AutoCloseable hook) { + } + + @Override + public void reportMetric(JsonWriter metrics) { + } } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Tracer.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Tracer.java index 666ea4fca6..4f1d6efc2e 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Tracer.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Tracer.java @@ -19,13 +19,17 @@ package co.elastic.apm.agent.tracer; import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; +import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.tracer.pooling.ObjectPoolFactory; import co.elastic.apm.agent.tracer.reference.ReferenceCounted; import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; import co.elastic.apm.agent.tracer.service.Service; +import com.dslplatform.json.JsonWriter; import javax.annotation.Nullable; import java.util.Set; +import java.util.concurrent.TimeUnit; public interface Tracer { @@ -92,6 +96,18 @@ public interface Tracer { @Nullable Throwable redactExceptionIfRequired(@Nullable Throwable original); + void removeGauge(String name, Labels.Immutable labels); + + void addGauge(String name, Labels.Immutable labels, DoubleSupplier supplier); + + void submit(Runnable job); + + void schedule(Runnable job, long interval, TimeUnit timeUnit); + + void addShutdownHook(AutoCloseable hook); + + void reportMetric(JsonWriter metrics); // TODO: replace with internalized DSL writer that only accepts data. + void flush(); void completeMetaData(String name, String version, String id, String region); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/DoubleSupplier.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metrics/DoubleSupplier.java similarity index 94% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/DoubleSupplier.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metrics/DoubleSupplier.java index 120a72221d..7f5087b653 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/DoubleSupplier.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metrics/DoubleSupplier.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.metrics; public interface DoubleSupplier { diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metrics/DslJsonUtil.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metrics/DslJsonUtil.java new file mode 100644 index 0000000000..256c8def4d --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metrics/DslJsonUtil.java @@ -0,0 +1,80 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.tracer.metrics; + +import com.dslplatform.json.JsonWriter; + +public class DslJsonUtil { + + public static final int MAX_VALUE_LENGTH = 1024; + + private static final String[] DISALLOWED_IN_PROPERTY_NAME = new String[]{".", "*", "\""}; + + public static void writeFieldName(final String fieldName, final JsonWriter jw) { + jw.writeByte(JsonWriter.QUOTE); + jw.writeAscii(fieldName); + jw.writeByte(JsonWriter.QUOTE); + jw.writeByte(JsonWriter.SEMI); + } + + + public static CharSequence sanitizePropertyName(String key, StringBuilder replaceBuilder) { + for (int i = 0; i < DISALLOWED_IN_PROPERTY_NAME.length; i++) { + if (key.contains(DISALLOWED_IN_PROPERTY_NAME[i])) { + return replaceAll(key, DISALLOWED_IN_PROPERTY_NAME, "_", replaceBuilder); + } + } + return key; + } + + private static CharSequence replaceAll(String s, String[] stringsToReplace, String replacement, StringBuilder replaceBuilder) { + // uses a instance variable StringBuilder to avoid allocations + replaceBuilder.setLength(0); + replaceBuilder.append(s); + for (String toReplace : stringsToReplace) { + replace(replaceBuilder, toReplace, replacement, 0); + } + return replaceBuilder; + } + + static void replace(StringBuilder replaceBuilder, String toReplace, String replacement, int fromIndex) { + for (int i = replaceBuilder.indexOf(toReplace, fromIndex); i != -1; i = replaceBuilder.indexOf(toReplace, fromIndex)) { + replaceBuilder.replace(i, i + toReplace.length(), replacement); + fromIndex = i; + } + } + + public static void writeStringValue(CharSequence value, final StringBuilder replaceBuilder, final JsonWriter jw) { + if (value.length() > MAX_VALUE_LENGTH) { + replaceBuilder.setLength(0); + replaceBuilder.append(value, 0, Math.min(value.length(), MAX_VALUE_LENGTH + 1)); + writeStringBuilderValue(replaceBuilder, jw); + } else { + jw.writeString(value); + } + } + + private static void writeStringBuilderValue(StringBuilder value, JsonWriter jw) { + if (value.length() > MAX_VALUE_LENGTH) { + value.setLength(MAX_VALUE_LENGTH - 1); + value.append('…'); + } + jw.writeString(value); + } +} diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/Labels.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metrics/Labels.java similarity index 98% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/Labels.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metrics/Labels.java index c6a2e0475d..a48076bbed 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/Labels.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metrics/Labels.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.metrics; import co.elastic.apm.agent.tracer.pooling.Recyclable; @@ -31,10 +31,6 @@ * However, there are also top-level labels which are not nested under the {@code labels} object, * for example {@link #getTransactionName()}, {@link #getTransactionType()}, {@link #getSpanType()} and {@link #getSpanSubType()}. *

    - * 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-core/src/test/java/co/elastic/apm/agent/metrics/LabelsTest.java b/apm-agent-tracer/src/test/java/co/elastic/apm/agent/tracer/metrics/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/metrics/LabelsTest.java index 21e55850c0..ef68d9a229 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/metrics/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.metrics; import org.junit.jupiter.api.Test;