Skip to content

Metrics switch support in the SDK #35418

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

Merged
merged 3 commits into from
Sep 15, 2023

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Sep 14, 2023

Within the Runtime, we've introduced a configuration switch called System.Diagnostics.Metrics.Meter.IsSupported to manage the activation and deactivation of metrics functionality. This adjustment has been made to facilitate compatibility with the msbuild property named MetricsSupport.

dotnet/runtime#89880
dotnet/runtime#92019

I have conducted comprehensive testing for the end-to-end scenario by configuring the MetricsSupport in a standalone application using the latest SDK and runtime. I've ensured that when MetricsSupport is absent or set to true in the csproj, the metrics functionality remains enabled. Conversely, when it's set to false, the metrics functionality is disabled. You can find further details and context regarding the need for this switch in .NET 8.0 in the pull request located here: dotnet/runtime#92019, where an explanatory template outlines the rationale behind its implementation.

@ghost ghost added Area-Infrastructure untriaged Request triage from a team member labels Sep 14, 2023
@tarekgh
Copy link
Member Author

tarekgh commented Sep 14, 2023

@eerhardt @dsplaisted could you please help reviewing this change?

@artl93 @marcpopMSFT @ericstj for the merger approval to this rc2 branch.

CC @noahfalk @grendello

@tarekgh tarekgh added this to the 8.0.1xx milestone Sep 14, 2023
@marcpopMSFT
Copy link
Member

marcpopMSFT commented Sep 14, 2023

We'll be snapping Monday for RC2 so merge before then for inclusion.

@ericstj
Copy link
Member

ericstj commented Sep 15, 2023

Approve this scenario. Thank you for testing end-to-end. Please consider @eerhardt's feedback and do any follow up e2e testing needed to confirm that change is needed. Maybe previously the linker wasn't replacing the body and runtime was just reading the appcontext swtich? Please double check the linker does the replacement.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Copy link
Member

@dsplaisted dsplaisted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

What happens if you do something like <MetricsSupport>FileNotFound</MetricsSupport>?
It looks like for other similar properties we don't do any validation that the value is valid, so it's probably fine as is.

…rary.cs

Co-authored-by: Daniel Plaisted <dsplaisted@gmail.com>
@tarekgh
Copy link
Member Author

tarekgh commented Sep 15, 2023

What happens if you do something like FileNotFound?
It looks like for other similar properties we don't do any validation that the value is valid, so it's probably fine as is.

In the code we do the following to read the switch

            AppContext.TryGetSwitch("System.Diagnostics.Metrics.Meter.IsSupported", out bool isSupported) ? isSupported : true;

So, if the value is defined with something that is not true or false, we will still have the switch value as true which is the correct behavior we need.

Update
I found the AOT toolchain producing errors if assigning wrong value to the switch property. will get something like:

EXEC : error : Unexpected feature switch pair 'System.Diagnostics.Metrics.Meter.IsSupported=invalidValue' [C:\Temp\TestSdkMetricSwitch\TestSdkMetricSwitch.csproj]
  System.CommandLine.CommandLineException: Unexpected feature switch pair 'System.Diagnostics.Metrics.Meter.IsSupported=invalidValue'
     at ILCompiler.Program.Run() + 0x2afb
     at ILCompiler.ILCompilerRootCommand.<>c__DisplayClass221_0.<.ctor>b__0(ParseResult result) + 0x31d
C:\Users\tarekms\.nuget\packages\microsoft.dotnet.ilcompiler\8.0.0-preview.7.23375.6\build\Microsoft.NETCore.Native.targets(300,5): error MSB3073: The command ""C:\Users\tarekms\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\8.0.0-preview.7.23375.6\tools\\ilc" @"obj\release\net8.0\win-x64\nativ
e\TestSdkMetricSwitch.ilc.rsp"" exited with code 1. [C:\Temp\TestSdkMetricSwitch\TestSdkMetricSwitch.csproj]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-runtime untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants