-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Remove default logging scope from ASP.NET Core #44873
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
base: main
Are you sure you want to change the base?
Conversation
Did you mean |
@davidfowl I think this is change is good if we are not concering about the compat. If we proceed with such change would be good to file breaking change doc for that. |
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
what if we encourage people to phase out usage of logger scope and use Activity instead? My worry if we try to automatically migrate tags is that the scope lifetimes may not match up and you could have weird results. For example: // this might be ASP.Net code
void HandleRequest()
{
using (Activity a = source.StartActivity)
{
UserRequestHandler(requestData);
}
}
void UserRequestHandler(requestData)
{
foreach(var item in requestData.Batch)
{
// this scope doesn't have 1:1 relationship with Activity, the tags would overwrite each other
using(logger.CreateScope("Id", item.Id))
{
logger.Log("stuff");
}
// this log is outside the logger scope, but still inside the Activity scope where
// the tags have now been forwarded.
logger.Log("all done now");
}
} |
Relevant #31028 |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
@davidfowl What's happening with this? |
- We correlate logs with Activities and more information can be added to them (like the trace identifier) using activity listeners or custom middleware.
579ac6b
to
0bc04d3
Compare
Thanks for identifying a breaking change. , after you commit this PR please take the following actions, as part of the breaking changes announcement process: |
@noahfalk I updated this PR to just remove the scopes. I'm pretty convinced this scope useful by default and can be easily added back via middleware. The cost we're paying for the benefit people get by default is too high (many don't even know how to look at these logging scopes). I think now that the ability to associate logs with the activity exists and is on by default. I feel pretty confident breaking this. We will show people how to add a middleware back and adds this information via a logging scope or activity tags. |
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
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.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (2)
src/Hosting/Hosting/test/WebHostTests.cs:871
- The removal of the WebHost_CreatesDefaultRequestIdentifierFeature_IfNotPresent test case reduces the test coverage. Ensure that the new behavior is adequately tested.
[Fact]
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs:95
- Ensure that the removal of the Scope property and its associated logic is covered by tests to verify that the activity's scope is used correctly.
if (loggingEnabled)
I was looking at this and wondering why we still need it other than compatibility. I'm thinking we can lean into activity (as big as it is 😄) and use it's scope instead of having 2 by default. This reduces the number of async locals as well which is a plus. @noahfalk do you think it's reasonable to have a feature for logging adding tags to the logging activity scope as well?
cc @noahfalk @tarekgh @adityamandaleeka
These are the per request allocations (excluding execution context overhead) (10K requests):