8000 Disable UTC and SQM telemetry by enclosing the code in '#if LEGACYTEL… · PowerShell/PowerShell@71392a2 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 71392a2

Browse files
JamesWTruherdaxian-dbw
authored andcommitted
Disable UTC and SQM telemetry by enclosing the code in '#if LEGACYTELEMETRY' (#4190)
1 parent f95fbf1 commit 71392a2

File tree

12 files changed

+55
-6
lines changed

12 files changed

+55
-6
lines changed

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
using ConsoleHandle = Microsoft.Win32.SafeHandles.SafeFileHandle;
2929
using NakedWin32Handle = System.IntPtr;
3030
using System.Management.Automation.Tracing;
31+
#if LEGACYTELEMETRY
3132
using Microsoft.PowerShell.Telemetry.Internal;
33+
#endif
3234
using Debugger = System.Management.Automation.Debugger;
3335

3436
namespace Microsoft.PowerShell
@@ -44,8 +46,10 @@ internal sealed partial class ConsoleHost
4446
:
4547
PSHost,
4648
IDisposable,
47-
IHostSupportsInteractiveSession,
48-
IHostProvidesTelemetryData
49+
#if LEGACYTELEMETRY
50+
IHostProvidesTelemetryData,
51+
#endif
52+
IHostSupportsInteractiveSession
4953
{
5054
#region static methods
5155

@@ -271,7 +275,9 @@ internal static int Start(
271275
{
272276
if (s_theConsoleHost != null)
273277
{
278+
#if LEGACYTELEMETRY
274279
TelemetryAPI.ReportExitTelemetry(s_theConsoleHost);
280+
#endif
275281
s_theConsoleHost.Dispose();
276282
}
277283
}
@@ -1038,6 +1044,7 @@ public override void NotifyEndApplication()
10381044
}
10391045
}
10401046

1047+
#if LEGACYTELEMETRY
10411048
bool IHostProvidesTelemetryData.HostIsInteractive
10421049
{
10431050
get
@@ -1049,6 +1056,7 @@ bool IHostProvidesTelemetryData.HostIsInteractive
10491056
double IHostProvidesTelemetryData.ProfileLoadTimeInMS { get { return _profileLoadTimeInMS; } }
10501057
double IHostProvidesTelemetryData.ReadyForInputTimeInMS { get { return _readyForInputTimeInMS; } }
10511058
int IHostProvidesTelemetryData.InteractiveCommandCount { get { return _interactiveCommandCount; } }
1059+
#endif
10521060

10531061
private double _profileLoadTimeInMS;
10541062
private double _readyForInputTimeInMS;
@@ -1807,10 +1815,11 @@ private void DoRunspaceInitialization(bool importSystemModules, bool skipProfile
18071815
s_tracer.WriteLine("-noprofile option specified: skipping profiles");
18081816
}
18091817
}
1810-
1818+
#if LEGACYTELEMETRY
18111819
// Startup is reported after possibly running the profile, but before running the initial command (or file)
18121820
// if one is specified.
18131821
TelemetryAPI.ReportStartupTelemetry(this);
1822+
#endif
18141823

18151824
// If a file was specified as the argument to run, then run it...
18161825
if (s_cpp != null && s_cpp.File != null)

src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
using System.Management.Automation.Language;
1313
using System.Management.Automation.Runspaces;
1414
using System.Text.RegularExpressions;
15+
#if LEGACYTELEMETRY
1516
using Microsoft.PowerShell.Telemetry.Internal;
17+
#endif
1618

1719
namespace System.Management.Automation
1820
{
@@ -591,8 +593,10 @@ private static CommandCompletion CompleteInputImpl(Ast ast, Token[] tokens, IScr
591593

592594
var completionResults = results ?? EmptyCompletionResult;
593595
sw.Stop();
596+
#if LEGACYTELEMETRY
594597
TelemetryAPI.ReportTabCompletionTelemetry(sw.ElapsedMilliseconds, completionResults.Count,
595598
completionResults.Count > 0 ? completionResults[0].ResultType : CompletionResultType.Text);
599+
#endif
596600
return new CommandCompletion(
597601
new Collection<CompletionResult>(completionResults),
598602
-1,

src/System.Management.Automation/engine/GetCommandCommand.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ private void OutputResultsHelper(IEnumerable<CommandInfo> results)
531531

532532
_timer.Stop();
533533

534+
#if LEGACYTELEMETRY
534535
// We want telementry on commands people look for but don't exist - this should give us an idea
535536
// what sort of commands people expect but either don't exist, or maybe should be installed by default.
536537
// The StartsWith is to avoid logging telemetry when suggestion mode checks the
@@ -539,6 +540,8 @@ private void OutputResultsHelper(IEnumerable<CommandInfo> results)
539540
{
540541
Telemetry.Internal.TelemetryAPI.ReportGetCommandFailed(Name, _timer.ElapsedMilliseconds);
541542
}
543+
#endif
544+
542545
}
543546

544547
/// <summary>

src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
using Parser = System.Management.Automation.Language.Parser;
2424
using ScriptBlock = System.Management.Automation.ScriptBlock;
2525
using Token = System.Management.Automation.Language.Token;
26+
#if LEGACYTELEMETRY
2627
using Microsoft.PowerShell.Telemetry.Internal;
28+
#endif
2729

2830
#if CORECLR
2931
// Use stub for SecurityZone.
@@ -1720,7 +1722,9 @@ protected override void ProcessRecord()
17201722
{
17211723
SetModuleBaseForEngineModules(foundModule.Name, this.Context);
17221724

1725+
#if LEGACYTELEMETRY
17231726
TelemetryAPI.ReportModuleLoad(foundModule);
1727+
#endif
17241728
}
17251729
}
17261730
}

src/System.Management.Automation/engine/hostifaces/ConnectionBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
using System.Threading;
88
using System.Management.Automation.Host;
99
using System.Management.Automation.Internal;
10+
#if LEGACYTELEMETRY
1011
using Microsoft.PowerShell.Telemetry.Internal;
12+
#endif
1113
using Dbg = System.Management.Automation.Diagnostics;
1214

1315
#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings
@@ -279,6 +281,7 @@ private void CoreOpen(bool syncCall)
279281
OpenHelper(syncCall);
280282
if (etwEnabled) RunspaceEventSource.Log.OpenRunspaceStop();
281283

284+
#if LEGACYTELEMETRY
282285
// We report startup telementry when opening the runspace - because this is the first time
283286
// we are really using PowerShell. This isn't the cleanest place though, because
284287
// sometimes there are many runspaces created - the callee ensures telemetry is only
@@ -288,6 +291,7 @@ private void CoreOpen(bool syncCall)
288291
{
289292
TelemetryAPI.ReportStartupTelemetry(null);
290293
}
294+
#endif
291295
}
292296

