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

Add feature switch for diagnostics handler in System.Net.Http #38765

Merged
merged 5 commits into from
Jul 9, 2020

Conversation

marek-safar
Copy link
Contributor

@marek-safar marek-safar commented Jul 3, 2020

This allows easier exclusion on size sensitive workloads

@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented Jul 3, 2020

Tagging subscribers to this area: @dotnet/ncl
Notify danmosemsft if you want to be subscribed.

Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

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

LGTM, mandatory disclaimer: not an expert, get another approval as well 😄

@@ -14,6 +14,15 @@
<PropertyGroup Condition=" '$(TargetsBrowser)' == 'true'">
<DefineConstants>$(DefineConstants);TARGETS_BROWSER</DefineConstants>
</PropertyGroup>
<!-- ILLinker settings -->
Copy link
Member

Choose a reason for hiding this comment

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

Do we have same docs how this linker stuff works? Could you point me to it?
I'd like to understand these changes better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eerhardt wrote the build task but I'm not sure there is any doc. You can check the code at https://github.com/dotnet/runtime/blob/master/eng/illink.targets

Copy link
Member

Choose a reason for hiding this comment

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

A good starting overview is: https://github.com/dotnet/designs/blob/master/accepted/2020/linking-libraries.md

The feature switch design is good at explaining how certain code can be trimmed when a user doesn't want it: https://github.com/dotnet/designs/blob/master/accepted/2020/feature-switch.md.

@ManickaP
Copy link
Member

ManickaP commented Jul 7, 2020

Cc: @alnikola @MihaZupan this is touching diagnostics, that's your domain guys.

<linker>
<assembly fullname="System.Net.Http">
<type fullname="System.Net.Http.DiagnosticsHandler">
<method signature="System.Boolean IsEnabled()" body="stub" value="false" />
Copy link
Member

Choose a reason for hiding this comment

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

Why not make this into a full blown feature switch? There is already an AppContext setting.

Advantages:

  1. If someone wants to turn it off, they can by setting a single setting in their .csproj, just like any other feature switch.
  2. It can easily be used in other size-sensitive form factors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the substitution to full feature switch

<ILLinkDirectory>$(MSBuildThisFileDirectory)src\ILLink\</ILLinkDirectory>
</PropertyGroup>
<ItemGroup>
<ILLinkSubstitutionsXmls Include="$(ILLinkDirectory)ILLink.Substitutions.$(Platform).xml"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think $(Platform) works here. We only build per-platform binaries for System.Private.CoreLib. All other libraries are cross compiled by TFM and OS, but not by architecture.

If we use a full feature switch, this will go away as the Blazor SDK can just default the MSBuild setting to add --feature System.Net.Http.DiagnosticsHandler.IsSupported false when running the linker.

@marek-safar marek-safar changed the title Exclude diagnostics handler from browser version of System.Net.Http Add feature switch for diagnostics handler in System.Net.Http Jul 8, 2020
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.

:shipit:

@safern safern mentioned this pull request Jul 8, 2020
@marek-safar marek-safar merged commit 8753b34 into dotnet:master Jul 9, 2020
@marek-safar marek-safar deleted the http-wasm branch July 9, 2020 15:38
eerhardt added a commit to eerhardt/sdk that referenced this pull request Jul 14, 2020
…gation

These feature switches were added in the runtime:
* Debugger - dotnet/runtime#37288
* Http activity propagation - dotnet/runtime#38765

Fix dotnet#12217
eerhardt added a commit to dotnet/sdk that referenced this pull request Jul 15, 2020
…gation (#12457)

These feature switches were added in the runtime:
* Debugger - dotnet/runtime#37288
* Http activity propagation - dotnet/runtime#38765

Fix #12217
eerhardt added a commit to eerhardt/runtime that referenced this pull request Jul 20, 2020
Since the DiagnosticsHandler still gets instantiated in the HttpClientHandler, none of its overriden methods are getting trimmed. This leads to System.Diagnostics.DiagnosticListener still being preserved in a linked application.

This fix is split DiagnosticsHandler.IsEnabled() into two methods:

* IsGloballyEnabled() - checks the AppContext switch, and is replaced by the linker by a feature swtich.
* IsEnabled() - which checks IsGloballyEnabled() and if there is an Activity or listener available.

This allows all but the IsEnabled and IsGloballyEnabled methods to get trimmed on DiagnosticsHandler.

Contributes to dotnet#38765
eerhardt added a commit that referenced this pull request Jul 21, 2020
Since the DiagnosticsHandler still gets instantiated in the HttpClientHandler, none of its overriden methods are getting trimmed. This leads to System.Diagnostics.DiagnosticListener still being preserved in a linked application.

The fix is to split DiagnosticsHandler.IsEnabled() into two methods:

* IsGloballyEnabled() - checks the AppContext switch, and is replaced by the linker by a feature swtich.
* IsEnabled() - which checks IsGloballyEnabled() and if there is an Activity or listener available.

This allows all but the IsEnabled and IsGloballyEnabled methods to get trimmed on DiagnosticsHandler.

Contributes to #38765
Jacksondr5 pushed a commit to Jacksondr5/runtime that referenced this pull request Aug 10, 2020
Since the DiagnosticsHandler still gets instantiated in the HttpClientHandler, none of its overriden methods are getting trimmed. This leads to System.Diagnostics.DiagnosticListener still being preserved in a linked application.

The fix is to split DiagnosticsHandler.IsEnabled() into two methods:

* IsGloballyEnabled() - checks the AppContext switch, and is replaced by the linker by a feature swtich.
* IsEnabled() - which checks IsGloballyEnabled() and if there is an Activity or listener available.

This allows all but the IsEnabled and IsGloballyEnabled methods to get trimmed on DiagnosticsHandler.

Contributes to dotnet#38765
@karelz karelz added this to the 5.0.0 milestone Aug 18, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants