-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Use Microsoft.Extensions.Diagnostics #48403
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
A smooth migration (as expected) Feedback:
|
|
@wtgodbe This PR adds references to |
Excellent 👍
serviceProvider.GetRequiredService<IMeterFactory>() is insufficient?
Tarek originally had one but I believed it would have no use and suggested we get rid of it. So egg on my face :) Do you have a good example so I can better understand where you found it useful? |
That works if you have a DI container setup in your test. Without a DI container, you need to create your own implementation.
He might have seen it in the ASP.NET Core prototype.
I've worked around these two issues (an IMeterFactory implementation for tests and a way to get notifications of new measurements here) |
@@ -40,6 +40,7 @@ and are generated based on the last package release. | |||
<LatestPackageReference Include="Microsoft.Extensions.DependencyInjection" /> | |||
<LatestPackageReference Include="Microsoft.Extensions.DependencyModel" /> | |||
<LatestPackageReference Include="Microsoft.Extensions.DiagnosticAdapter" /> | |||
<LatestPackageReference Include="Microsoft.Extensions.Diagnostics" /> |
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.
Don't you need the Microsoft.Extensions.Diagnostics.Abstraction too? or will the dependency be automatically picked?
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.
CC @joperezr
You can see what we are doing in our tests. create a temporary ServiceCollection, call AddMetrics then request IMeterFactory from the service. It doesn't matter if you are running with a container or not. |
var response = await server.CreateClient().GetAsync("/path");
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
... In this example isn't awaiting the GetAsync() call sufficient to know that the work has been done and the measurement is recorded? Is there some asynchronous work happening somewhere even after the await completes? |
In this particular test, there is a race condition. The server can return the failing response to the client before the metric is recorded. 99% of the time it is fine, but 1% of the time the client can report it's finished before the request is finished on the server and the counter is recorded. |
This change was merged into #48407. Closing. |
Created issue: dotnet/runtime#86783 |
I think this is a little gross. However, it's not a big deal to create a simple |
AH interesting. In general I wouldn't want to encourage users to write tests with timed waits for a callback if they had an option to avoid it, but I'm fine for us to add a callback API and use docs/comments to provide that guidance. |
Hi @noahfalk. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Fixes #47618
@davidfowl @tarekgh @noahfalk