-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 ActivitySource support to DiagnosticsHandler #54437
Conversation
Tagging subscribers to this area: @dotnet/ncl Issue DetailsToday,
This PR preserves the same behaviour when no The behaviour changes iff all of the following hold:
In this case, no The PR moves the decision of whether to log events/create an activity out of the // The interesting part of the PR - this method decides on the actual behaviour
static bool ShouldLogDiagnostics(HttpRequestMessage request, out Activity? activity) I also removed the internal Note that the PR is only a slight refactor + adding Opening as a draft so the diagnostics team can confirm whether the above is the desired behaviour with
|
src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
@dotnet/ncl please take a look at this PR - the behaviour should be unchanged, but there is a considerable refactor to the underlying class. |
private static readonly DiagnosticListener s_diagnosticListener = new("HttpHandlerDiagnosticListener"); | ||
private static readonly ActivitySource s_activitySource = new(Namespace); | ||
|
||
public static readonly bool IsGloballyEnabled = GetEnableActivityPropagationValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be static property or it will regress feature switch setting and increases size duo to static ctor dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to
public static bool IsGloballyEnabled { get; } = GetEnableActivityPropagationValue();
@marek-safar Is this the pattern you had in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better but it will still all the unnecessary dependencies like DiagnosticListener, ActivitySource and others where were not there before. You can check the size regression to see how much it adds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a linker switch for DiagnosticsHandler
?
Or was it capable of removing the code before (it would have had to remove Activity
and DiagnosticListener
)?
You can check the size regression to see how much it adds
Do you mean just the size of the System.Net.Http
assembly? Or some other way of looking at trimmed regressions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a linker switch for DiagnosticsHandler?
Yes, see HttpActivityPropagationSupport at https://github.com/dotnet/runtime/blob/main/docs/workflow/trimming/feature-switches.md
Do you mean just the size of the System.Net.Http assembly? Or some other way of looking at trimmed regressions?
System.Net.Http will probably show the biggest increase if there is some. You can publish trimmed release build with HttpActivityPropagationSupport property set to false to compare.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the ILLink.Substitutions.xml
to get_IsGloballyEnabled()
.
Looking at .\build.cmd -projects .\src\libraries\System.Net.Http\src\System.Net.Http.csproj -os Browser -c Release
the size of System.Net.Http.dll
in browser-wasm\lib\net6.0
dropped from 247.296 to 246.272 bytes after this PR.
I don't know how to test the runtime change with trimming and the feature switch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a few questions around what our desired behavior should be inline. Other than that all looked good : )
src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look reasonable to me. I'd suggest changing the "when" usage (as I commented above), but it's not a huge deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This reverts commit c88da29.
This reverts commit c88da29.
dotnet#54437 but without the ActivitySource support
Today,
DiagnosticsHandler
will create a newActivity
if either is true:Activity
was already set (Activity.Current
is not null)DiagnosticListener
requested one (was enabled for the activity name)This PR preserves the same behaviour when no
ActivityListener
is present.The behaviour changes iff all of the following hold:
Activity
was already set (Activity.Current
was not null)DiagnosticListener
was enabled for the activity nameActivitySource
had listeners presentIn this case, no
Activity
is created (and so we also won't inject context headers).If a
DiagnosticListener
is enabled for the activity, one is always created (regardless of sampling decisions).The PR moves the decision of whether to log events/create an activity out of the
SendAsync
call intoI also removed the internal
Settings
andLoggingStrings
classes - am I missing something and they actually provide value?Note that the PR is only a slight refactor + adding
ActivitySource
. It does not address other knownDiagnosticsHandler
issues.This is runtime's equivalent of what dotnet/aspnetcore#30089 was for AspNet.
Opening as a draft so the diagnostics team can confirm whether the above is the desired behaviour with
ActivitySource
.cc: @shirhatti @tarekgh @noahfalk