New Relic for iOS or Android

New Relic Insights App for iOS

#1

# New Relic Stops working after System update

Very often New Relic is working fine, you do some Windows system patching and then New Relic no longer works. A little debugging time later, has pointed out that, the recent Microsoft update has wiped the environmental variables required for the agent to run.

## The Issue

With nearly all Microsoft patches, they have the power to wipe the registry and environmental variables. As System Admins, we want this to happen, we want the latest and greatest patches running on our systems. This provides us with the best protection against threats and bugs. However can sometimes have a negative affect on how New Relic has been installed as it will remove the required environmental variables for our .Net Agent. (Can happen to both Core and Framework)

Presently the options to fix this are limited to

1. Rerunning the New Relic installer (this can cause issues)
2. Manually re-entering the environmental keys
3. Following the Powershell in this document for resolving SCOM conflicts

Important Note: The .NET Agent is a passive .dll that loads at runtime when the .NET CLR spins up an application. As such it is not able to make any system level changes. Only the installer can do this. Any post-installation changes that need to be made must be done outside the agent configuration.

## The Solution

We can use some old technology to solve this for us, the humble batch file! This little guy is small but mighty. He has the power to summon these lost variables and also to reset IIS, all with one click. Something that neither option above is able to do completely unsupervised.

## Next Steps

Below is a batch file that can be used to do all of this. a quick summary of the code is as follows

1. Elevates the current console session to Admin Mode. (We need this for the IISRESET)

2. SETs the required Environment Variables system wide.

3. Runs IISRESET.

4. This can then be included as a startup script that is set to run each time your host restarts.

@echo off
(
::Checks current Admin rights and creates VBS Script to elevate to admin
>nul fsutil dirty query %SYSTEMDRIVE% 2>&1 || (
:: Create VBS script
echo Set UAC = CreateObject^("Shell.Application"^)>"%TEMP%\elevate.vbs"
echo UAC.ShellExecute "%~f0", "%TEMP%\elevate.vbs", "", "runas", 1 >>"%TEMP%\elevate.vbs"
if exist "%TEMP%\elevate.vbs" start /b /wait >nul cscript /nologo "%TEMP%\elevate.vbs" 2>&1

:: Delete elevation script if exist
if exist "%TEMP%\elevate.vbs" >nul del /f "%TEMP%\elevate.vbs" 2>&1

exit /b
)
)

TITLE _Mode Enabled

:: Assign .NET Framework Variables
SETX COR_ENABLE_PROFILING 1
SETX COR_PROFILER {71DA0A04-7777-4EC6-9643-7D28B46A8A41}
SETX NEWRELIC_INSTALL_PATH path\to\agent\directory

:: Assign .NET Core Variables
SETX CORECLR_ENABLE_PROFILING 1
SETX CORECLR_PROFILER {36032161-FFC0-4B61-B559-F6C5D41BAE5A}
SETX CORECLR_NEWRELIC_HOME path\to\agent\directory
SETX NEWRELIC_INSTALL_PATH path\to\agent\directory

IISRESET

PAUSE


A Couple of Caveats

1. Fill in absolute paths for your selected variables
2. Modify this as appropriate for .Net Framework vs .Net Core applications. If you have both this will also work, just leave them both in.
3. Since this will require elevating to admin privileges, please ensure that permission to do this has been obtained.