

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 Amazon CloudWatch 日志识别特定用户的操作
<a name="monitoring-telemetry"></a>

您可以获取有关您的 Amazon Q 开发者版使用情况的用户级指标。要弄清楚哪个用户采取了特定的操作，请查找调用的事件 SendTelemetryEvent，然后检查其中包含的类型 SendTelemetryEventRequest 为 JSON 对象。在该对象中，架构如下所示。

**提示**  
还可以将各个用户在 Amazon Q 开发者版中的活动输出到采用 CSV 格式的报告中。有关更多信息，请参阅 [在 Amazon Q 开发者版中查看特定用户的活动](q-admin-user-telemetry.md)。

```
http://json-schema.org/draft-07/schema#",
    "definitions": {
        "ProgrammingLanguage": {
            "type": "object",
            "properties": {
                "languageName": {
                    "type": "string",
                    "enum": [
                        "python",
                        "javascript",
                        "java",
                        "csharp",
                        "typescript",
                        "c",
                        "cpp",
                        "go",
                        "kotlin",
                        "php",
                        "ruby",
                        "rust",
                        "scala",
                        "shell",
                        "sql",
                        "json",
                        "yaml",
                        "vue",
                        "tf",
                        "tsx",
                        "jsx",
                        "plaintext"
                    ],
                    "description": "Programming Languages supported by Q"
                }
            }
        },
        "Dimension": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string",
                    "description": "must match ^[-a-zA-Z0-9._]*$ and be between 1 and 255 characters"
                },
                "value": {
                    "type": "string",
                    "description": "must match ^[-a-zA-Z0-9._]*$ and be between 1 and 1024 characters"
                }
            }
        }
    },
    "telemetryEvents": {
        "UserTriggerDecisionEvent": {
            "type": "object",
            "properties": {
                "sessionId": {
                    "type": "string",
                    "description": "UUID for the session"
                },
                "requestId": {
                    "type": "string",
                    "description": "UUID for the request"
                },
                "customizationArn": {
                    "type": "string",
                    "description": "ARN of the customization matching pattern: ^arn:[-.a-z0-9]{1,63}:codewhisperer:([-.a-z0-9]{0,63}:){2}([a-zA-Z0-9-_:/]){1,1023}$"
                },
                "programmingLanguage": {
                    "$ref": "#/definitions/ProgrammingLanguage"
                },
                "completionType": {
                    "type": "string",
                    "enum": [
                        "BLOCK",
                        "LINE"
                    ]
                },
                "suggestionState": {
                    "type": "string",
                    "enum": [
                        "ACCEPT",
                        "REJECT",
                        "DISCARD",
                        "EMPTY"
                    ]
                },
                "recommendationLatencyMilliseconds": {
                    "type": "number"
                },
                "timestamp": {
                    "type": "string",
                    "description": "datetime, example: Jul 23, 2024, 12:11:02 AM"
                },
                "triggerToResponseLatencyMilliseconds": {
                    "type": "number"
                },
                "suggestionReferenceCount": {
                    "type": "integer"
                },
                "generatedLine": {
                    "type": "integer"
                },
                "numberOfRecommendations": {
                    "type": "integer"
                }
            },
            "required": [
                "sessionId",
                "requestId",
                "programmingLanguage",
                "completionType",
                "suggestionState",
                "recommendationLatencyMilliseconds",
                "timestamp"
            ]
        },
        "CodeCoverageEvent": {
            "type": "object",
            "properties": {
                "customizationArn": {
                    "type": "string",
                    "description": "ARN of the customization matching pattern: ^arn:[-.a-z0-9]{1,63}:codewhisperer:([-.a-z0-9]{0,63}:){2}([a-zA-Z0-9-_:/]){1,1023}$"
                },
                "programmingLanguage": {
                    "$ref": "#/definitions/ProgrammingLanguage"
                },
                "acceptedCharacterCount": {
                    "type": "integer"
                },
                "totalCharacterCount": {
                    "type": "integer"
                },
                "timestamp": {
                    "type": "string",
                    "description": "datetime, example: Jul 23, 2024, 12:11:02 AM"
                },
                "unmodifiedAcceptedCharacterCount": {
                    "type": "integer"
                }
            },
            "required": [
                "programmingLanguage",
                "acceptedCharacterCount",
                "totalCharacterCount",
                "timestamp"
            ]
        },
        "UserModificationEvent": {
            "type": "object",
            "properties": {
                "sessionId": {
                    "type": "string",
                    "description": "UUID for the session"
                },
                "requestId": {
                    "type": "string",
                    "description": "UUID for the request"
                },
                "programmingLanguage": {
                    "$ref": "#/definitions/ProgrammingLanguage"
                },
                "modificationPercentage": {
                    "type": "number",
                    "description": "This is the percentage of AI generated code which has been modified by the user"
                },
                "customizationArn": {
                    "type": "string",
                    "description": "ARN of the customization matching pattern: ^arn:[-.a-z0-9]{1,63}:codewhisperer:([-.a-z0-9]{0,63}:){2}([a-zA-Z0-9-_:/]){1,1023}$"
                },
                "timestamp": {
                    "type": "string",
                    "description": "datetime, example: Jul 23, 2024, 12:11:02 AM"
                }
            },
            "required": [
                "sessionId",
                "requestId",
                "programmingLanguage",
                "modificationPercentage",
                "timestamp"
            ]
        },
        "CodeScanEvent": {
            "type": "object",
            "properties": {
                "programmingLanguage": {
                    "$ref": "#/definitions/ProgrammingLanguage"
                },
                "codeScanJobId": {
                    "type": "string"
                },
                "timestamp": {
                    "type": "string",
                    "description": "datetime, example: Jul 23, 2024, 12:11:02 AM"
                },
                "codeAnalysisScope": {
                    "type": "string",
                    "enum": [
                        "FILE",
                        "PROJECT"
                    ]
                }
            },
            "required": [
                "programmingLanguage",
                "codeScanJobId",
                "timestamp"
            ]
        },
        "CodeScanRemediationsEvent": {
            "type": "object",
            "properties": {
                "programmingLanguage": {
                    "$ref": "#/definitions/ProgrammingLanguage"
                },
                "CodeScanRemediationsEventType": {
                    "type": "string",
                    "enum": [
                        "CODESCAN_ISSUE_HOVER",
                        "CODESCAN_ISSUE_APPLY_FIX",
                        "CODESCAN_ISSUE_VIEW_DETAILS"
                    ]
                },
                "timestamp": {
                    "type": "string",
                    "description": "datetime, example: Jul 23, 2024, 12:11:02 AM"
                },
                "detectorId": {
                    "type": "string"
                },
                "findingId": {
                    "type": "string"
                },
                "ruleId": {
                    "type": "string"
                },
                "component": {
                    "type": "string"
                },
                "reason": {
                    "type": "string"
                },
                "result": {
                    "type": "string"
                },
                "includesFix": {
                    "type": "boolean"
                }
            }
        },
        "MetricData": {
            "type": "object",
            "properties": {
                "metricName": {
                    "type": "string",
                    "description": "must match pattern ^[-a-zA-Z0-9._]*$ and be between 1 and 1024 characters"
                },
                "metricValue": {
                    "type": "number"
                },
                "timestamp": {
                    "type": "string",
                    "description": "datetime, example: Jul 23, 2024, 12:11:02 AM"
                },
                "product": {
                    "type": "string",
                    "description": "must match pattern ^[-a-zA-Z0-9._]*$ and be between 1 and 128 characters"
                },
                "dimensions": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Dimension"
                    },
                    "description": "maximum size of 30"
                }
            },
            "required": [
                "metricName",
                "metricValue",
                "timestamp",
                "product"
            ]
        },
        "ChatAddMessageEvent": {
            "type": "object",
            "properties": {
                "conversationId": {
                    "type": "string",
                    "description": "ID which represents a multi-turn conversation, length between 1 and 128"
                },
                "messageId": {
                    "type": "string",
                    "description": "Unique identifier for the chat message"
                },
                "customizationArn": {
                    "type": "string",
                    "description": "ARN of the customization matching pattern: ^arn:[-.a-z0-9]{1,63}:codewhisperer:([-.a-z0-9]{0,63}:){2}([a-zA-Z0-9-_:/]){1,1023}$"
                },
                "userIntent": {
                    "type": "string",
                    "enum": [
                        "SUGGEST_ALTERNATE_IMPLEMENTATION",
                        "APPLY_COMMON_BEST_PRACTICES",
                        "IMPROVE_CODE",
                        "SHOW_EXAMPLES",
                        "CITE_SOURCES",
                        "EXPLAIN_LINE_BY_LINE",
                        "EXPLAIN_CODE_SELECTION",
                        "GENERATE_CLOUDFORMATION_TEMPLATE"
                    ]
                },
                "hasCodeSnippet": {
                    "type": "boolean"
                },
                "programmingLanguage": {
                    "$ref": "#/definitions/ProgrammingLanguage"
                },
                "activeEditorTotalCharacters": {
                    "type": "integer"
                },
                "timeToFirstChunkMilliseconds": {
                    "type": "number"
                },
                "timeBetweenChunks": {
                    "type": "array",
                    "items": {
                        "type": "number"
                    },
                    "description": "maximum size of 100"
                },
                "fullResponselatency": {
                    "type": "number"
                },
                "requestLength": {
                    "type": "integer"
                },
                "responseLength": {
                    "type": "integer"
                },
                "numberOfCodeBlocks": {
                    "type": "integer"
                },
                "hasProjectLevelContext": {
                    "type": "boolean"
                }
            },
            "required": [
                "conversationId",
                "messageId"
            ]
        },
        "ChatInteractWithMessageEvent": {
            "type": "object",
            "properties": {
                "conversationId": {
                    "type": "string",
                    "description": "ID which represents a multi-turn conversation, length between 1 and 128"
                },
                "messageId": {
                    "type": "string",
                    "description": "Unique identifier for the chat message"
                },
                "customizationArn": {
                    "type": "string",
                    "description": "ARN of the customization matching pattern: ^arn:[-.a-z0-9]{1,63}:codewhisperer:([-.a-z0-9]{0,63}:){2}([a-zA-Z0-9-_:/]){1,1023}$"
                },
                "interactionType": {
                    "type": "string",
                    "enum": [
                        "INSERT_AT_CURSOR",
                        "COPY_SNIPPET",
                        "COPY",
                        "CLICK_LINK",
                        "CLICK_BODY_LINK",
                        "CLICK_FOLLOW_UP",
                        "HOVER_REFERENCE",
                        "UPVOTE",
                        "DOWNVOTE"
                    ],
                    "description": "Chat Message Interaction Type"
                },
                "interactionTarget": {
                    "type": "string",
                    "description": "Target of message interaction"
                },
                "acceptedCharacterCount": {
                    "type": "integer"
                },
                "acceptedLineCount": {
                    "type": "integer"
                },
                "acceptedSnippetHasReference": {
                    "type": "boolean"
                },
                "hasProjectLevelContext": {
                    "type": "boolean"
                }
            },
            "required": [
                "conversationId",
                "messageId"
            ]
        },
        "ChatUserModificationEvent": {
            "type": "object",
            "properties": {
                "conversationId": {
                    "type": "string",
                    "description": "ID which represents a multi-turn conversation, length between 1 and 128"
                },
                "customizationArn": {
                    "type": "string",
                    "description": "ARN of the customization matching pattern: ^arn:[-.a-z0-9]{1,63}:codewhisperer:([-.a-z0-9]{0,63}:){2}([a-zA-Z0-9-_:/]){1,1023}$"
                },
                "messageId": {
                    "type": "string",
                    "description": "Unique identifier for the chat message"
                },
                "programmingLanguage": {
                    "$ref": "#/definitions/ProgrammingLanguage"
                },
                "modificationPercentage": {
                    "type": "number",
                    "description": "This is the percentage of AI generated code which has been modified by the user"
                },
                "hasProjectLevelContext": {
                    "type": "boolean"
                }
            },
            "required": [
                "conversationId",
                "messageId",
                "modificationPercentage"
            ]
        },
        "SuggestionState": {
            "type": "string",
            "enum": [
                "ACCEPT",
                "REJECT",
                "DISCARD",
                "EMPTY"
            ]
        },
        "TerminalUserInteractionEvent": {
            "type": "object",
            "properties": {
                "terminalUserInteractionEventType": {
                    "type": "string",
                    "enum": [
                        "CODEWHISPERER_TERMINAL_TRANSLATION_ACTION",
                        "CODEWHISPERER_TERMINAL_COMPLETION_INSERTED"
                    ],
                    "description": "Terminal User Interaction Event Type"
                },
                "terminal": {
                    "type": "string"
                },
                "terminalVersion": {
                    "type": "string"
                },
                "shell": {
                    "type": "string"
                },
                "shellVersion": {
                    "type": "string"
                },
                "duration": {
                    "type": "integer"
                },
                "timeToSuggestion": {
                    "type": "integer"
                },
                "isCompletionAccepted": {
                    "type": "boolean"
                },
                "cliToolCommand": {
                    "type": "string"
                }
            }
        },
        "FeatureDevEvent": {
            "type": "object",
            "properties": {
                "conversationId": {
                    "type": "string",
                    "description": "ID which represents a multi-turn conversation, length between 1 and 128"
                }
            },
            "required": [
                "conversationId"
            ]
        }
    },
    "SendTelemetryEventRequest": {
        "type": "object",
        "properties": {
            "clientToken": {
                "type": "string",
                "description": "The client's authentication token"
            },
            "telemetryEvent": {
                "properties": {
                    "oneOf": [
                        {
                            "_comment": "This event is emitted when a user accepts or rejects an inline code suggestion",
                            "$ref": "#/definitions/userTriggerDecisionEvent"
                        },
                        {
                            "_comment": "This event is emitted every five minutes. It details how much code is written by inline code suggestion and in total during that period",
                            "$ref": "#/definitions/codeCoverageEvent"
                        },
                        {
                            "_comment": "This event is emitted when a code snippet from inline code suggestion has been edited by a user. It details the percentage of that code snippet modified by the user",
                            "$ref": "#/definitions/userModificationEvent"
                        },
                        {
                            "_comment": "This field is emitted when a security scan is requested by a user",
                            "$ref": "#/definitions/codeScanEvent"
                        },
                        {
                            "_comment": "This field is emitted when a security scan recommended remediation is accepted by a user",
                            "$ref": "#/definitions/codeScanRemediationsEvent"
                        },
                        {
                            "_comment": "This event is deprecated but may still occur in telemetry. Do not use this.",
                            "$ref": "#/definitions/metricData"
                        },
                        {
                            "_comment": "This event is emitted when Q adds an AI generated message to the chat window",
                            "$ref": "#/definitions/chatAddMessageEvent"
                        },
                        {
                            "_comment": "This event is emitted when a user interacts with a chat message",
                            "$ref": "#/definitions/chatInteractWithMessageEvent"
                        },
                        {
                            "_comment": "This event is emitted when a user modifies a code snippet sourced from chat. It gives a percentage of the code snippet which has been modified",
                            "$ref": "#/definitions/chatUserModificationEvent"
                        },
                        {
                            "_comment": "This event is emitted when a user interacts with a terminal suggestion",
                            "$ref": "#/definitions/terminalUserInteractionEvent"
                        },
                        {
                            "_comment": "This event is emitted when a user first prompts the /dev feature.",
                            "$ref": "#/definitions/featureDevEvent"
                        }
                    ]
                }
            },
            "optOutPreference": {
                "type": "string",
                "enum": [
                    "OPTIN",
                    "OPTOUT"
                ],
                "description": "OPTOUT and telemetry is only provided to the account of purchasing enterprise, OPTIN and telemetry may also be used for product improvement"
            },
            "userContext": {
                "type": "object",
                "properties": {
                    "ideCategory": {
                        "type": "string",
                        "enum": [
                            "JETBRAINS",
                            "VSCODE",
                            "CLI",
                            "JUPYTER_MD",
                            "JUPYTER_SM"
                        ]
                    },
                    "operatingSystem": {
                        "type": "string",
                        "description": "The operating system being used"
                    },
                    "product": {
                        "type": "string",
                        "description": "The name of the product being used"
                    },
                    "clientId": {
                        "type": "string",
                        "description": "A UUID representing the individual client being used"
                    },
                    "ideVersion": {
                        "type": "string",
                        "description": "The version of the Q plugin"
                    }
                },
                "required": [
                    "ideCategory",
                    "operatingSystem",
                    "product",
                    "clientId",
                    "ideVersion"
                ]
            },
            "profileArn": {
                "type": "string",
                "description": "The arn of the Q Profile used to configure individual user accounts."
```

