From 13846dd444ad89af2d5e731c4fd10bef25c6889c Mon Sep 17 00:00:00 2001 From: Marty T <120425148+tippmar-nr@users.noreply.github.com> Date: Fri, 8 Dec 2023 11:56:43 -0600 Subject: [PATCH] chore: Add Install Type to environment variables that BMDS can capture. (#2126) --- .../Core/AgentHealth/AgentHealthReporter.cs | 20 +++---------------- .../Agent/Core/AgentHealth/AgentInfo.cs | 5 +++++ .../Agent/Core/AgentInstallConfiguration.cs | 2 +- src/Agent/NewRelic/Agent/Core/Environment.cs | 3 +++ 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Agent/NewRelic/Agent/Core/AgentHealth/AgentHealthReporter.cs b/src/Agent/NewRelic/Agent/Core/AgentHealth/AgentHealthReporter.cs index c8cc9ba788..659046ef25 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentHealth/AgentHealthReporter.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentHealth/AgentHealthReporter.cs @@ -67,7 +67,6 @@ private void LogPeriodicReport() { Log.Debug(logMessage); } - List events = new List(); foreach (var counter in _agentHealthEventCounters) { @@ -226,20 +225,7 @@ public void ReportErrorEventsSent(int count) public void ReportAgentInfo() { - if (AgentInstallConfiguration.AgentInfo == null) - { - TrySend(_metricBuilder.TryBuildInstallTypeMetric("Unknown")); - return; - } - - if (AgentInstallConfiguration.AgentInfo.AzureSiteExtension) - { - TrySend(_metricBuilder.TryBuildInstallTypeMetric((AgentInstallConfiguration.AgentInfo.InstallType ?? "Unknown") + "SiteExtension")); - } - else - { - TrySend(_metricBuilder.TryBuildInstallTypeMetric(AgentInstallConfiguration.AgentInfo.InstallType ?? "Unknown")); - } + TrySend(_metricBuilder.TryBuildInstallTypeMetric(AgentInstallConfiguration.AgentInfo?.ToString() ?? "Unknown")); } public void ReportTransactionGarbageCollected(TransactionMetricName transactionMetricName, string lastStartedSegmentName, string lastFinishedSegmentName) @@ -661,7 +647,7 @@ public void ReportLoggingEventsSent(int count) _agentHealthEventCounters[AgentHealthEvent.Log]?.Add(count); } - public void ReportLoggingEventsDropped(int droppedCount)=> TrySend(_metricBuilder.TryBuildSupportabilityLoggingEventsDroppedMetric(droppedCount)); + public void ReportLoggingEventsDropped(int droppedCount) => TrySend(_metricBuilder.TryBuildSupportabilityLoggingEventsDroppedMetric(droppedCount)); public void ReportIfAppDomainCachingDisabled() { @@ -678,7 +664,7 @@ public void ReportLogForwardingConfiguredValues() ReportSupportabilityCountMetric(MetricNames.GetSupportabilityLogDecoratingConfiguredName(_configuration.LogDecoratorEnabled)); } -#endregion + #endregion public void ReportSupportabilityPayloadsDroppeDueToMaxPayloadSizeLimit(string endpoint) { diff --git a/src/Agent/NewRelic/Agent/Core/AgentHealth/AgentInfo.cs b/src/Agent/NewRelic/Agent/Core/AgentHealth/AgentInfo.cs index a2ca3e8c77..dc98033997 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentHealth/AgentInfo.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentHealth/AgentInfo.cs @@ -12,5 +12,10 @@ public class AgentInfo [JsonProperty(PropertyName = "azure_site_extension", NullValueHandling = NullValueHandling.Ignore)] public bool AzureSiteExtension { get; set; } + + public override string ToString() + { + return $"{InstallType ?? "Unknown"}{(AzureSiteExtension ? "SiteExtension" : "")}"; + } } } diff --git a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs index 67c97d7fbf..01b8b64766 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs @@ -198,7 +198,7 @@ private static string GetNewRelicLogLevel() return System.Environment.GetEnvironmentVariable(NewRelicLogLevelEnvironmentVariable); } - private static AgentInfo GetAgentInfo() + public static AgentInfo GetAgentInfo() { var agentInfoPath = $@"{NewRelicHome}\agentinfo.json"; if (File.Exists(agentInfoPath)) diff --git a/src/Agent/NewRelic/Agent/Core/Environment.cs b/src/Agent/NewRelic/Agent/Core/Environment.cs index 4ff3362e0e..19165eecc6 100644 --- a/src/Agent/NewRelic/Agent/Core/Environment.cs +++ b/src/Agent/NewRelic/Agent/Core/Environment.cs @@ -125,7 +125,10 @@ public Environment(ISystemInfo systemInfo, IProcessStatic processStatic, IConfig AddVariable("Physical Processors", () => managementObject["NumberOfProcessors"]); AddVariable("Logical Processors", () => managementObject["NumberOfLogicalProcessors"]); } + #endif + + AddVariable("Install Type", () => AgentInstallConfiguration.GetAgentInfo()?.ToString() ?? "Unknown"); } catch (Exception ex) {