diff --git a/src/Agent/NewRelic/Agent/Core/Config/ConfigurationTracker.cs b/src/Agent/NewRelic/Agent/Core/Config/ConfigurationTracker.cs index d8bac03301..f9cfb093fa 100644 --- a/src/Agent/NewRelic/Agent/Core/Config/ConfigurationTracker.cs +++ b/src/Agent/NewRelic/Agent/Core/Config/ConfigurationTracker.cs @@ -21,8 +21,11 @@ public class ConfigurationTracker : IDisposable private DateTime _lastWriteTime; - public ConfigurationTracker(IConfigurationService configurationService) + private readonly INativeMethods _nativeMethods; + + public ConfigurationTracker(IConfigurationService configurationService, INativeMethods nativeMethods) { + _nativeMethods = nativeMethods; var fileName = configurationService.Configuration.NewRelicConfigFilePath; if (fileName == null) return; @@ -39,6 +42,7 @@ public ConfigurationTracker(IConfigurationService configurationService) Log.Debug("newrelic.config file changed, reloading."); ConfigurationLoader.Initialize(fileName); _lastWriteTime = lastWriteTime; + _nativeMethods.ReloadConfiguration(); } }, TimeSpan.FromMinutes(1)); } diff --git a/src/Agent/NewRelic/Agent/Core/INativeMethods.cs b/src/Agent/NewRelic/Agent/Core/INativeMethods.cs index 24db94ceab..f9c59a9897 100644 --- a/src/Agent/NewRelic/Agent/Core/INativeMethods.cs +++ b/src/Agent/NewRelic/Agent/Core/INativeMethods.cs @@ -14,6 +14,7 @@ public interface INativeMethods void ShutdownNativeThreadProfiler(); int InstrumentationRefresh(); + int ReloadConfiguration(); int AddCustomInstrumentation(string fileName, string xml); int ApplyCustomInstrumentation(); } diff --git a/src/Agent/NewRelic/Agent/Core/NativeMethods.cs b/src/Agent/NewRelic/Agent/Core/NativeMethods.cs index b82c7690ba..c859e5aeba 100644 --- a/src/Agent/NewRelic/Agent/Core/NativeMethods.cs +++ b/src/Agent/NewRelic/Agent/Core/NativeMethods.cs @@ -15,6 +15,9 @@ public class LinuxNativeMethods : INativeMethods [DllImport(DllName, EntryPoint = "InstrumentationRefresh", CallingConvention = CallingConvention.Cdecl)] private static extern int ExternInstrumentationRefresh(); + [DllImport(DllName, EntryPoint = "ReloadConfiguration", CallingConvention = CallingConvention.Cdecl)] + private static extern int ExternReloadConfiguration(); + [DllImport(DllName, EntryPoint = "AddCustomInstrumentation", CallingConvention = CallingConvention.Cdecl)] private static extern int ExternAddCustomInstrumentation(string fileName, string xml); @@ -34,6 +37,19 @@ public int InstrumentationRefresh() } } + public int ReloadConfiguration() + { + try + { + return ExternReloadConfiguration(); + } + catch (Exception ex) + { + Log.Error(ex, "LinuxNativeMethods.ReloadConfiguration() exception"); + return -1; + } + } + public int AddCustomInstrumentation(string fileName, string xml) { return ExternAddCustomInstrumentation(fileName, xml); @@ -84,6 +100,9 @@ public class WindowsNativeMethods : INativeMethods [DllImport(DllName, EntryPoint = "InstrumentationRefresh", CallingConvention = CallingConvention.Cdecl)] private static extern int ExternInstrumentationRefresh(); + [DllImport(DllName, EntryPoint = "ReloadConfiguration", CallingConvention = CallingConvention.Cdecl)] + private static extern int ExternReloadConfiguration(); + [DllImport(DllName, EntryPoint = "AddCustomInstrumentation", CallingConvention = CallingConvention.Cdecl)] private static extern int ExternAddCustomInstrumentation(string fileName, string xml); @@ -103,6 +122,19 @@ public int InstrumentationRefresh() } } + public int ReloadConfiguration() + { + try + { + return ExternReloadConfiguration(); + } + catch (Exception ex) + { + Log.Error(ex, "WindowsNativeMethods.ReloadConfiguration() exception"); + return -1; + } + } + public int AddCustomInstrumentation(string fileName, string xml) { return ExternAddCustomInstrumentation(fileName, xml); diff --git a/src/Agent/NewRelic/Profiler/Profiler/CorProfilerCallbackImpl.h b/src/Agent/NewRelic/Profiler/Profiler/CorProfilerCallbackImpl.h index febaa50e76..622cba04d4 100644 --- a/src/Agent/NewRelic/Profiler/Profiler/CorProfilerCallbackImpl.h +++ b/src/Agent/NewRelic/Profiler/Profiler/CorProfilerCallbackImpl.h @@ -648,6 +648,15 @@ namespace NewRelic { namespace Profiler { return S_OK; } + HRESULT ReloadConfiguration() + { + LogTrace(L"Enter: ", __func__); + + auto newConfiguration = InitializeConfigAndSetLogLevel(); + + return S_OK; + } + std::shared_ptr> GetMethodDefsForAssembly( ModuleID moduleId, xstring_t assemblyName, @@ -1314,7 +1323,8 @@ namespace NewRelic { namespace Profiler { } }; - // called by managed code to get function information from function IDs + // Called by managed code to get the profiler to update the which methods + // are instrumented at runtime. extern "C" __declspec(dllexport) HRESULT __cdecl InstrumentationRefresh() { LogInfo("Refreshing instrumentation"); @@ -1326,6 +1336,19 @@ namespace NewRelic { namespace Profiler { return profiler->InstrumentationRefresh(); } + // Called by managed code to get the profiler to reload configuration settings + // from the newrelic.config files. + extern "C" __declspec(dllexport) HRESULT __cdecl ReloadConfiguration() + { + LogInfo(L"Reloading newrelic.config files."); + auto profiler = CorProfilerCallbackImpl::GetSingletonish(); + if (profiler == nullptr) { + LogError(L"Unable to reload newrelic.config files because the profiler reference is invalid."); + return E_FAIL; + } + return profiler->ReloadConfiguration(); + } + extern "C" __declspec(dllexport) HRESULT __cdecl AddCustomInstrumentation(const char* fileName, const char* xml) { LogTrace("Adding custom instrumentation");