请注意，a SendTelemetryEvent 可能包含许多遥测事件之一。其中每一个都描述了开发环境之间的特定交互。

每个事件的更详细描述如下所示。

## UserTriggerDecisionEvent
<a name="monitoring-telemetry-user-trigger"></a>

当用户与 Amazon Q 提出的建议进行交互时会触发此事件。它记录了该建议是被接受、拒绝还是修改以及相关的元数据。
+ `completionType`：补全的是代码块还是代码行。
+ `suggestionState`：用户是接受、拒绝还是放弃建议。

## CodeScanEvent
<a name="monitoring-telemetry-code-scan"></a>

执行代码扫描时会记录此事件。它有助于跟踪扫描的范围和结果，提供对安全和代码质量检查的洞察。
+ `codeScanJobId`：代码扫描作业的唯一标识符。
+ `codeAnalysisScope`：扫描是在文件级别还是在项目级别执行的。
+ `programmingLanguage`：正在扫描的语言。

## CodeScanRemediationsEvent
<a name="monitoring-telemetry-remediations"></a>

此事件捕获用户与 Amazon Q 的补救建议的交互，例如应用修复或查看问题详情。
+ `CodeScanRemediationsEventType`：所采取的补救措施的类型（例如，查看详细信息或应用修复）。
+ `includesFix`：指示代码问题是否包含建议修复的布尔值。

