Skip to content

Commit b6a164f

Browse files
committed
fix: metric to show tool distribution
1 parent 84bccc6 commit b6a164f

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ export class AgenticChatController implements ChatHandlers {
641641
})
642642
break
643643
}
644+
645+
if (toolUse.name) {
646+
this.#telemetryController.emitToolUseSuggested(toolUse, session.conversationId || '')
647+
}
644648
} catch (err) {
645649
// If we did not approve a tool to be used or the user stopped the response, bubble this up to interrupt agentic loop
646650
if (CancellationError.isUserCancelled(err) || err instanceof ToolApprovalException) {

server/aws-lsp-codewhisperer/src/language-server/chat/telemetry/chatTelemetryController.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
RelevancyVoteType,
1515
isClientTelemetryEvent,
1616
} from './clientTelemetry'
17-
import { UserIntent } from '@amzn/codewhisperer-streaming'
17+
import { ToolUse, UserIntent } from '@amzn/codewhisperer-streaming'
1818
import { TriggerContext } from '../contexts/triggerContext'
1919

2020
import { CredentialsProvider, Logging } from '@aws/language-server-runtimes/server-interface'
@@ -166,6 +166,19 @@ export class ChatTelemetryController {
166166
}
167167
}
168168

169+
public emitToolUseSuggested(toolUse: ToolUse, conversationId: string) {
170+
this.#telemetry.emitMetric({
171+
name: ChatTelemetryEventName.ToolUseSuggested,
172+
data: {
173+
[CONVERSATION_ID_METRIC_KEY]: conversationId,
174+
cwsprChatConversationType: 'AgenticChatWithToolUse',
175+
credentialStartUrl: this.#credentialsProvider.getConnectionMetadata()?.sso?.startUrl,
176+
cwsprToolName: toolUse.name ?? '',
177+
cwsprToolUseId: toolUse.toolUseId ?? '',
178+
},
179+
})
180+
}
181+
169182
public emitAddMessageMetric(tabId: string, metric: Partial<CombinedConversationEvent>) {
170183
const conversationId = this.getConversationId(tabId)
171184
// Store the customization value associated with the message

server/aws-lsp-codewhisperer/src/shared/telemetry/types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export enum ChatTelemetryEventName {
165165
RunCommand = 'amazonq_runCommand',
166166
MessageResponseError = 'amazonq_messageResponseError',
167167
ModifyCode = 'amazonq_modifyCode',
168+
ToolUseSuggested = 'amazonq_toolUseSuggested',
168169
}
169170

170171
export interface ChatTelemetryEventMap {
@@ -178,6 +179,15 @@ export interface ChatTelemetryEventMap {
178179
[ChatTelemetryEventName.RunCommand]: RunCommandEvent
179180
[ChatTelemetryEventName.MessageResponseError]: MessageResponseErrorEvent
180181
[ChatTelemetryEventName.ModifyCode]: ModifyCodeEvent
182+
[ChatTelemetryEventName.ToolUseSuggested]: ToolUseSuggestedEvent
183+
}
184+
185+
export type ToolUseSuggestedEvent = {
186+
credentialStartUrl?: string
187+
cwsprChatConversationId: string
188+
cwsprChatConversationType: ChatConversationType
189+
cwsprToolName: string
190+
cwsprToolUseId: string
181191
}
182192

183193
export type ModifyCodeEvent = {
@@ -242,7 +252,7 @@ export enum ChatInteractionType {
242252
ClickBodyLink = 'clickBodyLink',
243253
}
244254

245-
export type ChatConversationType = 'Chat' | 'Assign' | 'Transform' | 'AgenticChat'
255+
export type ChatConversationType = 'Chat' | 'Assign' | 'Transform' | 'AgenticChat' | 'AgenticChatWithToolUse'
246256

247257
export type InteractWithMessageEvent = {
248258
credentialStartUrl?: string

0 commit comments

Comments
 (0)