DOTNET_EnableDiagnostics=0 disables profiling in .NET 8 #96227
Description
Description
It appears that setting DOTNET_EnableDiagnostics=0
(or COMPlus_EnableDiagnostics=0
) disables profiling in .NET 8. This is a behavior change from .NET 7. I believe what causes this are the changes in this PR: #90159
I'm an engineer on New Relic's .NET agent team and this issue was brought to our attention by a customer who observed that our agent (which is a profiler) stopped working for them in .NET 8 when they had COMPlus_EnableDiagnostics
set to 0.
Reproduction Steps
See the attached repro: EnableDiagnosticsDemo2.zip
This Docker project adds the New Relic .NET agent to a sample webapi project and configures our profiling environment variables. The entrypoint is a script that runs the app and then checks to see if any New Relic log files have been created. If log files are created, the profiler is working as expected. If no log files are created, profiling is broken. A line is printed with the results. By running the repro with and without DOTNET_EnableDiagnostics
set to 0, you can see the behavior difference:
PS C:\workspace\scratch\EnableDiagnosticsDemo2> docker build . -t enable_diagnostics_demo
(build output)
PS C:\workspace\scratch\EnableDiagnosticsDemo2> docker run enable_diagnostics_demo
Found 1 New Relic logs, profiling is working.
PS C:\workspace\scratch\EnableDiagnosticsDemo2> docker run -e DOTNET_EnableDiagnostics=0 enable_diagnostics_demo
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://[::]:8080
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app
No New Relic logs found; profiling is disabled.
Expected behavior
Similar behavior to .NET 7 where setting DOTNET_EnableDiagnostics=0
doesn't disable profiling.
I checked to see if this behavior change was announced here: https://learn.microsoft.com/en-us/dotnet/core/compatibility/8.0
but I didn't see anything at first glance. My understanding of the PR I linked in the description is to give customers finer-grained controls over what aspects of .NET runtime diagnostics to enable or disable, but it looks like it also makes it so the generic DOTNET_EnableDiagnostics
disables/enables all three (profiling, debugging, and IPC), which it previously did not do.
Actual behavior
Setting DOTNET_EnableDiagnostics=0
disables profiling in .NET 8.
Regression?
This is a behavior change from .NET 7 to .NET 8.
Known Workarounds
No response
Configuration
See the Dockerfile in the repro project. I have reproduced this issue on Windows 11 (x64) as well as in the Debian docker container.
Other information
No response
Activity