forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTelemetry.cs
More file actions
79 lines (71 loc) · 2.97 KB
/
Copy pathTelemetry.cs
File metadata and controls
79 lines (71 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using System.Management.Automation;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using System.IO;
namespace Microsoft.PowerShell
{
/// <summary>
/// send up telemetry for startup
/// </summary>
internal static class ApplicationInsightsTelemetry
{
// The semaphore file which indicates whether telemetry should be sent
// This is temporary code waiting on the acceptance and implementation of the configuration spec
// The name of the file by when present in $PSHOME will enable telemetry.
// If this file is not present, no telemetry will be sent.
private const string TelemetrySemaphoreFilename = "DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY";
// The path to the semaphore file which enables telemetry
private static string TelemetrySemaphoreFilePath = Path.Combine(
Utils.DefaultPowerShellAppBase,
TelemetrySemaphoreFilename);
// Telemetry client to be reused when we start sending more telemetry
private static TelemetryClient _telemetryClient = null;
// Set this to true to reduce the latency of sending the telemetry
private static bool _developerMode = false;
// PSCoreInsight2 telemetry key
private const string _psCoreTelemetryKey = "ee4b2115-d347-47b0-adb6-b19c2c763808";
static ApplicationInsightsTelemetry()
{
TelemetryConfiguration.Active.InstrumentationKey = _psCoreTelemetryKey;
TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = _developerMode;
}
/// <summary>
/// Send the telemetry
/// </summary>
private static void SendTelemetry(string eventName, Dictionary<string,string>payload)
{
try
{
// if the semaphore file exists, try to send telemetry
if (Utils.NativeFileExists(TelemetrySemaphoreFilePath))
{
if ( _telemetryClient == null )
{
_telemetryClient = new TelemetryClient();
}
_telemetryClient.TrackEvent(eventName, payload, null);
}
}
catch (Exception)
{
; // Do nothing, telemetry can't be sent
}
}
/// <summary>
/// Create the startup payload and send it up
/// </summary>
internal static void SendPSCoreStartupTelemetry()
{
var properties = new Dictionary<string, string>();
properties.Add("GitCommitID", PSVersionInfo.GitCommitId);
properties.Add("OSDescription", RuntimeInformation.OSDescription);
SendTelemetry("ConsoleHostStartup", properties);
}
}
}