-
Notifications
You must be signed in to change notification settings - Fork 5k
Add ActivitySource support to DiagnosticsHandler #64753
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
Conversation
Tagging subscribers to this area: @dotnet/ncl Issue DetailsThis is an attempt to bring the logic from #54437 in main.Description from the original PR: Today,
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 @MihaZupan could you please give it a look if I'm not missing anything? I had to adapt the PR and I tried to not to do much unnecessary churn.
|
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.
The behaviour changes iff all of the following hold:
Looks like I didn't update the description on the PR as things changed 😄
From what I can tell, this PR is functionally equivalent to #54437 and the difference is this:
ActivitySource
is given the chance to create theActivity
first, but if it chooses not to, one will still be created manually.
I.e. ActivitySource
's sampling decision is ignored if there is already an Activity present / a diagnostic listener said otherwise. This is the same thing AspNetCore does on their side. Some more details here: #54437 (comment)
src/libraries/System.Net.Http/tests/FunctionalTests/DiagnosticsTests.cs
Outdated
Show resolved
Hide resolved
0a5eefb
to
4ed0d55
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.
LGTM (I'm no expert though 😆)
@@ -998,6 +962,112 @@ public async Task SendAsync_CustomSocketsHttpHandlerPropagator_PropagatorIsUsed( | |||
}); | |||
} | |||
|
|||
[ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] | |||
[InlineData(true, true, true)] // Activity was set and ActivitySource created an Activity |
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.
Would it be better to have a generated MemberData instead? 😅
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 tried to preserve some of the wisdom from the comments so it's not much shorter than the original, but it's moved in member data.
No failing tests, pipelines are timing out on Mac/iOS/..., other runs have similar problems ==> merging. |
This is an attempt to bring the logic from #54437 in main.
Description from the original PR:
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 for
Activity
creation if anActivityListener
is present:ActivitySource
is given chance to create an activityActivity.Current
is set orDiagnosticListener
is enabled for the activity name- AnActivity
was already set (Activity.Current
was not null)- NoDiagnosticListener
was enabled for the activity name-ActivitySource
had listeners present- Listeners decided not to sample the requestIn this case, noActivity
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 theSendAsync
call intoI also removed the internalSettings
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.
@MihaZupan could you please give it a look if I'm not missing anything? I had to adapt the PR and I tried to not to do much unnecessary churn.
Contributes to #63868
cc @denisivan0v @cijothomas