Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9952d94
initial pass at new telemetry
JamesWTruher Jun 18, 2019
cb0efd5
remove some extraneous spaces at line endings
JamesWTruher Jul 11, 2019
7264dfa
Add more detailed startup data for console startup
JamesWTruher Jul 18, 2019
d8504e2
Fix up name of OSDetail channel
JamesWTruher Jul 29, 2019
3ec30e4
Remove pipeline telemetry, change the way the mutex is handled
JamesWTruher Jul 30, 2019
cd3284f
First round of clean up
JamesWTruher Aug 1, 2019
68ec2ea
additional refactoring
JamesWTruher Aug 1, 2019
5ad5c10
attempt to send telemetry if there is a catastrophic telemetry failure
JamesWTruher Aug 5, 2019
ac45459
further clean up
JamesWTruher Aug 6, 2019
7f429c1
Add tests for telemetry persistence and correct reading of the enviro…
JamesWTruher Aug 6, 2019
3fd4ef1
Add telemetry for experimental features
JamesWTruher Aug 6, 2019
67fd4e7
turn telemetry back off by default for test runs
JamesWTruher Aug 6, 2019
4a4964e
Change public types to internal
JamesWTruher Aug 8, 2019
7347dde
Change filename for telemetry class
JamesWTruher Aug 9, 2019
a37120b
add copyright to test file
JamesWTruher Aug 9, 2019
755686e
Partial updates for Codacy and Code Factor
JamesWTruher Aug 12, 2019
2dba693
Remove commented reference to application insights package
JamesWTruher Aug 12, 2019
23de71d
More CodeFactor fixes
JamesWTruher Aug 12, 2019
13997a1
more code factor fixes
JamesWTruher Aug 13, 2019
15be2f6
Update test to reflect unloaded assemblies
JamesWTruher Aug 13, 2019
3831a0f
Update test/powershell/engine/Basic/Telemetry.Tests.ps1
JamesWTruher Aug 13, 2019
485c25c
Update src/System.Management.Automation/engine/GetCommandCommand.cs
JamesWTruher Aug 13, 2019
c97f8f4
additional codefactor issues
JamesWTruher Aug 13, 2019
01c0c75
Remove assemblies which are no longer loaded
JamesWTruher Aug 13, 2019
00ed3ad
Harden link tests by allowing 503 response codes
JamesWTruher Aug 13, 2019
e041381
fix typo with regard to System.Xml.XDocument.dll
JamesWTruher Aug 13, 2019
752b1a9
make anonymous a const string
JamesWTruher Aug 13, 2019
4f3679a
Fixes to tests to address feedback
JamesWTruher Aug 13, 2019
d78a6d9
address feedback to call powershell without profile '-noprofile'
JamesWTruher Aug 14, 2019
0253f1f
Turn off developer mode at the last
JamesWTruher Aug 14, 2019
b367aec
Remove comment about telemetry collection in this location
JamesWTruher Aug 14, 2019
b894c59
Update test/powershell/engine/Basic/Telemetry.Tests.ps1
JamesWTruher Aug 15, 2019
3c1e49c
Merge branch 'master' into telemetry20
JamesWTruher Aug 15, 2019
1384b7e
Address feedback from @daxian-dbw
JamesWTruher Aug 15, 2019
21ebb3e
Don't create another string, just use s_uniqueUserIdentifier directly.
JamesWTruher Aug 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ function Start-PSPester {
# All concatenated commands/arguments are suffixed with the delimiter (space)

# Disable telemetry for all startups of pwsh in tests
$command = "`$env:POWERSHELL_TELEMETRY_OPTOUT = 1;"
$command = "`$env:POWERSHELL_TELEMETRY_OPTOUT = 'yes';"
if ($Terse)
{
$command += "`$ProgressPreference = 'silentlyContinue'; "
Expand Down Expand Up @@ -1153,7 +1153,7 @@ function Start-PSPester {
try {
$originalModulePath = $env:PSModulePath
$originalTelemetry = $env:POWERSHELL_TELEMETRY_OPTOUT
$env:POWERSHELL_TELEMETRY_OPTOUT = 1
$env:POWERSHELL_TELEMETRY_OPTOUT = 'yes'
if ($Unelevate)
{
Start-UnelevatedProcess -process $powershell -arguments ($PSFlags + "-c $Command")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

<ItemGroup>
<ProjectReference Include="..\System.Management.Automation\System.Management.Automation.csproj" />
<!-- the following package(s) are from https://github.com/microsoft/applicationinsights-??? -->
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0" />
</ItemGroup>

<PropertyGroup>
Expand Down
15 changes: 8 additions & 7 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.PowerShell.Telemetry;

using ConsoleHandle = Microsoft.Win32.SafeHandles.SafeFileHandle;
using Dbg = System.Management.Automation.Diagnostics;
Expand Down Expand Up @@ -123,12 +124,8 @@ internal static int Start(

try
{
string profileDir;
#if UNIX
profileDir = Platform.SelectProductNameForDirectory(Platform.XDG_Type.CACHE);
#else
profileDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\PowerShell";

string profileDir = Platform.CacheDirectory;
#if ! UNIX
if (!Directory.Exists(profileDir))
{
Directory.CreateDirectory(profileDir);
Expand Down Expand Up @@ -200,25 +197,29 @@ internal static int Start(
// First check for and handle PowerShell running in a server mode.
if (s_cpp.ServerMode)
{
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("ServerMode");
ProfileOptimization.StartProfile("StartupProfileData-ServerMode");
System.Management.Automation.Remoting.Server.OutOfProcessMediator.Run(s_cpp.InitialCommand);
exitCode = 0;
}
else if (s_cpp.NamedPipeServerMode)
{
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("NamedPipe");
ProfileOptimization.StartProfile("StartupProfileData-NamedPipeServerMode");
System.Management.Automation.Remoting.RemoteSessionNamedPipeServer.RunServerMode(
s_cpp.ConfigurationName);
exitCode = 0;
}
else if (s_cpp.SSHServerMode)
{
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("SSHServer");
ProfileOptimization.StartProfile("StartupProfileData-SSHServerMode");
System.Management.Automation.Remoting.Server.SSHProcessMediator.Run(s_cpp.InitialCommand);
exitCode = 0;
}
else if (s_cpp.SocketServerMode)
{
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("SocketServerMode");
ProfileOptimization.StartProfile("StartupProfileData-SocketServerMode");
System.Management.Automation.Remoting.Server.HyperVSocketMediator.Run(s_cpp.InitialCommand,
s_cpp.ConfigurationName);
Expand All @@ -242,7 +243,7 @@ internal static int Start(
PSHost.IsStdOutputRedirected = Console.IsOutputRedirected;

// Send startup telemetry for ConsoleHost startup
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry();
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry("Normal");

exitCode = s_theConsoleHost.Run(s_cpp, false);
}
Expand Down
102 changes: 0 additions & 102 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs

This file was deleted.

15 changes: 15 additions & 0 deletions src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ public static bool IsWindowsDesktop
}
}

/// <summary>
/// Gets the location for the various caches.
/// </summary>
internal static string CacheDirectory
{
get
{
#if UNIX
return Platform.SelectProductNameForDirectory(Platform.XDG_Type.CACHE);
#else
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\PowerShell";
#endif
}
}

#if !UNIX
private static bool? _isNanoServer = null;
private static bool? _isIoT = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<ItemGroup>
<!-- the following package(s) are from https://github.com/JamesNK/Newtonsoft.Json -->
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<!-- the Application Insights package -->
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0" />
<!-- the following package(s) are from https://github.com/dotnet/corefx -->
<PackageReference Include="Microsoft.Win32.Registry.AccessControl" Version="4.6.0-preview8.19405.3" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.6.0-preview8.19405.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,12 @@ private static CommandCompletion CallScriptWithAstParameterSet(Ast ast, Token[]
// This is the start of the real implementation of autocomplete/intellisense/tab completion
private static CommandCompletion CompleteInputImpl(Ast ast, Token[] tokens, IScriptPosition positionOfCursor, Hashtable options)
{
#if LEGACYTELEMETRY
// We could start collecting telemetry at a later date.
// We will leave the #if to remind us that we did this once.
var sw = new Stopwatch();
sw.Start();

#endif
using (var powershell = PowerShell.Create(RunspaceMode.CurrentRunspace))
{
var context = LocalPipeline.GetExecutionContextFromTLS();
Expand Down Expand Up @@ -590,8 +593,10 @@ private static CommandCompletion CompleteInputImpl(Ast ast, Token[] tokens, IScr
}

var completionResults = results ?? EmptyCompletionResult;
sw.Stop();

#if LEGACYTELEMETRY
// no telemetry here. We don't capture tab completion performance.
sw.Stop();
TelemetryAPI.ReportTabCompletionTelemetry(sw.ElapsedMilliseconds, completionResults.Count,
completionResults.Count > 0 ? completionResults[0].ResultType : CompletionResultType.Text);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Management.Automation.Internal;
using System.Management.Automation.Tracing;
using System.Runtime.CompilerServices;
using Microsoft.PowerShell.Telemetry;

namespace System.Management.Automation
{
Expand Down Expand Up @@ -150,13 +151,15 @@ private static ReadOnlyBag<string> ProcessEnabledFeatures(string[] enabledFeatur
if (IsModuleFeatureName(name))
{
list.Add(name);
ApplicationInsightsTelemetry.SendTelemetryMetric(TelemetryType.ExperimentalModuleFeatureActivation, name);
}
else if (IsEngineFeatureName(name))
{
if (EngineExperimentalFeatureMap.TryGetValue(name, out ExperimentalFeature feature))
{
feature.Enabled = true;
list.Add(name);
ApplicationInsightsTelemetry.SendTelemetryMetric(TelemetryType.ExperimentalEngineFeatureActivation, name);
}
else
{
Expand Down
10 changes: 7 additions & 3 deletions src/System.Management.Automation/engine/GetCommandCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,9 @@ public PSTypeName[] ParameterType
/// </summary>
protected override void BeginProcessing()
{
#if LEGACYTELEMETRY
_timer.Start();

#endif
base.BeginProcessing();

if (ShowCommandInfo.IsPresent && Syntax.IsPresent)
Expand Down Expand Up @@ -552,9 +553,11 @@ private void OutputResultsHelper(IEnumerable<CommandInfo> results)
}
}

#if LEGACYTELEMETRY
_timer.Stop();

#if LEGACYTELEMETRY
// No telemetry here - capturing the name of a command which we are not familiar with
// may be confidential customer information
// We want telementry on commands people look for but don't exist - this should give us an idea
// what sort of commands people expect but either don't exist, or maybe should be installed by default.
// The StartsWith is to avoid logging telemetry when suggestion mode checks the
Expand Down Expand Up @@ -1443,8 +1446,9 @@ private bool IsCommandInResult(CommandInfo command)
private Collection<WildcardPattern> _nounPatterns;
private Collection<WildcardPattern> _modulePatterns;

#if LEGACYTELEMETRY
private Stopwatch _timer = new Stopwatch();

#endif
#endregion

#region ShowCommandInfo support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Internal;
using System.Management.Automation.Language;
using System.Management.Automation.Runspaces;
using System.Reflection;
using System.Security;
using System.Threading;

using Microsoft.Management.Infrastructure;
using Microsoft.PowerShell.Cmdletization;
using Microsoft.PowerShell.Telemetry;

using Dbg = System.Management.Automation.Diagnostics;

using System.Management.Automation.Language;
using Parser = System.Management.Automation.Language.Parser;
using ScriptBlock = System.Management.Automation.ScriptBlock;
using Token = System.Management.Automation.Language.Token;

#if LEGACYTELEMETRY
using Microsoft.PowerShell.Telemetry.Internal;
#endif
Expand Down Expand Up @@ -825,6 +826,12 @@ private IList<PSModuleInfo> ImportModule_RemotelyViaPsrpSession(
}
}

// Send telemetry on the imported modules
foreach (PSModuleInfo moduleInfo in remotelyImportedModules)
{
ApplicationInsightsTelemetry.SendTelemetryMetric(TelemetryType.ModuleLoad, moduleInfo.Name);
}

return remotelyImportedModules;
}

Expand Down Expand Up @@ -1251,6 +1258,7 @@ private void ImportModule_RemotelyViaCimSession(
foreach (RemoteDiscoveryHelper.CimModule remoteCimModule in remotePsCimModules)
{
ImportModule_RemotelyViaCimModuleData(importModuleOptions, remoteCimModule, cimSession);
ApplicationInsightsTelemetry.SendTelemetryMetric(TelemetryType.ModuleLoad, remoteCimModule.ModuleName);
}
}

Expand Down Expand Up @@ -1743,6 +1751,7 @@ protected override void ProcessRecord()
// of doing Get-Module -list
foreach (PSModuleInfo module in ModuleInfo)
{
ApplicationInsightsTelemetry.SendTelemetryMetric(TelemetryType.ModuleLoad, module.Name);
RemoteDiscoveryHelper.DispatchModuleInfoProcessing(
module,
localAction: delegate ()
Expand Down Expand Up @@ -1772,6 +1781,7 @@ protected override void ProcessRecord()
{
foreach (Assembly suppliedAssembly in Assembly)
{
ApplicationInsightsTelemetry.SendTelemetryMetric(TelemetryType.ModuleLoad, suppliedAssembly.GetName().Name);
ImportModule_ViaAssembly(importModuleOptions, suppliedAssembly);
}
}
Expand All @@ -1785,6 +1795,8 @@ protected override void ProcessRecord()
{
SetModuleBaseForEngineModules(foundModule.Name, this.Context);

// Telemetry here - report module load
ApplicationInsightsTelemetry.SendTelemetryMetric(TelemetryType.ModuleLoad, foundModule.Name);
#if LEGACYTELEMETRY
TelemetryAPI.ReportModuleLoad(foundModule);
#endif
Expand All @@ -1809,6 +1821,7 @@ protected override void ProcessRecord()
BaseGuid = modulespec.Guid;

PSModuleInfo foundModule = ImportModule_LocallyViaName(importModuleOptions, modulespec.Name);
ApplicationInsightsTelemetry.SendTelemetryMetric(TelemetryType.ModuleLoad, modulespec.Name);
if (foundModule != null)
{
SetModuleBaseForEngineModules(foundModule.Name, this.Context);
Expand All @@ -1818,6 +1831,10 @@ protected override void ProcessRecord()
else if (this.ParameterSetName.Equals(ParameterSet_FQName_ViaPsrpSession, StringComparison.OrdinalIgnoreCase))
{
ImportModule_RemotelyViaPsrpSession(importModuleOptions, null, FullyQualifiedName, this.PSSession);
foreach (ModuleSpecification modulespec in FullyQualifiedName)
{
ApplicationInsightsTelemetry.SendTelemetryMetric(TelemetryType.ModuleLoad, modulespec.Name);
}
}
else
{
Expand Down
Loading