Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOTNET_EnableDiagnostics=0 disables profiling in .NET 8 #96227

Closed
nr-ahemsath opened this issue Dec 20, 2023 · 3 comments · Fixed by dotnet/docs#38931
Closed

DOTNET_EnableDiagnostics=0 disables profiling in .NET 8 #96227

nr-ahemsath opened this issue Dec 20, 2023 · 3 comments · Fixed by dotnet/docs#38931
Assignees
Labels
area-Diagnostics-coreclr documentation Documentation bug or enhancement, does not impact product or test code
Milestone

Comments

@nr-ahemsath
Copy link

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

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 20, 2023
@ghost
Copy link

ghost commented Dec 20, 2023

Tagging subscribers to this area: @tommcdon
See info in area-owners.md if you want to be subscribed.

Issue Details

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

Author: nr-ahemsath
Assignees: -
Labels:

area-Diagnostics-coreclr, untriaged

Milestone: -

@tommcdon
Copy link
Member

Hi @nr-ahemsath! I apologize for the oversight in our breaking change documentation. I agree our documentation should be clearer - DOTNET_EnableDiagnostics disables if 0 / enables if 1 all of diagnostics including the Diagnostic Port, Debugging, and Profiling. The current docs simply state setting it to 1 enables it. Setting DOTNET_EnableDiagnostics=0 overrides the sub-configuration variables, and the docs do not mention that behavior either.

As you have correctly pointed out, in .NET 8 we added new configuration knobs that will allow you to more granularly enable/disable diagnostics:

To emulate previous behavior, I suggest setting the following to ensure the behavior is as intended:

export DOTNET_EnableDiagnostics=1
export DOTNET_EnableDiagnostics_IPC=0
export DOTNET_EnableDiagnostics_Debugger=0
export DOTNET_EnableDiagnostics_Profiler=1

I'll mark this issue as a documentation bug. Hope this helps! Thanks for reporting the issue!

@tommcdon tommcdon added this to the Future milestone Dec 21, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Dec 21, 2023
@tommcdon tommcdon added the documentation Documentation bug or enhancement, does not impact product or test code label Dec 21, 2023
@tommcdon tommcdon self-assigned this Dec 21, 2023
@nr-ahemsath
Copy link
Author

@tommcdon Thanks for the quick response, I'll let our customer know what the workaround is.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Diagnostics-coreclr documentation Documentation bug or enhancement, does not impact product or test code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants