|
17 | 17 | using Microsoft.Azure.Commands.Profile.CommonModule;
|
18 | 18 | using Microsoft.Rest.Azure;
|
19 | 19 | using Microsoft.Rest.Serialization;
|
| 20 | +using Microsoft.WindowsAzure.Commands.Common; |
20 | 21 | using Microsoft.WindowsAzure.Commands.Utilities.Common;
|
21 | 22 | using Newtonsoft.Json;
|
22 | 23 | using System;
|
@@ -121,31 +122,52 @@ public async Task EventListener(string id, CancellationToken cancellationToken,
|
121 | 122 | switch (id)
|
122 | 123 | {
|
123 | 124 | case Events.CmdletBeginProcessing:
|
124 |
| - await OnCmdletBeginProcessing(id, cancellationToken, getEventData, signal, processRecordId); |
| 125 | + await OnCmdletBeginProcessing(id, cancellationToken, getEventData, signal, correlationId); |
125 | 126 | break;
|
126 | 127 | case Events.BeforeCall:
|
127 |
| - await OnBeforeCall(id, cancellationToken, getEventData, signal, processRecordId); |
| 128 | + await OnBeforeCall(id, cancellationToken, getEventData, signal, correlationId); |
128 | 129 | break;
|
129 | 130 | case Events.CmdletProcessRecordAsyncStart:
|
130 | 131 | await OnProcessRecordAsyncStart(id, cancellationToken, getEventData, signal, processRecordId, invocationInfo, parameterSetName, correlationId);
|
131 | 132 | break;
|
132 | 133 | case Events.CmdletProcessRecordAsyncEnd:
|
133 |
| - await OnProcessRecordAsyncEnd(id, cancellationToken, getEventData, signal, processRecordId); |
| 134 | + await OnProcessRecordAsyncEnd(id, cancellationToken, getEventData, signal, correlationId); |
134 | 135 | break;
|
135 | 136 | case Events.CmdletException:
|
136 |
| - await OnCmdletException(id, cancellationToken, getEventData, signal, processRecordId, exception); |
| 137 | + await OnCmdletException(id, cancellationToken, getEventData, signal, correlationId, exception); |
137 | 138 | break;
|
138 | 139 | case Events.ResponseCreated:
|
139 |
| - await OnResponseCreated(id, cancellationToken, getEventData, signal, processRecordId); |
| 140 | + await OnResponseCreated(id, cancellationToken, getEventData, signal, correlationId); |
140 | 141 | break;
|
141 | 142 | case Events.Polling:
|
142 | 143 | await OnPolling(id, cancellationToken, getEventData, signal, processRecordId);
|
143 | 144 | break;
|
144 | 145 | case Events.Finally:
|
145 |
| - await OnFinally(id, cancellationToken, getEventData, signal, processRecordId); |
| 146 | + await OnFinally(id, cancellationToken, getEventData, signal, correlationId); |
146 | 147 | break;
|
147 | 148 | case Events.CmdletEndProcessing:
|
148 |
| - await OnCmdletEndProcessing(id, cancellationToken, getEventData, signal, processRecordId); |
| 149 | + await OnCmdletEndProcessing(id, cancellationToken, getEventData, signal, correlationId); |
| 150 | + break; |
| 151 | + default: |
| 152 | + break; |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + /// <summary> |
| 157 | + /// The cmdlet will call this for every event during the pipeline. |
| 158 | + /// </summary> |
| 159 | + /// <param name="id">a <c>string</c> containing the name of the event being raised (well-known events are in <see cref="Microsoft.Azure.Commands.Common.Events"/></param> |
| 160 | + /// <param name="invocationInfo">The <see cref="System.Management.Automation.InvocationInfo" /> from the cmdlet</param> |
| 161 | + /// <param name="parameterSetName">The <see cref="string" /> containing the name of the parameter set for this invocation (if available></param> |
| 162 | + public void Telemetry(string id, InvocationInfo invocationInfo, string parameterSetName, PSCmdlet pscmdlet) |
| 163 | + { |
| 164 | + switch (id) |
| 165 | + { |
| 166 | + case Telemetries.Create: |
| 167 | + OnTelemetryCreated(invocationInfo, parameterSetName, pscmdlet); |
| 168 | + break; |
| 169 | + case Telemetries.Send: |
| 170 | + OnTelemetrySent(pscmdlet); |
149 | 171 | break;
|
150 | 172 | default:
|
151 | 173 | break;
|
@@ -222,18 +244,45 @@ await signal(Events.Debug, cancellationToken,
|
222 | 244 | internal async Task OnProcessRecordAsyncStart(string id, CancellationToken cancellationToken, GetEventData getEventData, SignalDelegate signal, string processRecordId, InvocationInfo invocationInfo, string parameterSetName, string correlationId)
|
223 | 245 | {
|
224 | 246 | //AzVersion is null indicates no SDK based cmdlet is invoked. Below properties needs to be filled.
|
225 |
| - if(_runtime != null && AzurePSCmdlet.AzVersion == null) |
| 247 | + if (_runtime != null && AzurePSCmdlet.AzVersion == null) |
226 | 248 | {
|
227 | 249 | AzurePSCmdlet.PSHostName = _runtime.Host?.Name;
|
228 | 250 | AzurePSCmdlet.PSHostVersion = _runtime.Host?.Version?.ToString();
|
229 | 251 | }
|
230 |
| - var qos = _telemetry.CreateQosEvent(invocationInfo, parameterSetName, correlationId, processRecordId); |
| 252 | + var qos = _telemetry.CreateQosEvent(invocationInfo, parameterSetName, correlationId, correlationId); |
231 | 253 | qos.PreviousEndTime = _previousEndTime;
|
232 | 254 | await signal(Events.Debug, cancellationToken,
|
233 | 255 | () => EventHelper.CreateLogEvent($"[{id}]: Created new QosEvent for command '{qos?.CommandName}'"));
|
234 | 256 | }
|
235 | 257 |
|
236 |
| - internal async Task OnProcessRecordAsyncEnd(string id, CancellationToken cancellationToken, GetEventData getEventData, SignalDelegate signal, string processRecordId) |
| 258 | + internal void OnTelemetryCreated(InvocationInfo invocationInfo, string parameterSetName, PSCmdlet pscmdlet) |
| 259 | + { |
| 260 | + //AzVersion is null indicates no SDK based cmdlet is invoked. Below properties needs to be filled. |
| 261 | + if (_runtime != null && AzurePSCmdlet.AzVersion == null) |
| 262 | + { |
| 263 | + AzurePSCmdlet.PSHostName = _runtime.Host?.Name; |
| 264 | + AzurePSCmdlet.PSHostVersion = _runtime.Host?.Version?.ToString(); |
| 265 | + } |
| 266 | + var qos = _telemetry.CreateQosEvent(invocationInfo, parameterSetName, MetricHelper.TelemetryId, MetricHelper.TelemetryId); |
| 267 | + qos.Parameters = string.Join(" ", |
| 268 | + invocationInfo.BoundParameters.Keys.Select( |
| 269 | + s => string.Format(System.Globalization.CultureInfo.InvariantCulture, "-{0} ***", s))); |
| 270 | + qos.PreviousEndTime = _previousEndTime; |
| 271 | + } |
| 272 | + |
| 273 | + internal void OnTelemetrySent(PSCmdlet pscmdlet) |
| 274 | + { |
| 275 | + AzurePSQoSEvent qos; |
| 276 | + if (_telemetry.TryGetValue(MetricHelper.TelemetryId, out qos)) |
| 277 | + { |
| 278 | + qos.IsSuccess = (qos.Exception == null); |
| 279 | + _telemetry.LogEvent(MetricHelper.TelemetryId); |
| 280 | + _previousEndTime = DateTimeOffset.Now; |
| 281 | + pscmdlet.WriteDebug(qos.ToString()); |
| 282 | + } |
| 283 | + } |
| 284 | + |
| 285 | + internal async Task OnProcessRecordAsyncEnd(string id, CancellationToken cancellationToken, GetEventData getEventData, SignalDelegate signal, string correlationId) |
237 | 286 | {
|
238 | 287 | await signal(Events.Debug, cancellationToken,
|
239 | 288 | () => EventHelper.CreateLogEvent($"[{id}]: Finish HTTP process"));
|
|
0 commit comments