-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add telemetry to the console host to report platform and version #3620
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
Changes from all commits
95acf77
412ce4b
c90d669
101a757
fcf9d82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -257,6 +257,9 @@ internal static int Start( | |
| s_theConsoleHost.UI.WriteWarningLine(preStartWarning); | ||
| } | ||
|
|
||
| // Send startup telemetry for ConsoleHost startup | ||
| ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry(); | ||
|
||
|
|
||
| ClrFacade.StartProfileOptimization( | ||
| s_theConsoleHost.LoadPSReadline() | ||
| ? "StartupProfileData-Interactive" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will create the file in the directory where Start-PSBuild is being run. But don't we want this location to be the output publish path? #Closed
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The placement of the file in the actual publish directory is managed by putting it in the *.csproj files (same as powershell.version is done), but the file has to exist. #Closed