Skip to content

Add PowerShell version into telemetry #15546

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 7 commits into from
Jul 28, 2021
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 @@ -20,6 +20,7 @@

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

Expand Down
13 changes: 10 additions & 3 deletions src/Accounts/Accounts/CommonModule/AzModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management.Automation;
using System.Net;
Expand Down Expand Up @@ -223,10 +224,16 @@ await signal(Events.Debug, cancellationToken,

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

internal async Task OnProcessRecordAsyncEnd(string id, CancellationToken cancellationToken, GetEventData getEventData, SignalDelegate signal, string processRecordId)
Expand Down Expand Up @@ -280,9 +287,9 @@ internal async Task OnCmdletEndProcessing(string id, CancellationToken cancellat
if (_telemetry.TryGetValue(processRecordId, out qos))
{
qos.IsSuccess = (qos.Exception == null);
await signal(Events.Debug, cancellationToken,
() => EventHelper.CreateLogEvent($"[{id}]: Sending new QosEvent for command '{qos.CommandName}': {qos.ToString()}"));
await signal(Events.Debug, cancellationToken, () => EventHelper.CreateLogEvent(qos.ToString()));
_telemetry.LogEvent(processRecordId);
await signal(Events.Debug, cancellationToken, () => EventHelper.CreateLogEvent("Finish sending metric."));
_previousEndTime = DateTimeOffset.Now;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Accounts/Accounts/CommonModule/TelemetryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
namespace Microsoft.Azure.Commands.Common
{
/// <summary>
/// Class providing telemtry usage based on the user's data collection settings
/// Class providing telemetry usage based on the user's data collection settings
/// </summary>
public class TelemetryProvider : IDictionary<string, AzurePSQoSEvent>, IDisposable
{
Expand Down Expand Up @@ -116,6 +116,7 @@ public virtual void LogEvent(string key)
{
qos.FinishQosEvent();
_helper.LogQoSEvent(qos, enabled, enabled);
_helper.FlushMetric();
this.Remove(key);
}
}
Expand Down Expand Up @@ -158,6 +159,9 @@ public virtual AzurePSQoSEvent CreateQosEvent(InvocationInfo invocationInfo, str

qosEvent.UserAgent = AzurePSCmdlet.UserAgent;
qosEvent.AzVersion = AzurePSCmdlet.AzVersion;
qosEvent.PSVersion = AzurePSCmdlet.PowerShellVersion;
qosEvent.HostVersion = AzurePSCmdlet.PSHostVersion;
qosEvent.PSHostName = AzurePSCmdlet.PSHostName;

if (invocationInfo != null)
{
Expand Down
34 changes: 17 additions & 17 deletions tools/Common.Netcore.Dependencies.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
<ItemGroup>
<PackageReference Include="Microsoft.Rest.ClientRuntime" Version="2.3.23"/>
<PackageReference Include="Microsoft.Rest.ClientRuntime.Azure" Version="3.3.19"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.41-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Aks" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Authentication.Abstractions" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Authorization" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Compute" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Graph.Rbac" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.KeyVault" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Monitor" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Network" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.PolicyInsights" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.ResourceManager" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Storage" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Storage.Management" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Strategies" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Clients.Websites" Version="1.3.43-preview"/>
<PackageReference Include="Microsoft.Azure.PowerShell.Common.Share" Version="1.3.43-preview"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.16.0"/>
Expand All @@ -36,7 +36,7 @@
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup>
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.41-preview\tools\</StorageToolsPath>
<StorageToolsPath>$(NugetPackageRoot)\microsoft.azure.powershell.storage\1.3.43-preview\tools\</StorageToolsPath>
</PropertyGroup>
<ItemGroup Condition="'$(OmitJsonPackage)' != 'true'">
<PackageReference Include="Newtonsoft.Json" Version="10.0.3"/>
Expand Down