## ChatAddMessageEvent
<a name="monitoring-telemetry-add-message"></a>

当向正在进行的聊天对话中添加新消息时，会触发此事件。它可以捕获用户的意图和所涉及的任何代码片段。
+ `conversationId`：对话的唯一标识符。
+ `messageId`：聊天消息的唯一标识符。
+ `userIntent`：用户的意图，例如改进代码或解释代码。
+ `programmingLanguage`：与聊天消息相关的语言。

## ChatInteractWithMessageEvent
<a name="monitoring-telemetry-interact-message"></a>

此事件捕获用户何时与聊天消息进行交互，例如复制代码片段、点击链接或将鼠标悬停在引用内容上。
+ `interactionType`：交互类型（例如，复制、悬停、点击）。
+ `interactionTarget`：交互的对象（例如，代码片段或链接）。
+ `acceptedCharacterCount`：已接受消息中的字符数。
+ `acceptedSnippetHasReference`：表明接受的片段是否包含引用的布尔值。

## TerminalUserInteractionEvent
<a name="monitoring-telemetry-interact-event"></a>

此事件记录用户在终端环境中与终端命令的交互或补全内容。
+ `terminalUserInteractionEventType`：交互类型（例如，终端翻译或代码补全）。
+ `isCompletionAccepted`：表明用户是否接受补全的布尔值。
+ `duration`：交互所用的时间。