update CmdPal_ExtensionInvoked based on Jiris recommendation, but instead of prioritizing id over name, gonna keep both so its easier to read for reporting

This commit is contained in:
chatasweetie
2025-12-01 11:02:18 -08:00
parent 26103fa0c7
commit 5cf5618efa
4 changed files with 19 additions and 10 deletions

View File

@@ -8,4 +8,4 @@ namespace Microsoft.CmdPal.Core.ViewModels.Messages;
/// Message sent when an extension command or page is invoked. /// Message sent when an extension command or page is invoked.
/// Captures extension usage metrics for telemetry tracking. /// Captures extension usage metrics for telemetry tracking.
/// </summary> /// </summary>
public record ExtensionInvokedMessage(string ExtensionId, string CommandType, bool Success, ulong ExecutionTimeMs); public record ExtensionInvokedMessage(string ExtensionId, string CommandId, string CommandName, bool Success, ulong ExecutionTimeMs);

View File

@@ -273,9 +273,10 @@ public partial class ShellViewModel : ObservableObject,
if (host is not null) if (host is not null)
{ {
string extensionId = host.GetExtensionDisplayName() ?? "builtin"; string extensionId = host.GetExtensionDisplayName() ?? "builtin";
string commandType = command?.Name ?? command?.Id ?? "unknown"; string commandId = command?.Id ?? "unknown";
string commandName = command?.Name ?? "unknown";
WeakReferenceMessenger.Default.Send<ExtensionInvokedMessage>( WeakReferenceMessenger.Default.Send<ExtensionInvokedMessage>(
new(extensionId, commandType, true, 0)); new(extensionId, commandId, commandName, true, 0));
} }
// Construct our ViewModel of the appropriate type and pass it the UI Thread context. // Construct our ViewModel of the appropriate type and pass it the UI Thread context.
@@ -351,7 +352,8 @@ public partial class ShellViewModel : ObservableObject,
var stopwatch = System.Diagnostics.Stopwatch.StartNew(); var stopwatch = System.Diagnostics.Stopwatch.StartNew();
var command = message.Command.Unsafe; var command = message.Command.Unsafe;
string extensionId = host?.GetExtensionDisplayName() ?? "builtin"; string extensionId = host?.GetExtensionDisplayName() ?? "builtin";
string commandType = command?.Name ?? command?.Id ?? "unknown"; string commandId = command?.Id ?? "unknown";
string commandName = command?.Name ?? "unknown";
bool success = false; bool success = false;
try try
@@ -384,7 +386,7 @@ public partial class ShellViewModel : ObservableObject,
// Telemetry: Send extension invocation metrics (always sent, even on failure) // Telemetry: Send extension invocation metrics (always sent, even on failure)
stopwatch.Stop(); stopwatch.Stop();
WeakReferenceMessenger.Default.Send<ExtensionInvokedMessage>( WeakReferenceMessenger.Default.Send<ExtensionInvokedMessage>(
new(extensionId, commandType, success, (ulong)stopwatch.ElapsedMilliseconds)); new(extensionId, commandId, commandName, success, (ulong)stopwatch.ElapsedMilliseconds));
} }
} }

View File

@@ -23,9 +23,14 @@ public class CmdPalExtensionInvoked : EventBase, IEvent
public string ExtensionId { get; set; } public string ExtensionId { get; set; }
/// <summary> /// <summary>
/// Gets or sets the display name of the command being invoked. /// Gets or sets the non-localized identifier of the command being invoked.
/// </summary> /// </summary>
public string CommandType { get; set; } public string CommandId { get; set; }
/// <summary>
/// Gets or sets the localized display name of the command being invoked.
/// </summary>
public string CommandName { get; set; }
/// <summary> /// <summary>
/// Gets or sets whether the command executed successfully. /// Gets or sets whether the command executed successfully.
@@ -37,11 +42,12 @@ public class CmdPalExtensionInvoked : EventBase, IEvent
/// </summary> /// </summary>
public ulong ExecutionTimeMs { get; set; } public ulong ExecutionTimeMs { get; set; }
public CmdPalExtensionInvoked(string extensionId, string commandType, bool success, ulong executionTimeMs) public CmdPalExtensionInvoked(string extensionId, string commandId, string commandName, bool success, ulong executionTimeMs)
{ {
EventName = "CmdPal_ExtensionInvoked"; EventName = "CmdPal_ExtensionInvoked";
ExtensionId = extensionId; ExtensionId = extensionId;
CommandType = commandType; CommandId = commandId;
CommandName = commandName;
Success = success; Success = success;
ExecutionTimeMs = executionTimeMs; ExecutionTimeMs = executionTimeMs;
} }

View File

@@ -48,7 +48,8 @@ internal sealed class TelemetryForwarder :
{ {
PowerToysTelemetry.Log.WriteEvent(new CmdPalExtensionInvoked( PowerToysTelemetry.Log.WriteEvent(new CmdPalExtensionInvoked(
message.ExtensionId, message.ExtensionId,
message.CommandType, message.CommandId,
message.CommandName,
message.Success, message.Success,
message.ExecutionTimeMs)); message.ExecutionTimeMs));
} }