Skip to content

Commit 22ad5e5

Browse files
authored
telemetry(chat): try catch for telemetry to not break tool execution (aws#7085)
## Problem - `error: TypeError: Cannot read properties of undefined (reading 'emit') ` - telemetry can throw an error and break tool execution ## Solution - use `run` instead of emit - add try catch --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 5a0404e commit 22ad5e5

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

packages/core/src/codewhispererChat/controllers/chat/telemetryHelper.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,27 +218,39 @@ export class CWCTelemetryHelper {
218218
}
219219

220220
public recordToolUseSuggested(toolUse: ToolUse, messageId: string) {
221-
telemetry.amazonq_toolUseSuggested.emit({
222-
result: 'Succeeded',
223-
cwsprChatConversationId: messageId,
224-
cwsprChatConversationType: 'AgenticChatWithToolUse',
225-
credentialStartUrl: AuthUtil.instance.startUrl,
226-
cwsprToolName: toolUse.name ?? '',
227-
cwsprToolUseId: toolUse.toolUseId ?? '',
228-
})
221+
try {
222+
telemetry.amazonq_toolUseSuggested.run((span) => {
223+
span.record({
224+
result: 'Succeeded',
225+
cwsprChatConversationId: messageId,
226+
cwsprChatConversationType: 'AgenticChatWithToolUse',
227+
credentialStartUrl: AuthUtil.instance.startUrl,
228+
cwsprToolName: toolUse.name ?? '',
229+
cwsprToolUseId: toolUse.toolUseId ?? '',
230+
})
231+
})
232+
} catch (e: any) {
233+
getLogger().error('Unable to record amazonq_toolUseSuggested telemetry')
234+
}
229235
}
230236

231237
public recordInteractionWithAgenticChat(
232238
interactionType: AgenticChatInteractionType,
233239
message: AcceptResponseMessage | CustomFormActionMessage | StopResponseMessage
234240
) {
235-
telemetry.amazonq_interactWithAgenticChat.emit({
236-
cwsprAgenticChatInteractionType: interactionType,
237-
result: 'Succeeded',
238-
cwsprChatConversationId: this.getConversationId(message.tabID ?? '') ?? '',
239-
cwsprChatConversationType: 'AgenticChat',
240-
credentialStartUrl: AuthUtil.instance.startUrl,
241-
})
241+
try {
242+
telemetry.amazonq_interactWithAgenticChat.run((span) => {
243+
span.record({
244+
cwsprAgenticChatInteractionType: interactionType,
245+
result: 'Succeeded',
246+
cwsprChatConversationId: this.getConversationId(message.tabID ?? '') ?? '',
247+
cwsprChatConversationType: 'AgenticChat',
248+
credentialStartUrl: AuthUtil.instance.startUrl,
249+
})
250+
})
251+
} catch (e: any) {
252+
getLogger().error('Unable to record amazonq_interactWithAgenticChat telemetry')
253+
}
242254
}
243255

244256
public recordInteractWithMessage(

0 commit comments

Comments
 (0)