Skip to content

Commit bd0614b

Browse files
committed
Add required telemetry changes
1 parent 776e214 commit bd0614b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/Common/Commands.Common/AzurePSCmdlet.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ protected void LogQosEvent()
556556

557557
try
558558
{
559+
_metricHelper.SetPSHost(this.Host);
559560
_metricHelper.LogQoSEvent(_qosEvent, IsUsageMetricEnabled, IsErrorMetricEnabled);
560561
_metricHelper.FlushMetric();
561562
WriteDebug("Finish sending metric.");

src/Common/Commands.Common/MetricHelper.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System;
2323
using System.Collections.Generic;
2424
using System.Diagnostics;
25+
using System.Management.Automation.Host;
2526
using System.Security.Cryptography;
2627
using System.Text;
2728

@@ -31,6 +32,7 @@ public class MetricHelper
3132
{
3233
protected INetworkHelper _networkHelper;
3334
private const int FlushTimeoutInMilli = 5000;
35+
private const string DEFAULT_PSVERSION = "3.0.0.0";
3436

3537
/// <summary>
3638
/// The collection of telemetry clients.
@@ -56,6 +58,26 @@ public class MetricHelper
5658

5759
private static string _hashMacAddress = string.Empty;
5860

61+
private static PSHost _host;
62+
63+
private static string _psVersion;
64+
65+
protected string PSVersion
66+
{
67+
get
68+
{
69+
if (_host != null)
70+
{
71+
_psVersion = _host.Version.ToString();
72+
}
73+
else
74+
{
75+
_psVersion = DEFAULT_PSVERSION;
76+
}
77+
return _psVersion;
78+
}
79+
}
80+
5981
public string HashMacAddress
6082
{
6183
get
@@ -168,7 +190,7 @@ private void LogUsageEvent(AzurePSQoSEvent qos)
168190
{
169191
var pageViewTelemetry = new PageViewTelemetry
170192
{
171-
Name = qos.CommandName ?? "empty",
193+
Name = "cmdletInvocation",
172194
Duration = qos.Duration,
173195
Timestamp = qos.StartTime
174196
};
@@ -214,13 +236,19 @@ private void LoadTelemetryClientContext(AzurePSQoSEvent qos, TelemetryContext cl
214236
}
215237
}
216238

239+
public void SetPSHost(PSHost host)
240+
{
241+
_host = host;
242+
}
243+
217244
private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string, string> eventProperties)
218245
{
219246
if (qos == null)
220247
{
221248
return;
222249
}
223250

251+
eventProperties.Add("Command", qos.CommandName);
224252
eventProperties.Add("IsSuccess", qos.IsSuccess.ToString());
225253
eventProperties.Add("ModuleName", qos.ModuleName);
226254
eventProperties.Add("ModuleVersion", qos.ModuleVersion);
@@ -231,6 +259,8 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string,
231259
eventProperties.Add("x-ms-client-request-id", qos.ClientRequestId);
232260
eventProperties.Add("UserAgent", AzurePowerShell.UserAgentValue.ToString());
233261
eventProperties.Add("HashMacAddress", HashMacAddress);
262+
eventProperties.Add("PowerShellVersion", PSVersion);
263+
eventProperties.Add("Version", AzurePowerShell.AssemblyVersion);
234264
if (qos.InputFromPipeline != null)
235265
{
236266
eventProperties.Add("InputFromPipeline", qos.InputFromPipeline.Value.ToString());

0 commit comments

Comments
 (0)