You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 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.
$"No password detected in the connection string. Attempt to retrieve "+
169
-
$"a managed identity access token using DefaultAzureCredential failed due to: \n{ex}\n"+
170
-
(firstAttemptAtDefaultAccessToken?
171
-
$"If authentication with DefaultAzureCrendential is not intended, this warning can be safely ignored.":
172
-
string.Empty));
167
+
stringmessagePrefix="{correlationId} No password detected in the connection string. Attempt to retrieve a managed identity access token using DefaultAzureCredential failed due to:\n{errorMessage}";
168
+
stringmessageSuffix=(firstAttemptAtDefaultAccessToken?$"If authentication with DefaultAzureCrendential is not intended, this warning can be safely ignored.":string.Empty);
$"Request executed successfully in {retryAttempt} attempt of"+
115
-
$"{_maxRetryCount+1} available attempts.");
109
+
QueryExecutorLogger.LogInformation("{correlationId} Request executed successfully in {retryAttempt} attempt of {maxRetries} available attempts.",correlationId,retryAttempt,maxRetries);
0 commit comments