Skip to content

Commit f17c3e1

Browse files
authored
Merge pull request #301 from maddieclayton/TelemetryAdjustment
Add required telemetry changes
2 parents 38778d4 + 6a86d8a commit f17c3e1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Common/Commands.Common/AzurePSCmdlet.cs

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

523523
try
524524
{
525+
_metricHelper.SetPSHost(this.Host);
525526
_metricHelper.LogQoSEvent(_qosEvent, IsUsageMetricEnabled, IsErrorMetricEnabled);
526527
_metricHelper.FlushMetric();
527528
WriteDebug("Finish sending metric.");

src/Common/Commands.Common/MetricHelper.cs

Lines changed: 32 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,8 @@ public class MetricHelper
3132
{
3233
protected INetworkHelper _networkHelper;
3334
private const int FlushTimeoutInMilli = 5000;
35+
private const string DefaultPSVersion = "3.0.0.0";
36+
private const string EventName = "cmdletInvocation";
3437

3538
/// <summary>
3639
/// The collection of telemetry clients.
@@ -58,6 +61,26 @@ public class MetricHelper
5861

5962
private AzurePSDataCollectionProfile _profile;
6063

64+
private static PSHost _host;
65+
66+
private static string _psVersion;
67+
68+
protected string PSVersion
69+
{
70+
get
71+
{
72+
if (_host != null)
73+
{
74+
_psVersion = _host.Version.ToString();
75+
}
76+
else
77+
{
78+
_psVersion = DefaultPSVersion;
79+
}
80+
return _psVersion;
81+
}
82+
}
83+
6184
public string HashMacAddress
6285
{
6386
get
@@ -171,7 +194,7 @@ private void LogUsageEvent(AzurePSQoSEvent qos)
171194
{
172195
var pageViewTelemetry = new PageViewTelemetry
173196
{
174-
Name = qos.CommandName ?? "empty",
197+
Name = EventName,
175198
Duration = qos.Duration,
176199
Timestamp = qos.StartTime
177200
};
@@ -217,13 +240,19 @@ private void LoadTelemetryClientContext(AzurePSQoSEvent qos, TelemetryContext cl
217240
}
218241
}
219242

243+
public void SetPSHost(PSHost host)
244+
{
245+
_host = host;
246+
}
247+
220248
private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string, string> eventProperties)
221249
{
222250
if (qos == null)
223251
{
224252
return;
225253
}
226254

255+
eventProperties.Add("Command", qos.CommandName);
227256
eventProperties.Add("IsSuccess", qos.IsSuccess.ToString());
228257
eventProperties.Add("ModuleName", qos.ModuleName);
229258
eventProperties.Add("ModuleVersion", qos.ModuleVersion);
@@ -234,6 +263,8 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string,
234263
eventProperties.Add("x-ms-client-request-id", qos.ClientRequestId);
235264
eventProperties.Add("UserAgent", AzurePowerShell.UserAgentValue.ToString());
236265
eventProperties.Add("HashMacAddress", HashMacAddress);
266+
eventProperties.Add("PowerShellVersion", PSVersion);
267+
eventProperties.Add("Version", AzurePowerShell.AssemblyVersion);
237268
if (qos.InputFromPipeline != null)
238269
{
239270
eventProperties.Add("InputFromPipeline", qos.InputFromPipeline.Value.ToString());

0 commit comments

Comments
 (0)