diff --git a/server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts b/server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts index 56a1cbe0a2..43ffa4a4e2 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts @@ -641,6 +641,10 @@ export class AgenticChatController implements ChatHandlers { }) break } + + if (toolUse.name) { + this.#telemetryController.emitToolUseSuggested(toolUse, session.conversationId || '') + } } catch (err) { // If we did not approve a tool to be used or the user stopped the response, bubble this up to interrupt agentic loop if (CancellationError.isUserCancelled(err) || err instanceof ToolApprovalException) { diff --git a/server/aws-lsp-codewhisperer/src/language-server/chat/telemetry/chatTelemetryController.ts b/server/aws-lsp-codewhisperer/src/language-server/chat/telemetry/chatTelemetryController.ts index a617f2721b..e0c4643bda 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/chat/telemetry/chatTelemetryController.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/chat/telemetry/chatTelemetryController.ts @@ -14,7 +14,7 @@ import { RelevancyVoteType, isClientTelemetryEvent, } from './clientTelemetry' -import { UserIntent } from '@amzn/codewhisperer-streaming' +import { ToolUse, UserIntent } from '@amzn/codewhisperer-streaming' import { TriggerContext } from '../contexts/triggerContext' import { CredentialsProvider, Logging } from '@aws/language-server-runtimes/server-interface' @@ -166,6 +166,19 @@ export class ChatTelemetryController { } } + public emitToolUseSuggested(toolUse: ToolUse, conversationId: string) { + this.#telemetry.emitMetric({ + name: ChatTelemetryEventName.ToolUseSuggested, + data: { + [CONVERSATION_ID_METRIC_KEY]: conversationId, + cwsprChatConversationType: 'AgenticChatWithToolUse', + credentialStartUrl: this.#credentialsProvider.getConnectionMetadata()?.sso?.startUrl, + cwsprToolName: toolUse.name ?? '', + cwsprToolUseId: toolUse.toolUseId ?? '', + }, + }) + } + public emitAddMessageMetric(tabId: string, metric: Partial) { const conversationId = this.getConversationId(tabId) // Store the customization value associated with the message diff --git a/server/aws-lsp-codewhisperer/src/shared/telemetry/types.ts b/server/aws-lsp-codewhisperer/src/shared/telemetry/types.ts index a51ce6c65e..ca6d94141e 100644 --- a/server/aws-lsp-codewhisperer/src/shared/telemetry/types.ts +++ b/server/aws-lsp-codewhisperer/src/shared/telemetry/types.ts @@ -165,6 +165,7 @@ export enum ChatTelemetryEventName { RunCommand = 'amazonq_runCommand', MessageResponseError = 'amazonq_messageResponseError', ModifyCode = 'amazonq_modifyCode', + ToolUseSuggested = 'amazonq_toolUseSuggested', } export interface ChatTelemetryEventMap { @@ -178,6 +179,15 @@ export interface ChatTelemetryEventMap { [ChatTelemetryEventName.RunCommand]: RunCommandEvent [ChatTelemetryEventName.MessageResponseError]: MessageResponseErrorEvent [ChatTelemetryEventName.ModifyCode]: ModifyCodeEvent + [ChatTelemetryEventName.ToolUseSuggested]: ToolUseSuggestedEvent +} + +export type ToolUseSuggestedEvent = { + credentialStartUrl?: string + cwsprChatConversationId: string + cwsprChatConversationType: ChatConversationType + cwsprToolName: string + cwsprToolUseId: string } export type ModifyCodeEvent = { @@ -242,7 +252,7 @@ export enum ChatInteractionType { ClickBodyLink = 'clickBodyLink', } -export type ChatConversationType = 'Chat' | 'Assign' | 'Transform' | 'AgenticChat' +export type ChatConversationType = 'Chat' | 'Assign' | 'Transform' | 'AgenticChat' | 'AgenticChatWithToolUse' export type InteractWithMessageEvent = { credentialStartUrl?: string