/// <summary> /// Report when Get-Command fails to find something. /// </summary> internal static void ReportGetCommandFailed(string[] name, long timeInMS) { TelemetryWrapper.TraceMessage("PSGetCommandFailed", new { TimeInMS = timeInMS, CommandNames = name }); }
/// <summary> /// Public API to expose Telemetry in PowerShell /// Provide meaningful message. Ex: PSCONSOLE_START, PSRUNSPACE_START /// arguments are of anonymous type. Ex: new { PSVersion = "5.0", PSRemotingProtocolVersion = "2.2"} /// </summary> public static void TraceMessage <T>(string message, T arguments) { TelemetryWrapper.TraceMessage(message, arguments); }
/// <summary> /// Report some telemetry about the scripts that are run /// </summary> internal static void ReportScriptTelemetry(Ast ast, bool dotSourced, long compileTimeInMS) { if (ast.Parent != null || !TelemetryWrapper.IsEnabled) { return; } Task.Run(() => { var extent = ast.Extent; var text = extent.Text; var hash = text.GetHashCode(); // Ignore 'prompt' so we don't generate an event for every 'prompt' that is invoked. // (We really should only create 'prompt' once, but we don't. if (hash == s_promptHashCode) { return; } var visitor = new ScriptBlockTelemetry(); ast.Visit(visitor); var scriptFileType = ScriptFileType.None; var fileName = extent.File; if (fileName != null) { var ext = System.IO.Path.GetExtension(fileName); if (".ps1".Equals(ext, StringComparison.OrdinalIgnoreCase)) { scriptFileType = ScriptFileType.Ps1; } else if (".psd1".Equals(ext, StringComparison.OrdinalIgnoreCase)) { scriptFileType = ScriptFileType.Psd1; } else if (".psm1".Equals(ext, StringComparison.OrdinalIgnoreCase)) { scriptFileType = ScriptFileType.Psm1; } else { // Reachable? scriptFileType = ScriptFileType.Other; } } TelemetryWrapper.TraceMessage("PSScriptDetails", new { Hash = hash, IsDotSourced = dotSourced, ScriptFileType = scriptFileType, Length = text.Length, LineCount = extent.EndLineNumber - extent.StartLineNumber, CompileTimeInMS = compileTimeInMS, StatementCount = visitor.StatementCount, CountOfCommands = visitor.CountOfCommands, CountOfDotSourcedCommands = visitor.CountOfDotSourcedCommands, MaxArrayLength = visitor.MaxArraySize, ArrayLiteralCount = visitor.ArrayLiteralCount, ArrayLiteralCumulativeSize = visitor.ArrayLiteralCumulativeSize, MaxStringLength = visitor.MaxStringSize, StringLiteralCount = visitor.StringLiteralCount, StringLiteralCumulativeSize = visitor.StringLiteralCumulativeSize, MaxPipelineDepth = visitor.MaxPipelineDepth, PipelineCount = visitor.PipelineCount, FunctionCount = visitor.FunctionCount, ScriptBlockCount = visitor.ScriptBlockCount, ClassCount = visitor.ClassCount, EnumCount = visitor.EnumCount, CommandsCalled = visitor.CommandsCalled, }); }); }