293297

src/System.Management.Automation/engine/hostifaces/LocalConnection.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
using Dbg = System.Management.Automation.Diagnostics;
1717
using System.Diagnostics;
1818
using System.Linq;
19+
#if LEGACYTELEMETRY
1920
using Microsoft.PowerShell.Telemetry.Internal;
21+
#endif
2022

2123
#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings
2224

@@ -737,7 +739,9 @@ private void DoOpenHelper()
737739
}
738740
}
739741

742+
#if LEGACYTELEMETRY
740743
TelemetryAPI.ReportLocalSessionCreated(InitialSessionState, TranscriptionData);
744+
#endif
741745
}
742746

743747
/// <summary>
@@ -936,6 +940,8 @@ private void DoCloseHelper()
936940
RaiseRunspaceStateEvents();
937941

938942
// Report telemetry if we have no more open runspaces.
943+
944+
#if LEGACYTELEMETRY
939945
bool allRunspacesClosed = true;
940946
bool hostProvidesExitTelemetry = false;
941947
foreach (var r in Runspace.RunspaceList)
@@ -956,6 +962,7 @@ private void DoCloseHelper()
956962
{
957963
TelemetryAPI.ReportExitTelemetry(null);
958964
}
965+
#endif
959966
}
960967

961968
/// <summary>

