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 25e26f2bf4..6639e57be2 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java @@ -26,6 +26,8 @@ import co.elastic.apm.agent.configuration.CoreConfiguration; import co.elastic.apm.agent.configuration.MetricsConfiguration; import co.elastic.apm.agent.configuration.ServerlessConfiguration; +import co.elastic.apm.agent.impl.metadata.ServiceFactory; +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; @@ -973,4 +975,24 @@ public Set getTraceHeaderNames() { public ServiceInfo autoDetectedServiceInfo() { return AutoDetectedServiceInfo.autoDetected(); } + + @Override + public void reportLog(String log) { + reporter.reportLog(log); + } + + @Override + public void reportLog(byte[] log) { + reporter.reportLog(log); + } + + @Nullable + @Override + public Service createService(String ephemeralId) { + return new ServiceFactory().createService( + coreConfiguration, + ephemeralId, + configurationRegistry.getConfig(ServerlessConfiguration.class).runsOnAwsLambda() + ); + } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Node.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Node.java index c56f58bb0c..11717c4e1a 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Node.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Node.java @@ -23,7 +23,7 @@ /** * A representation of a service node, ie JVM */ -public class Node { +public class Node implements co.elastic.apm.agent.tracer.service.Node { /** * (Optional) @@ -37,6 +37,7 @@ public Node(@Nullable String name) { } @Nullable + @Override public String getName() { return name; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Service.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Service.java index ac666749a0..6c44db9159 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Service.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Service.java @@ -25,7 +25,7 @@ /** * Information about the instrumented Service */ -public class Service { +public class Service implements co.elastic.apm.agent.tracer.service.Service { /** * Name and version of the Elastic APM agent @@ -127,10 +127,8 @@ public Service withLanguage(Language language) { return this; } - /** - * Representation of a service node - */ @Nullable + @Override public Node getNode() { return node; } @@ -143,11 +141,8 @@ public Service withNode(Node node) { return this; } - /** - * Immutable name of the service emitting this event - * (Required) - */ @Nullable + @Override public String getName() { return name; } @@ -161,10 +156,8 @@ public Service withName(String name) { return this; } - /** - * Environment name of the service, e.g. "production" or "staging" - */ @Nullable + @Override public String getEnvironment() { return environment; } @@ -193,10 +186,8 @@ public Service withRuntime(RuntimeInfo runtime) { return this; } - /** - * Version of the service emitting this event - */ @Nullable + @Override public String getVersion() { return version; } diff --git a/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml b/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml index e002528b8a..1127e9427d 100644 --- a/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml +++ b/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml @@ -16,13 +16,6 @@ - - - ${project.groupId} - apm-agent-core - ${project.version} - - co.elastic.logging diff --git a/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/src/main/java/co/elastic/apm/agent/jul/error/JulLoggerErrorCapturingInstrumentation.java b/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/src/main/java/co/elastic/apm/agent/jul/error/JulLoggerErrorCapturingInstrumentation.java index 744956f7c4..7357599636 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/src/main/java/co/elastic/apm/agent/jul/error/JulLoggerErrorCapturingInstrumentation.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/src/main/java/co/elastic/apm/agent/jul/error/JulLoggerErrorCapturingInstrumentation.java @@ -18,7 +18,6 @@ */ package co.elastic.apm.agent.jul.error; -import co.elastic.apm.agent.impl.Tracer; import co.elastic.apm.agent.loginstr.error.AbstractLoggerErrorCapturingInstrumentation; import co.elastic.apm.agent.loginstr.error.LoggerErrorHelper; import net.bytebuddy.asm.Advice; diff --git a/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/src/main/java/co/elastic/apm/agent/jul/reformatting/AbstractJulEcsReformattingHelper.java b/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/src/main/java/co/elastic/apm/agent/jul/reformatting/AbstractJulEcsReformattingHelper.java index 7e0eb6fd25..b5284b4981 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/src/main/java/co/elastic/apm/agent/jul/reformatting/AbstractJulEcsReformattingHelper.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/src/main/java/co/elastic/apm/agent/jul/reformatting/AbstractJulEcsReformattingHelper.java @@ -21,10 +21,10 @@ import co.elastic.apm.agent.jul.sending.JulLogSenderHandler; import co.elastic.apm.agent.loginstr.correlation.CorrelationIdMapAdapter; import co.elastic.apm.agent.loginstr.reformatting.AbstractEcsReformattingHelper; -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.internal.util.LoggerUtils; +import co.elastic.apm.agent.tracer.Tracer; import co.elastic.logging.AdditionalField; import co.elastic.logging.jul.EcsFormatter; @@ -151,8 +151,8 @@ private static FileHandler doCreateFileHandler(String pattern, int maxLogFileSiz protected abstract boolean isFileHandler(Handler originalHandler); @Override - protected T createAndStartLogSendingAppender(Reporter reporter, Formatter formatter) { - return (T) new JulLogSenderHandler(reporter, formatter); + protected T createAndStartLogSendingAppender(Tracer tracer, Formatter formatter) { + return (T) new JulLogSenderHandler(tracer, formatter); } @Override diff --git a/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/src/main/java/co/elastic/apm/agent/jul/sending/JulLogSenderHandler.java b/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/src/main/java/co/elastic/apm/agent/jul/sending/JulLogSenderHandler.java index 58fcf82b81..975f5f0b91 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/src/main/java/co/elastic/apm/agent/jul/sending/JulLogSenderHandler.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/src/main/java/co/elastic/apm/agent/jul/sending/JulLogSenderHandler.java @@ -18,24 +18,24 @@ */ package co.elastic.apm.agent.jul.sending; -import co.elastic.apm.agent.report.Reporter; +import co.elastic.apm.agent.tracer.Tracer; import java.util.logging.Formatter; import java.util.logging.Handler; import java.util.logging.LogRecord; public class JulLogSenderHandler extends Handler { - private final Reporter reporter; + private final Tracer tracer; private final Formatter formatter; - public JulLogSenderHandler(Reporter reporter, Formatter formatter) { - this.reporter = reporter; + public JulLogSenderHandler(Tracer tracer, Formatter formatter) { + this.tracer = tracer; this.formatter = formatter; } @Override public void publish(LogRecord record) { - reporter.reportLog(formatter.format(record)); + tracer.reportLog(formatter.format(record)); } @Override diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j1-plugin/src/main/java/co/elastic/apm/agent/log4j1/reformatting/Log4J1EcsReformattingHelper.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j1-plugin/src/main/java/co/elastic/apm/agent/log4j1/reformatting/Log4J1EcsReformattingHelper.java index f70bbd550b..2d6f88910d 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j1-plugin/src/main/java/co/elastic/apm/agent/log4j1/reformatting/Log4J1EcsReformattingHelper.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j1-plugin/src/main/java/co/elastic/apm/agent/log4j1/reformatting/Log4J1EcsReformattingHelper.java @@ -22,9 +22,9 @@ import co.elastic.apm.agent.loginstr.reformatting.AbstractEcsReformattingHelper; import co.elastic.apm.agent.loginstr.reformatting.Utils; -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.tracer.Tracer; import co.elastic.logging.log4j.EcsLayout; import org.apache.log4j.Appender; import org.apache.log4j.FileAppender; @@ -112,8 +112,8 @@ protected void closeShadeAppender(WriterAppender shadeAppender) { } @Override - protected Appender createAndStartLogSendingAppender(Reporter reporter, Layout formatter) { - return new LogSenderAppender(reporter, formatter); + protected Appender createAndStartLogSendingAppender(Tracer tracer, Layout formatter) { + return new LogSenderAppender(tracer, formatter); } @Override diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j1-plugin/src/main/java/co/elastic/apm/agent/log4j1/sending/LogSenderAppender.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j1-plugin/src/main/java/co/elastic/apm/agent/log4j1/sending/LogSenderAppender.java index ae1c66987f..80fc697bbf 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j1-plugin/src/main/java/co/elastic/apm/agent/log4j1/sending/LogSenderAppender.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j1-plugin/src/main/java/co/elastic/apm/agent/log4j1/sending/LogSenderAppender.java @@ -18,17 +18,17 @@ */ package co.elastic.apm.agent.log4j1.sending; -import co.elastic.apm.agent.report.Reporter; +import co.elastic.apm.agent.tracer.Tracer; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.Layout; import org.apache.log4j.spi.LoggingEvent; public class LogSenderAppender extends AppenderSkeleton { - private final Reporter reporter; + private final Tracer tracer; private final Layout formatter; - public LogSenderAppender(Reporter reporter, Layout formatter) { - this.reporter = reporter; + public LogSenderAppender(Tracer tracer, Layout formatter) { + this.tracer = tracer; this.formatter = formatter; } @@ -39,7 +39,7 @@ public synchronized void doAppend(LoggingEvent event) { @Override protected void append(LoggingEvent event) { - reporter.reportLog(formatter.format(event)); + tracer.reportLog(formatter.format(event)); } @Override diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/correlation/Log4j2_7PlusLogCorrelationHelper.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/correlation/Log4j2_7PlusLogCorrelationHelper.java index 0551af209a..fd0b2ac813 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/correlation/Log4j2_7PlusLogCorrelationHelper.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/correlation/Log4j2_7PlusLogCorrelationHelper.java @@ -19,7 +19,6 @@ package co.elastic.apm.agent.log4j2.correlation; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.error.ErrorCapture; import co.elastic.apm.agent.loginstr.correlation.AbstractLogCorrelationHelper; import co.elastic.apm.agent.loginstr.correlation.CorrelationIdMapAdapter; import co.elastic.apm.agent.tracer.Tracer; diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/reformatting/Log4J2EcsReformattingHelper.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/reformatting/Log4J2EcsReformattingHelper.java index a9c7f519bc..399f8b77e4 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/reformatting/Log4J2EcsReformattingHelper.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/reformatting/Log4J2EcsReformattingHelper.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.log4j2.sending.Log4j2LogSenderAppender; import co.elastic.apm.agent.loginstr.reformatting.AbstractEcsReformattingHelper; import co.elastic.apm.agent.loginstr.reformatting.Utils; -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.tracer.Tracer; import co.elastic.logging.log4j2.EcsLayout; import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Layout; @@ -155,8 +155,8 @@ protected void closeShadeAppender(Appender shadeAppender) { } @Override - protected Appender createAndStartLogSendingAppender(Reporter reporter, Layout ecsLayout) { - Log4j2LogSenderAppender appender = new Log4j2LogSenderAppender(reporter, (StringLayout) ecsLayout); + protected Appender createAndStartLogSendingAppender(Tracer tracer, Layout ecsLayout) { + Log4j2LogSenderAppender appender = new Log4j2LogSenderAppender(tracer, (StringLayout) ecsLayout); appender.start(); return appender; } diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/sending/Log4j2LogSenderAppender.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/sending/Log4j2LogSenderAppender.java index 652d30de3a..b48cb99aa4 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/sending/Log4j2LogSenderAppender.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/main/java/co/elastic/apm/agent/log4j2/sending/Log4j2LogSenderAppender.java @@ -18,25 +18,25 @@ */ package co.elastic.apm.agent.log4j2.sending; -import co.elastic.apm.agent.report.Reporter; +import co.elastic.apm.agent.tracer.Tracer; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.StringLayout; import org.apache.logging.log4j.core.appender.AbstractAppender; public class Log4j2LogSenderAppender extends AbstractAppender { - private final Reporter reporter; + private final Tracer tracer; private final StringLayout ecsLayout; - public Log4j2LogSenderAppender(Reporter reporter, StringLayout ecsLayout) { + public Log4j2LogSenderAppender(Tracer tracer, StringLayout ecsLayout) { super("ElasticApmAppender", null, ecsLayout, true, null); - this.reporter = reporter; + this.tracer = tracer; this.ecsLayout = ecsLayout; } @Override public void append(LogEvent event) { - reporter.reportLog(ecsLayout.toSerializable(event)); + tracer.reportLog(ecsLayout.toSerializable(event)); } } diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/src/main/java/co/elastic/apm/agent/logback/reformatting/LogbackEcsReformattingHelper.java b/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/src/main/java/co/elastic/apm/agent/logback/reformatting/LogbackEcsReformattingHelper.java index 6ebb056352..6a64591cd5 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/src/main/java/co/elastic/apm/agent/logback/reformatting/LogbackEcsReformattingHelper.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/src/main/java/co/elastic/apm/agent/logback/reformatting/LogbackEcsReformattingHelper.java @@ -32,9 +32,9 @@ import co.elastic.apm.agent.loginstr.reformatting.AbstractEcsReformattingHelper; import co.elastic.apm.agent.loginstr.reformatting.Utils; 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.tracer.Tracer; import co.elastic.logging.AdditionalField; import co.elastic.logging.logback.EcsEncoder; @@ -158,8 +158,8 @@ protected void closeShadeAppender(OutputStreamAppender shadeAppen } @Override - protected Appender createAndStartLogSendingAppender(Reporter reporter, Encoder formatter) { - LogbackLogSenderAppender appender = new LogbackLogSenderAppender(reporter, formatter); + protected Appender createAndStartLogSendingAppender(Tracer tracer, Encoder formatter) { + LogbackLogSenderAppender appender = new LogbackLogSenderAppender(tracer, formatter); appender.start(); return appender; } diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/src/main/java/co/elastic/apm/agent/logback/sending/LogbackLogSenderAppender.java b/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/src/main/java/co/elastic/apm/agent/logback/sending/LogbackLogSenderAppender.java index 3e2e3fea2f..539bd6211d 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/src/main/java/co/elastic/apm/agent/logback/sending/LogbackLogSenderAppender.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/src/main/java/co/elastic/apm/agent/logback/sending/LogbackLogSenderAppender.java @@ -21,15 +21,15 @@ import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.UnsynchronizedAppenderBase; import ch.qos.logback.core.encoder.Encoder; -import co.elastic.apm.agent.report.Reporter; +import co.elastic.apm.agent.tracer.Tracer; import co.elastic.logging.logback.EcsEncoder; public class LogbackLogSenderAppender extends UnsynchronizedAppenderBase { - private final Reporter reporter; + private final Tracer tracer; private final EcsEncoder formatter; - public LogbackLogSenderAppender(Reporter reporter, Encoder formatter) { - this.reporter = reporter; + public LogbackLogSenderAppender(Tracer tracer, Encoder formatter) { + this.tracer = tracer; // Due to API compatibility (see below in 'append'), we have to use our own formatter type rather than the // base/interface class from logback. if (!(formatter instanceof EcsEncoder)) { @@ -42,6 +42,6 @@ public LogbackLogSenderAppender(Reporter reporter, Encoder format protected void append(ILoggingEvent eventObject) { // the Formatter interface was changed in logback 1.x, but our ECS implementation is compatible with both // older and newer versions of the API so we can rely on the more recent version of the API - reporter.reportLog(formatter.encode(eventObject)); + tracer.reportLog(formatter.encode(eventObject)); } } diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/reformatting/AbstractEcsReformattingHelper.java b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/reformatting/AbstractEcsReformattingHelper.java index 75af126a95..623c854314 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/reformatting/AbstractEcsReformattingHelper.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/reformatting/AbstractEcsReformattingHelper.java @@ -18,13 +18,9 @@ */ package co.elastic.apm.agent.loginstr.reformatting; -import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.metadata.Service; -import co.elastic.apm.agent.impl.metadata.ServiceFactory; import co.elastic.apm.agent.tracer.configuration.LogEcsReformatting; 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.state.CallDepth; @@ -35,6 +31,8 @@ import co.elastic.apm.agent.tracer.configuration.CoreConfiguration; import co.elastic.apm.agent.tracer.configuration.LoggingConfiguration; import co.elastic.apm.agent.tracer.configuration.ServerlessConfiguration; +import co.elastic.apm.agent.tracer.service.Service; +import co.elastic.apm.agent.tracer.service.ServiceAwareTracer; import javax.annotation.Nullable; import java.util.List; @@ -168,26 +166,28 @@ public abstract class AbstractEcsReformattingHelper { @Nullable private final Map additionalFields; - private final Reporter reporter; + private final Tracer tracer; public AbstractEcsReformattingHelper() { - Tracer tracer = GlobalTracer.get(); + tracer = GlobalTracer.get(); loggingConfiguration = tracer.getConfig(LoggingConfiguration.class); additionalFields = loggingConfiguration.getLogEcsReformattingAdditionalFields(); - Service service = new ServiceFactory().createService( - tracer.getConfig(CoreConfiguration.class), - "", - tracer.getConfig(ServerlessConfiguration.class).runsOnAwsLambda() - ); - globalServiceName = service.getName(); - globalServiceVersion = service.getVersion(); - if (service.getNode() != null) { - configuredServiceNodeName = service.getNode().getName(); - } else { + Service service = tracer.createService(""); + if (service == null) { + globalServiceName = null; + globalServiceVersion = null; configuredServiceNodeName = null; + environment = null; + } else { + globalServiceName = service.getName(); + globalServiceVersion = service.getVersion(); + if (service.getNode() != null) { + configuredServiceNodeName = service.getNode().getName(); + } else { + configuredServiceNodeName = null; + } + environment = service.getEnvironment(); } - environment = service.getEnvironment(); - reporter = tracer.require(ElasticApmTracer.class).getReporter(); } /** @@ -330,7 +330,7 @@ private Object createAndMapSendingAppenderFor(final A originalAppender) { } sendingAppender = NULL_APPENDER; try { - sendingAppender = createAndStartLogSendingAppender(reporter, createEcsFormatter(originalAppender)); + sendingAppender = createAndStartLogSendingAppender(tracer, createEcsFormatter(originalAppender)); originalAppender2sendingAppender.put(originalAppender, sendingAppender); } catch (Throwable throwable) { logger.warn(String.format("Failed to create ECS shipper appender for log appender %s.%s. " + @@ -538,7 +538,7 @@ protected long getDefaultMaxLogFileSize() { protected abstract void closeShadeAppender(A shadeAppender); - protected abstract B createAndStartLogSendingAppender(Reporter reporter, F formatter); + protected abstract B createAndStartLogSendingAppender(Tracer tracer, F formatter); protected abstract void append(L logEvent, B appender); } diff --git a/apm-agent-plugins/apm-logging-plugin/pom.xml b/apm-agent-plugins/apm-logging-plugin/pom.xml index 4e26c9a0ef..333dce4ac2 100644 --- a/apm-agent-plugins/apm-logging-plugin/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/pom.xml @@ -27,13 +27,4 @@ apm-jul-plugin - - - - ${project.groupId} - apm-agent-core - ${project.version} - - - diff --git a/apm-agent-plugins/apm-servlet-plugin/pom.xml b/apm-agent-plugins/apm-servlet-plugin/pom.xml index 7e9d59e5f5..6c55c37d9e 100644 --- a/apm-agent-plugins/apm-servlet-plugin/pom.xml +++ b/apm-agent-plugins/apm-servlet-plugin/pom.xml @@ -16,12 +16,6 @@ - - - ${project.groupId} - apm-agent-core - ${project.version} - ${project.groupId} apm-java-concurrent-plugin diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/pom.xml b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/pom.xml index 2cf09ff875..d3547ad591 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/pom.xml +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/pom.xml @@ -33,12 +33,6 @@ - - - ${project.groupId} - apm-agent-core - ${project.version} - javax.servlet javax.servlet-api 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 031f927381..1ad88cd129 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 @@ -22,6 +22,7 @@ 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 javax.annotation.Nullable; import java.util.Set; @@ -133,4 +134,20 @@ public Transaction startChildTransaction(@Nullable C headerCarrier, He public ErrorCapture captureException(@Nullable Throwable e, @Nullable ClassLoader initiatingClassLoader) { return tracer.captureException(e, initiatingClassLoader); } + + @Override + public void reportLog(String log) { + tracer.reportLog(log); + } + + @Override + public void reportLog(byte[] log) { + tracer.reportLog(log); + } + + @Nullable + @Override + public Service createService(String ephemeralId) { + return tracer.createService(ephemeralId); + } } 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 6088e75683..2c2727152d 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 @@ -22,6 +22,7 @@ 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 javax.annotation.Nullable; import java.util.Collections; @@ -110,4 +111,18 @@ public Transaction startChildTransaction(@Nullable C headerCarrier, He public ErrorCapture captureException(@Nullable Throwable e, @Nullable ClassLoader initiatingClassLoader) { return null; } + + @Override + public void reportLog(String log) { + } + + @Override + public void reportLog(byte[] log) { + } + + @Override + @Nullable + public Service createService(String ephemeralId) { + return null; + } } 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 97f8e8bb87..b7f9042142 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 @@ -22,6 +22,7 @@ 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 javax.annotation.Nullable; import java.util.Set; @@ -80,4 +81,11 @@ public interface Tracer { @Nullable ErrorCapture captureException(@Nullable Throwable e, @Nullable ClassLoader initiatingClassLoader); + + void reportLog(String log); + + void reportLog(byte[] log); + + @Nullable + Service createService(String ephemeralId); } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/service/Node.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/service/Node.java new file mode 100644 index 0000000000..6eb3a9c1e9 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/service/Node.java @@ -0,0 +1,27 @@ +/* + * 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.service; + +import javax.annotation.Nullable; + +public interface Node { + + @Nullable + String getName(); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/service/Service.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/service/Service.java new file mode 100644 index 0000000000..18b95dcba8 --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/service/Service.java @@ -0,0 +1,49 @@ +/* + * 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.service; + +import javax.annotation.Nullable; + +public interface Service { + + /** + * Immutable name of the service emitting this event + * (Required) + */ + @Nullable + String getName(); + + /** + * Version of the service emitting this event + */ + @Nullable + String getVersion(); + + /** + * Representation of a service node + */ + @Nullable + Node getNode(); + + /** + * Environment name of the service, e.g. "production" or "staging" + */ + @Nullable + String getEnvironment(); +} diff --git a/integration-tests/spring-boot-1-5/pom.xml b/integration-tests/spring-boot-1-5/pom.xml index bb6482860b..ac2d91b9b3 100644 --- a/integration-tests/spring-boot-1-5/pom.xml +++ b/integration-tests/spring-boot-1-5/pom.xml @@ -28,6 +28,12 @@ apm-servlet-plugin ${project.version} + + ${project.groupId} + apm-agent-core + ${project.version} + test + ${project.groupId} apm-agent-core