-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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.
|
MihaZupan
left a comment
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:
ActivitySourceis given the chance to create theActivityfirst, 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
CarnaViire
left a comment
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 😆)
| } | ||
|
|
||
| [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,
DiagnosticsHandlerwill create a newActivityif either is true:Activitywas already set (Activity.Currentis not null)DiagnosticListenerrequested one (was enabled for the activity name)This PR preserves the same behaviour when no
ActivityListeneris present.The behaviour changes for
Activitycreation if anActivityListeneris present:ActivitySourceis given chance to create an activityActivity.Currentis set orDiagnosticListeneris enabled for the activity name- AnActivitywas already set (Activity.Currentwas not null)- NoDiagnosticListenerwas enabled for the activity name-ActivitySourcehad listeners present- Listeners decided not to sample the requestIn this case, noActivityis created (and so we also won't inject context headers).If a
DiagnosticListeneris 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 theSendAsynccall intoI also removed the internalSettingsandLoggingStringsclasses - 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 knownDiagnosticsHandlerissues.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