Skip to content

Commit 352befd

Browse files
authored
Improve long running operation debug log (#13612)
* listen to polling event and print req/res * try catch to be compatible with old gen modules * Update ChangeLog.md
1 parent 3512e9a commit 352befd

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Accounts/Accounts/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Improved debug log of long running operations in generated modules
2122

2223
## Version 2.2.2
2324
* Managed to parse ExpiresOn time from raw token if could not get from underlying library

src/Accounts/Accounts/CommonModule/AzModule.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ public async Task EventListener(string id, CancellationToken cancellationToken,
110110
case Events.ResponseCreated:
111111
await OnResponseCreated(id, cancellationToken, getEventData, signal, processRecordId);
112112
break;
113+
case Events.Polling:
114+
await OnPolling(id, cancellationToken, getEventData, signal, processRecordId);
115+
break;
113116
default:
114117
getEventData.Print(signal, cancellationToken, Events.Information, id);
115118
break;
@@ -142,6 +145,33 @@ await signal(Events.Debug, cancellationToken,
142145
}
143146
}
144147

148+
internal async Task OnPolling(string id, CancellationToken cancellationToken, GetEventData getEventData, SignalDelegate signal, string processRecordId)
149+
{
150+
var data = EventDataConverter.ConvertFrom(getEventData());
151+
// a polling event contains a response, and the response contains the request
152+
// so we can print them both in one event
153+
if (data?.RequestMessage is HttpRequestMessage request)
154+
{
155+
try {
156+
// Print formatted request message
157+
await signal(Events.Debug, cancellationToken,
158+
() => EventHelper.CreateLogEvent(GeneralUtilities.GetLog(request)));
159+
} catch {
160+
// request was disposed, ignore
161+
}
162+
}
163+
if (data?.ResponseMessage is HttpResponseMessage response)
164+
{
165+
try {
166+
// Print formatted response message
167+
await signal(Events.Debug, cancellationToken,
168+
() => EventHelper.CreateLogEvent(GeneralUtilities.GetLog(response)));
169+
} catch {
170+
// response was disposed, ignore
171+
}
172+
}
173+
}
174+
145175
internal async Task OnCmdletException(string id, CancellationToken cancellationToken, GetEventData getEventData, SignalDelegate signal, string processRecordId, Exception exception)
146176
{
147177
var data = EventDataConverter.ConvertFrom(getEventData());

0 commit comments

Comments
 (0)