diff --git a/newrelic-agent/build.gradle b/newrelic-agent/build.gradle index 4cf969a536..78ad1dc268 100644 --- a/newrelic-agent/build.gradle +++ b/newrelic-agent/build.gradle @@ -74,7 +74,7 @@ dependencies { transitive = false } shadowIntoJar("com.newrelic.agent.java:newrelic-module-util-java:2.1") - shadowIntoJar("com.newrelic:jfr-daemon:1.11.1") + shadowIntoJar("com.newrelic:jfr-daemon:1.12.0") shadowIntoJar "org.ow2.asm:asm:$asmVersion" shadowIntoJar "org.ow2.asm:asm-tree:$asmVersion" shadowIntoJar "org.ow2.asm:asm-commons:$asmVersion" diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java b/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java index d8b12778c6..68afb686ff 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java @@ -21,12 +21,14 @@ import com.newrelic.jfr.daemon.*; import com.newrelic.telemetry.Attributes; +import java.net.InetAddress; import java.net.URI; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.logging.Level; import static com.newrelic.jfr.daemon.AttributeNames.ENTITY_GUID; +import static com.newrelic.jfr.daemon.AttributeNames.HOSTNAME; import static com.newrelic.jfr.daemon.SetupUtils.buildCommonAttributes; import static com.newrelic.jfr.daemon.SetupUtils.buildUploader; @@ -56,7 +58,8 @@ protected void doStart() { final String entityGuid = ServiceFactory.getRPMService().getEntityGuid(); Agent.LOG.log(Level.INFO, "JFR Monitor obtained entity guid from agent: " + entityGuid); commonAttrs.put(ENTITY_GUID, entityGuid); - + final String hostname = getHostname(); + commonAttrs.put(HOSTNAME, hostname); final JFRUploader uploader = buildUploader(daemonConfig); String pattern = defaultAgentConfig.getValue(ThreadService.NAME_PATTERN_CFG_KEY, ThreadNameNormalizer.DEFAULT_PATTERN); uploader.readyToSend(new EventConverter(commonAttrs, pattern)); @@ -64,14 +67,14 @@ protected void doStart() { ExecutorService jfrMonitorService = Executors.newSingleThreadExecutor(); jfrMonitorService.submit( - () -> { - try { - startJfrLoop(); - } catch (JfrRecorderException e) { - Agent.LOG.log(Level.INFO, "Error in JFR Monitor, shutting down", e); - jfrController.shutdown(); - } - }); + () -> { + try { + startJfrLoop(); + } catch (JfrRecorderException e) { + Agent.LOG.log(Level.INFO, "Error in JFR Monitor, shutting down", e); + jfrController.shutdown(); + } + }); } catch (Throwable t) { Agent.LOG.log(Level.INFO, "Unable to attach JFR Monitor", t); } @@ -118,21 +121,37 @@ boolean coreApisExist() { return true; } + private String getHostname() { + String host; + Integer appPort = ServiceFactory + .getEnvironmentService() + .getEnvironment() + .getAgentIdentity() + .getServerPort(); + try { + host = InetAddress.getLocalHost().getHostName(); + } catch (Exception e) { + logger.error(e.getMessage()); + host = InetAddress.getLoopbackAddress().getHostAddress(); + } + return String.format("%s:%s", host, appPort); + } + @VisibleForTesting DaemonConfig buildDaemonConfig() { DaemonConfig.Builder builder = DaemonConfig.builder() - .daemonVersion(VersionFinder.getVersion()) - .useLicenseKey(jfrConfig.useLicenseKey()) - .apiKey(defaultAgentConfig.getLicenseKey()) - .monitoredAppName(defaultAgentConfig.getApplicationName()) - .auditLogging(jfrConfig.auditLoggingEnabled()) - .metricsUri(URI.create(defaultAgentConfig.getMetricIngestUri())) - .eventsUri(URI.create(defaultAgentConfig.getEventIngestUri())) - .proxyHost(defaultAgentConfig.getProxyHost()) - .proxyScheme(defaultAgentConfig.getProxyScheme()) - .proxyPort(defaultAgentConfig.getProxyPort()) - .proxyUser(defaultAgentConfig.getProxyUser()) - .proxyPassword(defaultAgentConfig.getProxyPassword()); + .daemonVersion(VersionFinder.getVersion()) + .useLicenseKey(jfrConfig.useLicenseKey()) + .apiKey(defaultAgentConfig.getLicenseKey()) + .monitoredAppName(defaultAgentConfig.getApplicationName()) + .auditLogging(jfrConfig.auditLoggingEnabled()) + .metricsUri(URI.create(defaultAgentConfig.getMetricIngestUri())) + .eventsUri(URI.create(defaultAgentConfig.getEventIngestUri())) + .proxyHost(defaultAgentConfig.getProxyHost()) + .proxyScheme(defaultAgentConfig.getProxyScheme()) + .proxyPort(defaultAgentConfig.getProxyPort()) + .proxyUser(defaultAgentConfig.getProxyUser()) + .proxyPassword(defaultAgentConfig.getProxyPassword()); return builder.build(); }