diff --git a/shell/agents/Microsoft.Azure.Agent/AzureAgent.cs b/shell/agents/Microsoft.Azure.Agent/AzureAgent.cs index 4a8f3cf6..7266b393 100644 --- a/shell/agents/Microsoft.Azure.Agent/AzureAgent.cs +++ b/shell/agents/Microsoft.Azure.Agent/AzureAgent.cs @@ -121,24 +121,40 @@ public void Initialize(AgentConfig config) public IEnumerable GetCommands() => [new ReplaceCommand(this)]; public bool CanAcceptFeedback(UserAction action) => Telemetry.Enabled; - public void OnUserAction(UserActionPayload actionPayload) { + + public void OnUserAction(UserActionPayload actionPayload) + { // Send telemetry about the user action. bool isUserFeedback = false; + bool shareConversation = false; string details = null; - UserAction action = actionPayload.Action; + string action = actionPayload.Action.ToString(); - if (action is UserAction.Dislike) + switch (actionPayload) { - var dislike = (DislikePayload) actionPayload; - isUserFeedback = true; - details = string.Format("{0} | {1}", dislike.ShortFeedback, dislike.LongFeedback); + case DislikePayload dislike: + isUserFeedback = true; + shareConversation = dislike.ShareConversation; + details = string.Format("{0} | {1}", dislike.ShortFeedback, dislike.LongFeedback); + break; + + case LikePayload like: + isUserFeedback = true; + shareConversation = like.ShareConversation; + break; + + default: + break; } - else if (action is UserAction.Like) + + if (isUserFeedback) { - isUserFeedback = true; + Telemetry.Trace(AzTrace.Feedback(action, shareConversation, _copilotResponse, details)); + } + else + { + Telemetry.Trace(AzTrace.UserAction(action, _copilotResponse, details)); } - - Telemetry.Trace(AzTrace.UserAction(action.ToString(), _copilotResponse, details, isUserFeedback)); } public async Task RefreshChatAsync(IShell shell, bool force) @@ -412,7 +428,7 @@ private ResponseData ParseCLIHandlerResponse(IShell shell) { // The placeholder section is not in the format as we've instructed ... Log.Error("Placeholder section not in expected format:\n{0}", text); - Telemetry.Trace(AzTrace.Exception(_copilotResponse, "Placeholder section not in expected format.")); + Telemetry.Trace(AzTrace.Exception("Placeholder section not in expected format.")); } ReplaceKnownPlaceholders(data); diff --git a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs index d27e3015..afe88f15 100644 --- a/shell/agents/Microsoft.Azure.Agent/ChatSession.cs +++ b/shell/agents/Microsoft.Azure.Agent/ChatSession.cs @@ -14,7 +14,6 @@ internal class ChatSession : IDisposable // TODO: production URL not yet working for some regions. // private const string ACCESS_URL = "https://copilotweb.production.portalrp.azure.com/api/access?api-version=2024-09-01"; private const string ACCESS_URL = "https://copilotweb.canary.production.portalrp.azure.com/api/access?api-version=2024-09-01"; - private const string DL_TOKEN_URL = "https://copilotweb.production.portalrp.azure.com/api/conversations/start?api-version=2024-11-15"; private const string CONVERSATION_URL = "https://directline.botframework.com/v3/directline/conversations"; diff --git a/shell/agents/Microsoft.Azure.Agent/Telemetry.cs b/shell/agents/Microsoft.Azure.Agent/Telemetry.cs index 195e8919..6eb31c82 100644 --- a/shell/agents/Microsoft.Azure.Agent/Telemetry.cs +++ b/shell/agents/Microsoft.Azure.Agent/Telemetry.cs @@ -88,18 +88,38 @@ internal static void Initialize() internal static AzTrace UserAction( string shellCommand, CopilotResponse response, - object details, - bool isFeedback = false) + object details) { if (Telemetry.Enabled) { return new() { - QueryId = response.ReplyToId, + EventType = "UserAction", + ShellCommand = shellCommand, TopicName = response.TopicName, - ConversationId = response.ConversationId, + Details = details + }; + } + + // Don't create an object when telemetry is disabled. + return null; + } + + internal static AzTrace Feedback( + string shellCommand, + bool shareConversation, + CopilotResponse response, + object details) + { + if (Telemetry.Enabled) + { + return new() + { + EventType = "Feedback", ShellCommand = shellCommand, - EventType = isFeedback ? "Feedback" : "UserAction", + TopicName = response.TopicName, + QueryId = shareConversation ? response.ReplyToId : null, + ConversationId = shareConversation ? response.ConversationId : null, Details = details }; } @@ -115,9 +135,7 @@ internal static AzTrace Chat(CopilotResponse response) return new() { EventType = "Chat", - QueryId = response.ReplyToId, - TopicName = response.TopicName, - ConversationId = response.ConversationId + TopicName = response.TopicName }; }