Skip to content

Improve long running operation debug log #13612

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

Merged
merged 3 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Improved debug log of long running operations in generated modules

## Version 2.2.1
* Fixed the issue that incorrectly use Task.Result causes unclear error message if browser is not avaialable for Interactive auth
Expand Down
30 changes: 30 additions & 0 deletions src/Accounts/Accounts/CommonModule/AzModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public async Task EventListener(string id, CancellationToken cancellationToken,
case Events.ResponseCreated:
await OnResponseCreated(id, cancellationToken, getEventData, signal, processRecordId);
break;
case Events.Polling:
await OnPolling(id, cancellationToken, getEventData, signal, processRecordId);
break;
default:
getEventData.Print(signal, cancellationToken, Events.Information, id);
break;
Expand Down Expand Up @@ -142,6 +145,33 @@ await signal(Events.Debug, cancellationToken,
}
}

internal async Task OnPolling(string id, CancellationToken cancellationToken, GetEventData getEventData, SignalDelegate signal, string processRecordId)
{
var data = EventDataConverter.ConvertFrom(getEventData());
// a polling event contains a response, and the response contains the request
// so we can print them both in one event
if (data?.RequestMessage is HttpRequestMessage request)
{
try {
// Print formatted request message
await signal(Events.Debug, cancellationToken,
() => EventHelper.CreateLogEvent(GeneralUtilities.GetLog(request)));
} catch {
// request was disposed, ignore
}
}
if (data?.ResponseMessage is HttpResponseMessage response)
{
try {
// Print formatted response message
await signal(Events.Debug, cancellationToken,
() => EventHelper.CreateLogEvent(GeneralUtilities.GetLog(response)));
} catch {
// response was disposed, ignore
}
}
}

internal async Task OnCmdletException(string id, CancellationToken cancellationToken, GetEventData getEventData, SignalDelegate signal, string processRecordId, Exception exception)
{
var data = EventDataConverter.ConvertFrom(getEventData());
Expand Down