From b7f4a1c73050237c7144423a2444991eae01caf3 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:32:23 -0600 Subject: [PATCH 1/5] fix: Path to agentinfo.json was built incorrectly, leading to file not found errors when running on Linux. #2156 --- .../NewRelic/Agent/Core/AgentInstallConfiguration.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs index 01b8b64766..7d14bfbe94 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs @@ -200,19 +200,21 @@ private static string GetNewRelicLogLevel() public static AgentInfo GetAgentInfo() { - var agentInfoPath = $@"{NewRelicHome}\agentinfo.json"; + var agentInfoPath = Path.Combine(NewRelicHome, "agentinfo.json"); + if (File.Exists(agentInfoPath)) { try { return JsonConvert.DeserializeObject(File.ReadAllText(agentInfoPath)); } - catch + catch (Exception e) { - // Fail silently + Log.Debug(e, $"Could not get agent info from {agentInfoPath}."); } } + Log.Debug($"Could not get agent info from {agentInfoPath}. File does not exist."); return null; } } From cee3be96f975a96b667ab1e521fad4d6def58154 Mon Sep 17 00:00:00 2001 From: Marty T <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:41:33 -0600 Subject: [PATCH 2/5] Update src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs --- src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs index 7d14bfbe94..a8d4e7faec 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs @@ -210,7 +210,7 @@ public static AgentInfo GetAgentInfo() } catch (Exception e) { - Log.Debug(e, $"Could not get agent info from {agentInfoPath}."); + Log.Debug(e, $"Could not deserialize agent info from {agentInfoPath}."); } } From e259af53c0b23045b3a26c1f9f3929e0fecbe75b Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:53:03 -0600 Subject: [PATCH 3/5] Add some defensive checking --- src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs index 7d14bfbe94..c7e725897e 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs @@ -200,6 +200,12 @@ private static string GetNewRelicLogLevel() public static AgentInfo GetAgentInfo() { + if (string.IsNullOrEmpty(NewRelicHome)) + { + Log.Debug($"Could not get agent info. NewRelicHome is null or empty."); + return null; + } + var agentInfoPath = Path.Combine(NewRelicHome, "agentinfo.json"); if (File.Exists(agentInfoPath)) From fa2f273a091527dfc4d7ac6c6f414f4850f77a24 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:29:23 -0600 Subject: [PATCH 4/5] PR comments --- src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs index cb02aa0cce..529d7132c9 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs @@ -217,6 +217,7 @@ public static AgentInfo GetAgentInfo() catch (Exception e) { Log.Debug(e, $"Could not deserialize agent info from {agentInfoPath}."); + return null; } } From a76c3dd9da7b32a58882422a6102bb06199500fd Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 20 Dec 2023 15:29:43 -0600 Subject: [PATCH 5/5] Better fix for PR comments --- src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs index 529d7132c9..fa8418e7ab 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentInstallConfiguration.cs @@ -217,11 +217,11 @@ public static AgentInfo GetAgentInfo() catch (Exception e) { Log.Debug(e, $"Could not deserialize agent info from {agentInfoPath}."); - return null; } } + else + Log.Debug($"Could not get agent info from {agentInfoPath}. File does not exist."); - Log.Debug($"Could not get agent info from {agentInfoPath}. File does not exist."); return null; } }