Structured logging for the Core project#1665
Merged
seantleonard merged 9 commits intomainfrom Sep 7, 2023
Merged
Conversation
aaronpowell
approved these changes
Aug 29, 2023
Contributor
aaronpowell
left a comment
There was a problem hiding this comment.
Minor nit's in there.
My only question, would it be better to put the correlationId with some kind of delimiter around it (like [] or a : suffix) so that it'd be easier to write a regex to find?
…ultiple calls to getCorrelationId extension method. Updated instance of inconsistent correlationId variable used in message contents and removed redundant inclusion of exception message in log message when exception is already provided as argument.
Aniruddh25
reviewed
Sep 6, 2023
Aniruddh25
reviewed
Sep 6, 2023
Aniruddh25
reviewed
Sep 6, 2023
Aniruddh25
approved these changes
Sep 6, 2023
…lqueryexecutor. Because this PR reduces the number of redundant logging events in places (2 events are now 1 event) these tests broke. This changeset does not address the validity of checking number of logger executions as a means to validate functionality.
rohkhann
pushed a commit
that referenced
this pull request
Sep 11, 2023
## Why make this change? - Adds structured logging to the Core project per #1517 ## What is this change? - In instances of ilogger usage, removes interpolated strings and uses structured logging paradigm: - in the `message` parameter, names in curly brackets are names that can be filtered in a log view such as app insights/log analytics. The parameters after message are the variables which supply the values for the names in curly brackets. ```csharp _logger.LogDebug( message: "{correlationId} Request authentication state: {requestAuthStatus}.", HttpContextExtensions.GetLoggerCorrelationId(httpContext), requestAuthStatus); ``` - Updated the CorrelationId creation helpers to no longer include extra formatting such as a space and colon. Now correlationID is just that, the id with no special formatting so that searching for an id in app insights is straightforward. - I did not add a colon manually to every location correlationId shows up in order to avoid cascading changes. - example log event before: `dbug: Azure.DataApiBuilder.Core.AuthenticationHelpers.ClientRoleHeaderAuthenticationMiddleware[0] 233f76e8-7955-4fce-85b3-b47c9ca2cdfa: The request will be executed in the context of the role: Authenticated` - example log event now: `dbug: Azure.DataApiBuilder.Core.AuthenticationHelpers.ClientRoleHeaderAuthenticationMiddleware[0] 233f76e8-7955-4fce-85b3-b47c9ca2cdfa The request will be executed in the context of the role: Authenticated` ## testing - Updates two tests that were dependent on the number of log events during query execution. Because this PR removes redundant log events (some cases where there were 2 events, now there is one event), the counts were wrong. I added more comments describing the tests and what they validate as well as explain the "Magic numbers" that were previously being used. Testing is manual via analyzing the console, no logic changes were made to the engine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why make this change?
What is this change?
messageparameter, names in curly brackets are names that can be filtered in a log view such as app insights/log analytics. The parameters after message are the variables which supply the values for the names in curly brackets.dbug: Azure.DataApiBuilder.Core.AuthenticationHelpers.ClientRoleHeaderAuthenticationMiddleware[0] 233f76e8-7955-4fce-85b3-b47c9ca2cdfa: The request will be executed in the context of the role: Authenticateddbug: Azure.DataApiBuilder.Core.AuthenticationHelpers.ClientRoleHeaderAuthenticationMiddleware[0] 233f76e8-7955-4fce-85b3-b47c9ca2cdfa The request will be executed in the context of the role: Authenticatedtesting
Testing is manual via analyzing the console, no logic changes were made to the engine.