Skip to content

Commit 75bdeff

Browse files
authored
Update telemetry to include conversation id and query id only when user agrees to send history (#262)
1 parent 2bf4d4c commit 75bdeff

File tree

3 files changed

+53
-20
lines changed

3 files changed

+53
-20
lines changed

shell/agents/Microsoft.Azure.Agent/AzureAgent.cs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,40 @@ public void Initialize(AgentConfig config)
121121

122122
public IEnumerable<CommandBase> GetCommands() => [new ReplaceCommand(this)];
123123
public bool CanAcceptFeedback(UserAction action) => Telemetry.Enabled;
124-
public void OnUserAction(UserActionPayload actionPayload) {
124+
125+
public void OnUserAction(UserActionPayload actionPayload)
126+
{
125127
// Send telemetry about the user action.
126128
bool isUserFeedback = false;
129+
bool shareConversation = false;
127130
string details = null;
128-
UserAction action = actionPayload.Action;
131+
string action = actionPayload.Action.ToString();
129132

130-
if (action is UserAction.Dislike)
133+
switch (actionPayload)
131134
{
132-
var dislike = (DislikePayload) actionPayload;
133-
isUserFeedback = true;
134-
details = string.Format("{0} | {1}", dislike.ShortFeedback, dislike.LongFeedback);
135+
case DislikePayload dislike:
136+
isUserFeedback = true;
137+
shareConversation = dislike.ShareConversation;
138+
details = string.Format("{0} | {1}", dislike.ShortFeedback, dislike.LongFeedback);
139+
break;
140+
141+
case LikePayload like:
142+
isUserFeedback = true;
143+
shareConversation = like.ShareConversation;
144+
break;
145+
146+
default:
147+
break;
135148
}
136-
else if (action is UserAction.Like)
149+
150+
if (isUserFeedback)
137151
{
138-
isUserFeedback = true;
152+
Telemetry.Trace(AzTrace.Feedback(action, shareConversation, _copilotResponse, details));
153+
}
154+
else
155+
{
156+
Telemetry.Trace(AzTrace.UserAction(action, _copilotResponse, details));
139157
}
140-
141-
Telemetry.Trace(AzTrace.UserAction(action.ToString(), _copilotResponse, details, isUserFeedback));
142158
}
143159

144160
public async Task RefreshChatAsync(IShell shell, bool force)
@@ -412,7 +428,7 @@ private ResponseData ParseCLIHandlerResponse(IShell shell)
412428
{
413429
// The placeholder section is not in the format as we've instructed ...
414430
Log.Error("Placeholder section not in expected format:\n{0}", text);
415-
Telemetry.Trace(AzTrace.Exception(_copilotResponse, "Placeholder section not in expected format."));
431+
Telemetry.Trace(AzTrace.Exception("Placeholder section not in expected format."));
416432
}
417433

418434
ReplaceKnownPlaceholders(data);

shell/agents/Microsoft.Azure.Agent/ChatSession.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ internal class ChatSession : IDisposable
1414
// TODO: production URL not yet working for some regions.
1515
// private const string ACCESS_URL = "https://copilotweb.production.portalrp.azure.com/api/access?api-version=2024-09-01";
1616
private const string ACCESS_URL = "https://copilotweb.canary.production.portalrp.azure.com/api/access?api-version=2024-09-01";
17-
1817
private const string DL_TOKEN_URL = "https://copilotweb.production.portalrp.azure.com/api/conversations/start?api-version=2024-11-15";
1918
private const string CONVERSATION_URL = "https://directline.botframework.com/v3/directline/conversations";
2019

shell/agents/Microsoft.Azure.Agent/Telemetry.cs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,38 @@ internal static void Initialize()
8888
internal static AzTrace UserAction(
8989
string shellCommand,
9090
CopilotResponse response,
91-
object details,
92-
bool isFeedback = false)
91+
object details)
9392
{
9493
if (Telemetry.Enabled)
9594
{
9695
return new()
9796
{
98-
QueryId = response.ReplyToId,
97+
EventType = "UserAction",
98+
ShellCommand = shellCommand,
9999
TopicName = response.TopicName,
100-
ConversationId = response.ConversationId,
100+
Details = details
101+
};
102+
}
103+
104+
// Don't create an object when telemetry is disabled.
105+
return null;
106+
}
107+
108+
internal static AzTrace Feedback(
109+
string shellCommand,
110+
bool shareConversation,
111+
CopilotResponse response,
112+
object details)
113+
{
114+
if (Telemetry.Enabled)
115+
{
116+
return new()
117+
{
118+
EventType = "Feedback",
101119
ShellCommand = shellCommand,
102-
EventType = isFeedback ? "Feedback" : "UserAction",
120+
TopicName = response.TopicName,
121+
QueryId = shareConversation ? response.ReplyToId : null,
122+
ConversationId = shareConversation ? response.ConversationId : null,
103123
Details = details
104124
};
105125
}
@@ -115,9 +135,7 @@ internal static AzTrace Chat(CopilotResponse response)
115135
return new()
116136
{
117137
EventType = "Chat",
118-
QueryId = response.ReplyToId,
119-
TopicName = response.TopicName,
120-
ConversationId = response.ConversationId
138+
TopicName = response.TopicName
121139
};
122140
}
123141

0 commit comments

Comments
 (0)