-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add test for the order of activity and metrics with HTTP requests #56592
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
cc @noahfalk @tarekgh @antonfirsov A test that verifies an activity is active when a metric is recorded. This kind of test should be applied to HttpClient (it currently doesn't do the right thing) and anywhere else in the future that combines a duration histogram and 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.
LGTM!
var hostingEventSource = new HostingEventSource(Guid.NewGuid().ToString()); | ||
using var activityListener = new ActivityListener | ||
{ | ||
ShouldListenTo = activitySource => activitySource.Name == "Microsoft.AspNetCore", |
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.
You should create an activity source, inject it, and use reference equal so the test isn't affected by other tests.
See prior examples:
ShouldListenTo = activitySource => ReferenceEquals(activitySource, testSource), |
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 don't think it matters for this test because it doesn't actually listen for activities and then use them. We're only listening so an activity is created.
But, for consistency and to reduce confusion, I'll update the test.
bb25c67
to
79ec511
Compare
Exemplars require metrics and activities are completed in the correct order. ASP.NET Core fortunately already does the right thing.
Add comments and a unit test to assert the correct behavior.