Skip to content

Commit ad87106

Browse files
authored
Add PowerShell version into telemetry (#15546)
* Add PowerShell version into telemetry * Update changelog * Add dummy code * Remove local test libs
1 parent 5d854e7 commit ad87106

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

src/Accounts/Accounts/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
## Upcoming Release
2222
* Disabled context auto saving when token cache persistence fails on Windows and macOS
23+
* Added PowerShell version into telemetry record
2324
* Upgraded Microsoft.ApplicationInsights from 2.4.0 to 2.12.0
2425
* Updated Azure.Core to 1.16.0
2526

src/Accounts/Accounts/CommonModule/AzModule.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Newtonsoft.Json;
2323
using System;
2424
using System.Collections.Generic;
25+
using System.Collections.ObjectModel;
2526
using System.Linq;
2627
using System.Management.Automation;
2728
using System.Net;
@@ -223,10 +224,16 @@ await signal(Events.Debug, cancellationToken,
223224

224225
internal async Task OnProcessRecordAsyncStart(string id, CancellationToken cancellationToken, GetEventData getEventData, SignalDelegate signal, string processRecordId, InvocationInfo invocationInfo, string parameterSetName, string correlationId)
225226
{
227+
//AzVersion is null indicates no SDK based cmdlet is invoked. Below properties needs to be filled.
228+
if(_runtime != null && AzurePSCmdlet.AzVersion == null)
229+
{
230+
AzurePSCmdlet.PSHostName = _runtime.Host?.Name;
231+
AzurePSCmdlet.PSHostVersion = _runtime.Host?.Version?.ToString();
232+
}
226233
var qos = _telemetry.CreateQosEvent(invocationInfo, parameterSetName, correlationId, processRecordId);
227234
qos.PreviousEndTime = _previousEndTime;
228235
await signal(Events.Debug, cancellationToken,
229-
() => EventHelper.CreateLogEvent($"[{id}]: Created new QosEvent for command '{qos?.CommandName}': {qos?.ToString()}"));
236+
() => EventHelper.CreateLogEvent($"[{id}]: Created new QosEvent for command '{qos?.CommandName}'"));
230237
}
231238

232239
internal async Task OnProcessRecordAsyncEnd(string id, CancellationToken cancellationToken, GetEventData getEventData, SignalDelegate signal, string processRecordId)
@@ -280,9 +287,9 @@ internal async Task OnCmdletEndProcessing(string id, CancellationToken cancellat
280287
if (_telemetry.TryGetValue(processRecordId, out qos))
281288
{
282289
qos.IsSuccess = (qos.Exception == null);
283-
await signal(Events.Debug, cancellationToken,
284-
() => EventHelper.CreateLogEvent($"[{id}]: Sending new QosEvent for command '{qos.CommandName}': {qos.ToString()}"));
290+
await signal(Events.Debug, cancellationToken, () => EventHelper.CreateLogEvent(qos.ToString()));
285291
_telemetry.LogEvent(processRecordId);
292+
await signal(Events.Debug, cancellationToken, () => EventHelper.CreateLogEvent("Finish sending metric."));
286293
_previousEndTime = DateTimeOffset.Now;
287294
}
288295
}

src/Accounts/Accounts/CommonModule/TelemetryProvider.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
namespace Microsoft.Azure.Commands.Common
3333
{
3434
/// <summary>
35-
/// Class providing telemtry usage based on the user's data collection settings
35+
/// Class providing telemetry usage based on the user's data collection settings
3636
/// </summary>
3737
public class TelemetryProvider : IDictionary<string, AzurePSQoSEvent>, IDisposable
3838
{
@@ -116,6 +116,7 @@ public virtual void LogEvent(string key)
116116
{
117117
qos.FinishQosEvent();
118118
_helper.LogQoSEvent(qos, enabled, enabled);
119+
_helper.FlushMetric();
119120
this.Remove(key);
120121
}
121122
}
@@ -158,6 +159,9 @@ public virtual AzurePSQoSEvent CreateQosEvent(InvocationInfo invocationInfo, str
158159

159160
qosEvent.UserAgent = AzurePSCmdlet.UserAgent;
160161
qosEvent.AzVersion = AzurePSCmdlet.AzVersion;
162+
qosEvent.PSVersion = AzurePSCmdlet.PowerShellVersion;
163+
qosEvent.HostVersion = AzurePSCmdlet.PSHostVersion;
164+
qosEvent.PSHostName = AzurePSCmdlet.PSHostName;
161165

162166
if (invocationInfo != null)
163167
{

tools/Common.Netcore.Dependencies.targets

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
<ItemGroup>
44
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.23"/>
55
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure" Version="3.3.19"/>
6-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.41-preview"/>
7-
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.41-preview"/>
8-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.41-preview"/>
9-
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.41-preview"/>
10-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.41-preview"/>
11-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.41-preview"/>
12-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.41-preview"/>
13-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.41-preview"/>
14-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.41-preview"/>
15-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.41-preview"/>
16-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.41-preview"/>
17-
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.41-preview"/>
18-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.41-preview"/>
19-
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.41-preview"/>
20-
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.41-preview"/>
21-
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.41-preview"/>
6+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.43-preview"/>
7+
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.43-preview"/>
8+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.43-preview"/>
9+
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.43-preview"/>
10+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.43-preview"/>
11+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.43-preview"/>
12+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.43-preview"/>
13+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.43-preview"/>
14+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.43-preview"/>
15+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.43-preview"/>
16+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.43-preview"/>
17+
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.43-preview"/>
18+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.43-preview"/>
19+
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.43-preview"/>
20+
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.43-preview"/>
21+
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.43-preview"/>
2222
</ItemGroup>
2323
<ItemGroup>
2424
<PackageReference Include="Azure.Core" Version="1.16.0"/>
@@ -36,7 +36,7 @@
3636
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" PrivateAssets="All" />
3737
</ItemGroup>
3838
<PropertyGroup>
39-
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.41-preview\tools\</StorageToolsPath>
39+
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.43-preview\tools\</StorageToolsPath>
4040
</PropertyGroup>
4141
<ItemGroup Condition="'$(OmitJsonPackage)' != 'true'">
4242
<PackageReference Include="Newtonsoft.Json" Version="10.0.3"/>

0 commit comments

Comments
 (0)