src/System.Management.Automation/engine/pipeline.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,9 @@ private void Start(bool incomingStream)
10101010
CommandState.Started,
10111011
commandProcessor.Command.MyInvocation);
10121012

1013-
//Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI.TraceExecutedCommand(commandProcessor.Command.CommandInfo, commandProcessor.Command.CommandOrigin);
1013+
#if LEGACYTELEMETRY
1014+
Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI.TraceExecutedCommand(commandProcessor.Command.CommandInfo, commandProcessor.Command.CommandOrigin);
1015+
#endif
10141016

10151017
// Log the execution of a command (not script chunks, as they
10161018
// are not commands in and of themselves)

src/System.Management.Automation/engine/remoting/client/RemoteRunspacePoolInternal.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
using System.Management.Automation.Host;
1313
using System.Collections.ObjectModel;
1414
using System.Management.Automation.Remoting.Client;
15+
#if LEGACYTELEMETRY
1516
using Microsoft.PowerShell.Telemetry.Internal;
17+
#endif
1618

1719
namespace System.Management.Automation.Runspaces.Internal
1820
{
@@ -850,7 +852,9 @@ protected override IAsyncResult CoreOpen(bool isAsync, AsyncCallback callback,
850852
PSEtwLog.LogOperationalVerbose(PSEventId.RunspacePoolOpen, PSOpcode.Open,
851853
PSTask.CreateRunspace, PSKeyword.UseAlwaysOperational);
852854

855+
#if LEGACYTELEMETRY
853856
TelemetryAPI.ReportRemoteSessionCreated(_connectionInfo);
857+
#endif
854858

855859
lock (syncObject)
856860
{

src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
using System.Runtime.Serialization;
1717
using System.Text;
1818
using System.Threading.Tasks;
19+
#if LEGACYTELEMETRY
1920
using Microsoft.PowerShell.Telemetry.Internal;
21+
#endif
2022

2123
namespace System.Management.Automation
2224
{
@@ -178,11 +180,12 @@ private void ReallyCompile(bool optimize)
178180
Compiler compiler = new Compiler();
179181
compiler.Compile(this, optimize);
180182

183+
#if LEGACYTELEMETRY
181184
if (!IsProductCode)
182185
{
183186
TelemetryAPI.ReportScriptTelemetry((Ast)_ast, !optimize, sw.ElapsedMilliseconds);
184187
}
185-
188+
#endif
186189
if (etwEnabled) ParserEventSource.Log.CompileStop();
187190
}
188191

src/System.Management.Automation/help/HelpCommands.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ public SwitchParameter ShowWindow
234234
#endif
235235

236236
private readonly Stopwatch _timer = new Stopwatch();
237+
#if LEGACYTELEMETRY
237238
private bool _updatedHelp;
239+
#endif
238240

239241
#endregion
240242

@@ -252,7 +254,9 @@ protected override void BeginProcessing()
252254
if (ShouldContinue(HelpDisplayStrings.UpdateHelpPromptBody, HelpDisplayStrings.UpdateHelpPromptTitle))
253255
{
254256
System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace).AddCommand("Update-Help").Invoke();
257+
#if LEGACYTELEMETRY
255258
_updatedHelp = true;
259+
#endif
256260
}
257261

258262
UpdatableHelpSystem.SetDisablePromptToUpdateHelp();
@@ -332,9 +336,10 @@ protected override void ProcessRecord()
332336

333337
_timer.Stop();
334338

339+
#if LEGACYTELEMETRY
335340
if (!string.IsNullOrEmpty(Name))
336341
Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI.ReportGetHelpTelemetry(Name, countOfHelpInfos, _timer.ElapsedMilliseconds, _updatedHelp);
337-
342+
#endif
338343
// Write full help as there is only one help info object
339344
if (1 == countOfHelpInfos)
340345
{

0 commit comments

Comments
 (0)
0