Trim more Http DiagnosticsHandler code (#39525)
authorEric Erhardt <eric.erhardt@microsoft.com>
Tue, 21 Jul 2020 13:59:52 +0000 (08:59 -0500)
committerGitHub <noreply@github.com>
Tue, 21 Jul 2020 13:59:52 +0000 (08:59 -0500)
commit632cdcab09fda363e460296a77be0be32096f512
tree4958f0f8d99e9a2e1d458206e172cbbd64299a2e
parentd129af65b2570d519b12009c54b12255d9fe870d
Trim more Http DiagnosticsHandler code (#39525)

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
docs/workflow/trimming/feature-switches.md
src/libraries/System.Net.Http/src/ILLink/ILLink.Substitutions.xml
src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs
src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs