Add telemetry to the console host to report platform and version (#3620)
This is limited to the console host and is not meant as generalized telemetry code for PowerShell Core. It will capture the GitCommitID and Platform Information when the console host starts. It enables opting out of sending telemetry.
This commit is contained in:
parent
f0eda031d6
commit
a2268ab3ec
3
.gitignore
vendored
3
.gitignore
vendored
@ -42,6 +42,9 @@ dotnet-uninstall-debian-packages.sh
|
||||
# ignore the version file as it is generated at build time
|
||||
powershell.version
|
||||
|
||||
# ignore the telemetry semaphore file
|
||||
DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY
|
||||
|
||||
# default location for produced nuget packages
|
||||
/nuget-artifacts
|
||||
|
||||
|
@ -160,6 +160,9 @@ function Start-PSBuild {
|
||||
# save Git description to file for PowerShell to include in PSVersionTable
|
||||
git --git-dir="$PSScriptRoot/.git" describe --dirty --abbrev=60 > "$psscriptroot/powershell.version"
|
||||
|
||||
# create the telemetry flag file
|
||||
$null = new-item -force -type file "$psscriptroot/DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY"
|
||||
|
||||
# simplify ParameterSetNames
|
||||
if ($PSCmdlet.ParameterSetName -eq 'FullCLR') {
|
||||
$FullCLR = $true
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\System.Management.Automation\System.Management.Automation.csproj" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
@ -257,6 +257,9 @@ namespace Microsoft.PowerShell
|
||||
s_theConsoleHost.UI.WriteWarningLine(preStartWarning);
|
||||
}
|
||||
|
||||
// Send startup telemetry for ConsoleHost startup
|
||||
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry();
|
||||
|
||||
ClrFacade.StartProfileOptimization(
|
||||
s_theConsoleHost.LoadPSReadline()
|
||||
? "StartupProfileData-Interactive"
|
||||
|
79
src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs
Normal file
79
src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs
Normal file
@ -0,0 +1,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.GetApplicationBase(Utils.DefaultPowerShellShellID),
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Include="*.so;*.dylib;..\..\license_thirdparty_proprietary.txt;..\..\powershell.version">
|
||||
<Content Include="*.so;*.dylib;..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
|
@ -23,7 +23,7 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\powershell.version">
|
||||
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
|
Loading…
Reference in New Issue
Block a user