

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 監控和追蹤 Amazon Q Developer 的使用情形
<a name="monitoring-overview"></a>

監控是維護 Amazon Q Developer 及其他 AWS 解決方案可靠性、可用性和效能的重要部分。 AWS 提供下列監控工具和功能來監控和記錄 Amazon Q Developer 活動：
+  *AWS CloudTrail* 會擷取由 發出或代表發出的 API 呼叫和相關事件， AWS 帳戶 並將日誌檔案交付至您指定的 Amazon Simple Storage Service (Amazon S3) 儲存貯體。您可以識別呼叫的使用者和帳戶 AWS、進行呼叫的來源 IP 地址，以及呼叫的時間。如需詳細資訊，請參閱[使用 記錄 Amazon Q Developer API 呼叫 AWS CloudTrail](logging-using-cloudtrail.md)。
+ *Amazon CloudWatch* AWS 會即時監控您的 AWS 資源和您在 上執行的應用程式。您可以收集和追蹤指標、建立自訂儀板表，以及設定警示，在特定指標達到您指定的閾值時通知您或採取動作。例如，您可以讓 CloudWatch 追蹤在您帳戶上調用 Amazon Q 的次數，或每天的作用中使用者數量。如需詳細資訊，請參閱[使用 Amazon CloudWatch 監控 Amazon Q Developer](monitoring-cloudwatch.md)。

Amazon Q Developer 也包含下列功能，可協助您追蹤和記錄 Amazon Q 中的使用者活動：
+  *儀表板*會顯示 Amazon Q Developer 專業方案訂閱用戶的彙總使用者活動指標。如需詳細資訊，請參閱[在儀表板上檢視 Amazon Q Developer 使用者活動](dashboard.md)。
+  *使用者活動報告*會顯示個別使用者在 Amazon Q 中做了什麼。如需詳細資訊，請參閱 [在 Amazon Q Developer 中檢視特定使用者的活動](q-admin-user-telemetry.md)。
+  *提示日誌*可提供使用者在其整合式開發環境 (IDE) 中，於 Amazon Q 聊天中輸入的所有提示的記錄。如需詳細資訊，請參閱[在 Amazon Q Developer 中記錄使用者的提示](q-admin-prompt-logging.md)。

# 使用 記錄 Amazon Q Developer API 呼叫 AWS CloudTrail
<a name="logging-using-cloudtrail"></a>

Amazon Q Developer Pro 已與 整合 AWS CloudTrail，此服務提供 Amazon Q AWS 服務 中使用者、角色或 所採取動作的記錄。CloudTrail 會將 Amazon Q 的所有 API 呼叫擷取為事件。擷取的呼叫包括來自 Amazon Q 主控台的呼叫，以及對 Amazon Q API 操作發出的程式碼呼叫。如果您建立追蹤，就可以啟用持續傳送 CloudTrail 事件至 Amazon S3 儲存貯體，包含 Amazon Q 的事件。如果您不設定追蹤，您仍然可以在**事件歷史記錄**中檢視 CloudTrail 主控台中最近發生的事件。您可以利用 CloudTrail 所收集的資訊來判斷向 Amazon Q 發出的請求，以及發出請求的 IP 地址、人員、時間和其他詳細資訊。

如需有關 CloudTrail 的相關資訊，請參閱 [AWS CloudTrail 使用者指南](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/)。

## CloudTrail 中的 Amazon Q Developer 資訊
<a name="q-developer-info-in-cloudtrail"></a>

當您建立帳戶 AWS 帳戶 時，您的 上會啟用 CloudTrail。當 Amazon Q Developer 中發生活動時，該活動會與**事件歷史記錄**中的其他 AWS 服務 事件一起記錄在 CloudTrail 事件中。您可以在 中檢視、搜尋和下載最近的事件 AWS 帳戶。如需詳細資訊，請參閱《AWS CloudTrail 使用者指南》**中的[使用 CloudTrail 事件歷史記錄檢視事件](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events.html)。

若要持續記錄 中的事件 AWS 帳戶，包括 Amazon Q 的事件，請建立追蹤。*線索*能讓 CloudTrail 將日誌檔案交付至 Amazon S3 儲存貯體。依預設，當您在主控台中建立追蹤時，該追蹤會套用至所有的 AWS 區域。線索會記錄 AWS 分割區中所有區域的事件，並將日誌檔案交付至您指定的 Amazon S3 儲存貯體。此外，您可以設定其他 AWS 服務 服務，以進一步分析和處理 CloudTrail 日誌中所收集的事件資料。如需詳細資訊，請參閱 *AWS CloudTrail 使用者指南*中的以下主題：
+  [建立追蹤的概觀](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-and-update-a-trail.html) 
+  [CloudTrail 支援的服務和整合](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-aws-service-specific-topics.html#cloudtrail-aws-service-specific-topics-integrations) 
+  [設定 CloudTrail 的 Amazon SNS 通知](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/getting_notifications_top_level.html) 
+  [從多個區域接收 CloudTrail 日誌檔案](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/receive-cloudtrail-log-files-from-multiple-regions.html) 
+  [從多個帳戶接收 CloudTrail 日誌檔案](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-receive-logs-from-multiple-accounts.html) 

所有 Amazon Q Developer 動作均會由 CloudTrail 記錄，且會在 CloudTrail 日誌檔案中產生項目。

每一筆事件或日誌專案都會包含產生請求者的資訊。身分資訊可協助您判斷下列事項：
+ 是否使用根或 AWS Identity and Access Management (IAM) 使用者登入資料提出請求
+ 提出該請求時，是否使用了特定角色或聯合身分使用者的臨時安全憑證
+ 請求是否由另一個 提出 AWS 服務

如需詳細資訊，請參閱《AWS CloudTrail 使用者指南》**中的 [CloudTrail userIdentity 元素](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-user-identity.html)。

## 了解 Amazon Q Developer 日誌檔案項目
<a name="understanding-q-developer-entries"></a>

追蹤是一種組態，能讓事件以日誌檔案的形式交付到您指定的 Amazon S3 儲存貯體。CloudTrail 日誌檔案包含一或多個日誌專案。一個事件為任何來源提出的單一請求，並包含請求動作、請求的日期和時間、請求參數等資訊。CloudTrail 日誌檔並非依公有 API 呼叫的堆疊追蹤排序，因此不會以任何特定順序出現。

Amazon Q Developer 也會使用 `dryRun` 參數進行 API 呼叫，以確認您具有執行動作的必要許可，而不需實際提出請求。使用 `dryRun` 參數的 Amazon Q Developer API 呼叫會作為事件擷取，並記錄在 CloudTrail 日誌中，且 `requestParameters` 欄位中包含 `"dryRun" : true`。

以下範例顯示的是展示 `SendMessage` 動作的 CloudTrail 日誌項目。

```
{
    "eventVersion": "1.08",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "AROAXD12ABCDEF3G4HI5J:aws-user",
        "arn": "arn:aws:sts::123456789012:assumed-role/PowerUser/aws-user",
        "accountId": "123456789012",
        "accessKeyId": "ASIAAB12CDEFG34HIJK",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "AROAXD12ABCDEF3G4HI5J",
                "arn": "arn:aws:iam::123456789012:role/PowerUser",
                "accountId": "123456789012",
                "userName": "PowerUser"
            },
            "webIdFederationData": {},
            "attributes": {
                "creationDate": "2023-11-28T10:00:00Z",
                "mfaAuthenticated": "false"
            }
        }
    },
    "eventTime": "2023-11-28T10:00:00Z",
    "eventSource": "q.amazonaws.com",
    "eventName": "SendMessage",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "123.456.789.012",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0",
    "requestParameters": {
        "Origin": "https://conversational-experience-worker.widget.console.aws.amazon.com",
        "conversationId": "a298ec0d-0a49-4d2e-92bd-7d6e629b4619",
        "source": "CONSOLE",
        "conversationToken": "***",
        "utterance": "***"
    },
    "responseElements": {
        "result": {
            "content": {
                "text": {
                    "body": "***",
                    "references": []
                }
            },
            "format": "PLAINTEXT",
            "intents": {},
            "type": "TEXT"
        },
        "Access-Control-Expose-Headers": "x-amzn-RequestId,x-amzn-ErrorType,x-amzn-ErrorMessage,Date",
        "metadata": {
            "conversationExpirationTime": "2024-02-25T19:31:38Z",
            "conversationId": "a298ec0d-0a49-4d2e-92bd-7d6e629b4619",
            "conversationToken": "***",
            "utteranceId": "3b87b46f-04a9-41ef-b8fe-8abf52d2c053"
        },
        "resultCode": "LLM"
    },
    "additionalEventData": {
        "quickAction": "dev"
    },
    "requestID": "19b3c30e-906e-4b7f-b5c3-509f67248655",
    "eventID": "a552c487-7d97-403a-8ec4-d49539c7a03d",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "123456789012",
    "eventCategory": "Management"
}
```

以下範例顯示的是展示 `PassRequest` 動作的 CloudTrail 日誌項目。

```
{
    "eventVersion": "1.09",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "AIDA6ON6E4XEGIEXAMPLE",
        "arn": "arn:aws:iam::555555555555:user/Mary",
        "accountId": "555555555555",
        "accessKeyId": "AKIAIOSFODNN7EXAMPLE",
        "sessionContext": {
            "sessionIssuer": {
            "type": "Role",
            "principalId": "AIDA6ON6E4XEGIEXAMPLE",
            "arn": "arn:aws:iam::555555555555:user/Mary",
            "accountId": "555555555555",
            "userName": "Mary"
    
        },
        "attributes": {
            "creationDate": "2024-04-10T20:03:01Z",
            "mfaAuthenticated": "false"
        },
        "invokedBy": "q.amazonaws.com"
    },
    "eventTime": "2024-04-10T20:04:42Z",
    "eventSource": "q.amazonaws.com",
    "eventName": "PassRequest",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "q.amazonaws.com",
    "userAgent": "q.amazonaws.com",
    "requestParameters": null,
    "responseElements": null,
    "requestID": "2d528c76-329e-410b-9516-EXAMPLE565dc",
    "eventID": "ba0801a1-87ec-4d26-be87-EXAMPLE75bbb",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "555555555555",
    "eventCategory": "Management"
}
```

以下範例顯示的 CloudTrail 日誌項目展示了 Amazon Q 代表您呼叫 `s3:ListBuckets`。

```
{
    "eventVersion": "1.09",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "AIDA6ON6E4XEGIEXAMPLE",
        "arn": "arn:aws:iam::555555555555:user/Paulo",
        "accountId": "555555555555",
        "accessKeyId": "AKIAIOSFODNN7EXAMPLE",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "AIDA6ON6E4XEGIEXAMPLE",
                "arn": "arn:aws:iam::555555555555:user/Paulo",
                "accountId": "555555555555",
                "userName": "Paulo"
            },
            "attributes": {
                "creationDate": "2024-04-10T14:06:08Z",
                "mfaAuthenticated": "false"
            }
        },
        "invokedBy": "q.amazonaws.com"
    },
    "eventTime": "2024-04-10T14:07:55Z",
    "eventSource": "s3.amazonaws.com",
    "eventName": "ListBuckets",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "q.amazonaws.com",
    "userAgent": "q.amazonaws.com",
    "requestParameters": {
        "Host": "s3.amazonaws.com"
    },
    "responseElements": null,
    "additionalEventData": {
        "SignatureVersion": "SigV4",
        "CipherSuite": "ECDHE-RSA-AES128-GCM-SHA256",
        "bytesTransferredIn": 0,
        "AuthenticationMethod": "AuthHeader",
        "x-amz-id-2": "ExampleRequestId123456789",
        "bytesTransferredOut": 4054
    },
    "requestID": "ecd94349-b36f-44bf-b6f5-EXAMPLE9c463",
    "eventID": "2939ba50-1d26-4a5a-83bd-EXAMPLE85850",
    "readOnly": true,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "555555555555",
    "vpcEndpointId": "vpce-EXAMPLE1234",
    "eventCategory": "Management"
}
```

# 使用 Amazon CloudWatch 監控 Amazon Q Developer
<a name="monitoring-cloudwatch"></a>

**注意**  
此處討論的指標僅與[在 IDE 中使用 Amazon Q](q-in-IDE.md) 相關。

您可以使用 CloudWatch 監控 Amazon Q Developer，CloudWatch 會收集原始資料並將該資料處理成可讀且近乎即時的指標。這些統計資料會保留 15 個月，以便您存取歷史資訊，並更清楚 Amazon Q 的執行效能。您也可以設定留意特定閾值的警示，當滿足這些閾值時傳送通知或採取動作。如需詳細資訊，請參閱 [Amazon CloudWatch 使用者指南](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/)。

Amazon Q Developer 服務會在 `AWS/Q` 命名空間中報告下列指標。


| 維度 | 指標 | 使用案例或說明 | 
| --- | --- | --- | 
|  計數  |  調用  |  您想要確定經過一段時間計算出的調用次數。  | 
|  UserCount  |  DailyActiveUserTrend  |  您想要確定每天的作用中使用者數量。  | 
|  SubscriptionUserCount  |  SubscriptionCount  |  您想要確定擁有付費訂閱的使用者數量。  | 
|  UniqueUserCount  |  MonthlyActiveUniqueUsers  |  您想要確定某一月份的作用中使用者數量。  | 
|  ProgrammingLanguage、SuggestionState、CompletionType  |  GeneratedLineCount  |  您想要確定 Amazon Q Developer 產生的行數。  | 
|  ProgrammingLanguage、SuggestionState、CompletionType  |  SuggestionReferenceCount  |  您想要已發生使用參考的建議觸發次數。  | 
|  ProgrammingLanguage  |  CodeScanCount  |  您想要確定已發生的程式碼掃描次數。  | 
|  ProgrammingLanguage  |  TotalCharacterCount  |  檔案中的字元數，包括來自 Amazon Q Developer 的所有建議。  | 
|  ProgrammingLanguage  |  CodeWhispererCharacterCount  |  Amazon Q Developer 產生的字元數。  | 

若要彙總 Invocations，請使用總和統計資料。

若要彙總 DailyActiveUserTrend，請使用總和統計資料，並使用「1 天」作為期間。

若要彙總 SubscriptionCount，請使用總和統計資料。

若要彙總 MonthlyActiveUniqueUsers，請使用總和統計資料，並使用「30 天」作為期間。

# 使用 Amazon CloudWatch Logs 識別特定使用者的動作
<a name="monitoring-telemetry"></a>

您可以取得有關 Amazon Q Developer 用量的使用者層級指標。若要了解哪些使用者執行了特定動作，請尋找名為 SendTelemetryEvent 的事件，並查看事件中包含的 SendTelemetryEventRequest 類型 JSON 物件。在該物件內，結構描述如下所示。

**提示**  
您也可以將 Amazon Q Developer 中個別使用者的活動輸出為 CSV 格式的報告。如需詳細資訊，請參閱[在 Amazon Q Developer 中檢視特定使用者的活動](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."
```

請注意，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`：互動所花的時間。

# 在 Amazon CloudWatch Logs 中存取自訂相關訊息
<a name="customizations-optimize-accessing-logs"></a>

您可以在 [Amazon CloudWatch Logs ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html)中儲存建立自訂的相關資訊。

您可以利用下列許可集授權 Amazon Q Developer 管理員檢視這些日誌。

若要進一步了解將日誌傳送至多個資源所需的許可，請參閱《Amazon CloudWatch Logs 使用者指南》**中的[需要額外許可的記錄 [V2]](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AWS-logs-and-resource-policy.html#AWS-vended-logs-permissions-V2)。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AllowLogDeliveryActions",
            "Effect": "Allow",
            "Action": [
                "logs:PutDeliverySource",
                "logs:GetDeliverySource",
                "logs:DeleteDeliverySource",
                "logs:DescribeDeliverySources",
                "logs:PutDeliveryDestination",
                "logs:GetDeliveryDestination",
                "logs:DeleteDeliveryDestination",
                "logs:DescribeDeliveryDestinations",
                "logs:CreateDelivery",
                "logs:GetDelivery",
                "logs:DeleteDelivery",
                "logs:DescribeDeliveries",
                "firehose:ListDeliveryStreams",
                "firehose:DescribeDeliveryStream",
                "s3:ListAllMyBuckets",
                "s3:ListBucket",
                "s3:GetBucketLocation"
            ],
            "Resource": [
                "arn:aws:logs:us-east-1:111122223333:log-group:*",
                "arn:aws:firehose:us-east-1:111122223333:deliverystream/*",
                "arn:aws:s3:::*"
            ]
        }
    ]
}
```

------

# 在儀表板上檢視 Amazon Q Developer 使用者活動
<a name="dashboard"></a>

Amazon Q Developer 儀表板僅供 Amazon Q Developer 管理員使用，當中會摘要說明專業方案訂閱用戶如何使用服務的實用資料。

![\[Amazon Q 儀表板會顯示總訂閱數、作用中訂閱數、待定訂閱數、建議的程式碼行 Widget、作用中使用者 Widget 及篩選條件。\]](http://docs.aws.amazon.com/zh_tw/amazonq/latest/qdeveloper-ug/images/q-dev-dashboard.png)


Amazon Q 每小時會產生和顯示大部分的新指標。唯一未每小時更新的區段是**作用中使用者** Widget，此區段會依據國際標準時間 (UTC) 時鐘每日更新。

儀表板會顯示從下列訂閱的使用者收集而來的指標：
+ 您目前登入 AWS 的帳戶

  *而且*
+ 成員帳戶，如果您已登入管理帳戶，且該帳戶已啟用[訂閱的組織範圍內的可見性](subscribe-visibility.md)。
**注意**  
**作用中使用者** Widget 只會顯示您目前已登入帳戶的資訊。

**若要檢視和篩選儀表板**

1. 登入 AWS 管理主控台。

1. 切換到 Amazon Q Developer 主控台。

1. 從導覽窗格中選擇**儀表板**。

1. (選用) 依日期範圍、程式設計語言、自訂或整合式開發環境 (IDE) 廠商篩選資訊。

**備註**：
+ 如果導覽窗格中未提供**儀表板**連結，請參閱 [儀表板故障診斷](dashboard-troubleshooting.md)。
+ 如果您想要將使用者指標傳送至每日報告，且其中包含每位使用者的 Amazon Q Developer 用量明細，請參閱 [在 Amazon Q Developer 中檢視特定使用者的活動](q-admin-user-telemetry.md)。
+ 如需特定指標的相關資訊，請參閱 [Amazon Q Developer 儀表板用量指標的說明](dashboard-metrics-descriptions.md)，或選擇儀表板頁面右上角的說明連結 (![\[The help link.\]](http://docs.aws.amazon.com/zh_tw/amazonq/latest/qdeveloper-ug/images/help-icon.png))。

# Amazon Q Developer 儀表板用量指標的說明
<a name="dashboard-metrics-descriptions"></a>

下表說明 Amazon Q Developer 儀表板中顯示的指標。

如需儀表板中的詳細資訊，請參閱[在儀表板上檢視 Amazon Q Developer 使用者活動](dashboard.md)。


| 指標名稱 | Description | 
| --- | --- | 
|  **總訂閱數**  |  如果您登入的管理帳戶已啟用整個組織的訂閱可見性，則會顯示目前 AWS 帳戶中的訂閱總數，以及成員帳戶中的訂閱。 [https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/subscribe-visibility.html](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/subscribe-visibility.html)  | 
|  **作用中訂閱數**  |  如果您登入的管理帳戶已啟用整個組織的訂閱可見性，則會顯示目前 AWS 帳戶中的作用中訂閱總數，以及成員帳戶中的訂閱。 [https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/subscribe-visibility.html](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/subscribe-visibility.html) *作用中訂閱數*屬於已在其整合式開發環境 (IDE) 中開始使用 Amazon Q 的使用者。您需要支付這些訂閱的費用。如需作用中訂閱數的詳細資訊，請參閱 [Amazon Q Developer 訂閱狀態](q-admin-setup-subscribe-status.md)。  | 
|  **待定訂閱數**  |  如果您登入的管理帳戶已啟用整個組織的訂閱可見性，則會顯示目前 AWS 帳戶中的待處理訂閱總數，以及成員帳戶中的訂閱。 [https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/subscribe-visibility.html](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/subscribe-visibility.html) *待定訂閱數*屬於尚未開始在其 IDE 中使用 Amazon Q 的使用者。您不需支付這些訂閱的費用。如需待定訂閱數的詳細資訊，請參閱 [Amazon Q Developer 訂閱狀態](q-admin-setup-subscribe-status.md)。  | 
|  **接受的程式碼行**  |  顯示圓餅圖，指出使用者接受的程式碼行，依 Amazon Q 功能細分 （功能開發、文件產生、單元測試產生等）。  | 
|  **作用中使用者**  |  顯示折線圖，指出在指定的日期範圍內，於 IDE 中主動使用 Amazon Q 的訂閱用戶數。  | 
|  **內嵌建議**  |  顯示[內嵌建議](inline-suggestions.md)功能的建議和接受的建議總數。接受的建議百分比的計算方式，是以使用者接受的建議數除以 Amazon Q 產生的建議總數。建議總計數包括已接受和主動拒絕的建議，但不包括因使用者在其 IDE 中繼續輸入或開始執行其他操作而關閉的建議。  | 
|  **內嵌聊天**  |  顯示[內嵌聊天](q-in-IDE-inline-chat.md)功能的建議總數和接受的建議數。接受的建議百分比的計算方式，是以使用者接受的建議數除以 Amazon Q 產生的建議總數。  | 
|  **IDE 中的聊天** - **傳送的訊息總數**  |  在使用者 IDE 的 [Amazon Q 聊天](q-in-IDE-chat.md)視窗中顯示來自 Amazon Q 的回應總數。  | 
|  **功能開發** – **接受率**  |  顯示[特徵開發](q-in-IDE-chat.md#develop-code)功能的接受率。接受率的計算方式，是以使用者接受的程式碼行數除以 Amazon Q 建議的程式碼行總數。  | 
|  **文件產生**  |  顯示文件[產生](q-in-IDE-chat.md#doc-generation)功能建立和更新的文件檔案總數 （例如 READMEs和支援檔案）。接受率等於使用者接受的檔案更新或建立數，除以 Amazon Q 建議的檔案更新或建立總數。  | 
|  **單元測試產生**  |  顯示單位測試產生功能所產生的[單位測試](q-in-IDE-chat.md#unit-tests)總數，以及使用者接受的單位測試數目。接受率的計算方式，是以使用者接受的單元測試數除以 Amazon Q 產生的單元測試總數。  | 
|  **程式碼檢閱**  |  顯示程式碼檢閱功能產生的[程式碼檢閱](code-reviews.md)和調查結果報告總數。**程式碼檢閱總數 (僅限手動)** 和**問題清單報告 (僅限手動)** 是指*非*[自動產生](start-review.md#auto-scan)的程式碼檢閱和問題清單報告。  | 
|  **程式碼修正**  |  顯示 Amazon Q 產生的[程式碼修正](address-code-issues.md)總數。接受率的計算方式，是以使用者接受的程式碼修正數除以 Amazon Q 建議的程式碼修正總數。  | 
|  **程式碼轉換**  |  顯示轉換功能執行的程式碼[轉換](address-code-issues.md)總數，以及處理的程式碼行數。  | 

# 停用 Amazon Q Developer 儀表板
<a name="dashboard-disabling"></a>

如果您對資料隱私權、頁面載入時間或其他潛在問題有疑慮，建議您停用 Amazon Q Developer 儀表板。當您停用儀表板時，Amazon Q Developer 主控台中將不再提供儀表板頁面 (及其任何連結)。

如需儀表板中的詳細資訊，請參閱[檢視用量指標 (儀表板)](dashboard.md)。

**若要停用儀表板**

1. 開啟 Amazon Q Developer 主控台：
   + 如果您使用 的組織執行個體設定 Amazon Q Developer AWS IAM Identity Center，請使用管理帳戶或成員帳戶登入。
   + 如果您使用 IAM Identity Center 的帳戶執行個體設定 Amazon Q Developer，請使用與該執行個體相關聯的帳戶登入。

1. 選擇**設定**，然後在 **Amazon Q Developer 使用者活動**區段中，選擇**編輯**。

1. 停用 **Amazon Q Developer 用量儀表板**。

# Amazon Q Developer 儀表板故障診斷
<a name="dashboard-troubleshooting"></a>

如果無法使用 Amazon Q Developer 儀表板頁面，請執行下列操作：
+ **驗證您的許可**。若要檢視儀表板，您需具備下列許可：
  + `q:ListDashboardMetrics` 
  + `codewhisperer:ListProfiles` 
  + `sso:ListInstances` 
  + `user-subscriptions:ListUserSubscriptions` 
  + 若要查看 2024 年 11 月 22 日之前產生的指標，您還需要：`cloudwatch:GetMetricData` 和 `cloudwatch:ListMetrics` 

    如需許可的詳細資訊，請參閱「[允許管理員使用 Amazon Q Developer 主控台](id-based-policy-examples-admins.md#q-admin-setup-admin-users)」。
+ **驗證您的設定**。在 Amazon Q Developer 主控台中，選擇**設定**，並確認已啟用 **Amazon Q Developer 用量儀表板**切換開關。

如需儀表板中的詳細資訊，請參閱[檢視用量指標 (儀表板)](dashboard.md)。

# 在 Amazon Q Developer 中檢視特定使用者的活動
<a name="q-admin-user-telemetry"></a>

您可以設定讓 Amazon Q 收集組織中個別 Amazon Q Developer 訂閱用戶的使用者活動遙測，並在報告中顯示該資訊。報告為您提供了深入了解特定使用者如何使用 Amazon Q 的資訊。

Amazon Q 會在每天午夜 (00:00) 國際標準時間 (UTC) 產生報告，並以 CSV 檔案的形式將其儲存在下列路徑：

`s3://bucketName/prefix/AWSLogs/accountId/QDeveloperLogs/by_user_analytic/region/year/month/day/00/accountId_by_user_analytic_timestamp.csv`

CSV 檔案的配置如下：
+ 每一列顯示當天與 Amazon Q 互動的使用者。
+ 每一欄顯示指標，如 [使用者活動報告指標](user-activity-metrics.md) 中所述。指標是根據一整天收集到的使用者遙測來計算。

如果一天中有超過 1,000 位使用者與 Amazon Q 互動，則 Amazon Q 會將資料拆分成數個 CSV 檔案，每個檔案包含 1,000 位使用者，且檔案會加上尾碼 `part_1`、`part_2`，以此類推。

**注意**  
當您啟用使用者活動報告時，Amazon Q 就會收集遙測，而不受開發人員在其 IDE 中的**讓 Amazon Q 將用量資料傳送至 AWS**設定影響。該設定會控制 *AWS 公司*是否可使用遙測，而非您的組織。如需有關此設定的詳細資訊，請參閱 [選擇退出共用用戶端遙測](opt-out-IDE.md#opt-out-IDE-telemetry)。

使用下列指示來啟用使用者活動報告。

**必要條件**

建立 Amazon S3 儲存貯體以保留使用者活動報告 CSV 檔案。儲存貯體必須：
+ 位於安裝 Amazon Q Developer 設定檔 AWS 的區域。此設定檔是在您第一次向 Amazon Q Developer 專業方案訂閱 IAM Identity Center 員工使用者時安裝。如需此設定檔及支援該設定檔之區域的詳細資訊，請參閱 [什麼是 Amazon Q Developer 設定檔？](subscribe-understanding-profile.md) 和 [Q Developer 主控台和 Q Developer 設定檔支援的區域](q-admin-setup-subscribe-regions.md#qdev-console-and-profile-regions)。
+ 位於使用者訂閱 AWS 的帳戶。如果使用者在多個 AWS 帳戶中訂閱，則您必須在每個帳戶中建立儲存貯體。不支援跨帳戶儲存貯體。
+ (選用，但建議使用) 與您可能用於[提示記錄](q-admin-prompt-logging.md)的儲存貯體不同。
+ 包含首碼，也稱為子資料夾，也就是 Amazon Q 將儲存 CSV 檔案的位置。CSV 檔案無法儲存在儲存貯體的根目錄中。
+ 備妥儲存貯體政策，類似下方所示。將 *bucketName*、*region*、*accountId* 和 *prefix* 取代為您自己的資訊。

------
#### [ JSON ]

****  

  ```
  {
      "Version":"2012-10-17",		 	 	 
      "Statement": [
          {
              "Sid": "QDeveloperLogsWrite",
              "Effect": "Allow",
              "Principal": {
                  "Service": "q.amazonaws.com"
              },
              "Action": [
                  "s3:PutObject"
              ],
              "Resource": [
                  "arn:aws:s3:::bucketName/prefix/*"
              ],
              "Condition": {
                  "StringEquals": {
                      "aws:SourceAccount": "111122223333"
                  },
                  "ArnLike": {
                      "aws:SourceArn": "arn:aws:codewhisperer:us-east-1:111122223333:*"
                  }
              }
          }
      ]
  }
  ```

------

  (選用) 如果您在儲存貯體上設定 SSE-KMS，請在 KMS 金鑰上新增下列政策：

  ```
  {
      "Effect": "Allow",
      "Principal": {
          "Service": "q.amazonaws.com"
      },
      "Action": "kms:GenerateDataKey",
      "Resource": "*",
      "Condition": {
          "StringEquals": {
            "aws:SourceAccount": "accountId" 
          },
          "ArnLike": {
             "aws:SourceArn": "arn:aws:codewhisperer:region:accountId:*"
          }
      }
  }
  ```

  若要了解如何保護 Amazon S3 儲存貯體中的資料，請參閱《Amazon Simple Storage Service 使用者指南》**中的[使用加密保護資料](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingEncryption.html)。

**若要啟用使用者活動報告**

1. 開啟 Amazon Q Developer 主控台。

   若要使用 Amazon Q Developer 主控台，您必須具有 [允許管理員使用 Amazon Q Developer 主控台](id-based-policy-examples-admins.md#q-admin-setup-admin-users) 中定義的許可。

1. 選擇**設定**。

1. 在 **Q Developer 使用者活動報告**下，選擇**編輯**。

1. 切換**收集每個使用者的精細指標**。

1. 在 **S3 位置**下，輸入您將用來保留 CSV 報告的 Amazon S3 URI。範例：`s3://amzn-s3-demo-bucket/user-activity-reports/`

# 使用者活動報告指標
<a name="user-activity-metrics"></a>

下表說明 Amazon Q Developer 所產生使用者活動報告中包含的指標。

如需這些報告的詳細資訊，請參閱 [在 Amazon Q Developer 中檢視特定使用者的活動](q-admin-user-telemetry.md)。


| 指標名稱 | Description | 
| --- | --- | 
|  Chat\$1AICodeLines  |  Amazon Q 建議且使用者接受的程式碼行。此指標包含透過 [Amazon Q 聊天](q-in-IDE-chat.md) (非[內嵌聊天](q-in-IDE-inline-chat.md)) 產生並插入 IDE 的程式碼。  | 
|  Chat\$1MessagesInteracted  |  使用者主動與 Amazon Q 進行互動的聊天訊息數。主動互動的範例：按一下連結、插入建議，以及對 Amazon Q 的回應按讚。此指標包括 [Amazon Q 聊天](q-in-IDE-chat.md) (非[內嵌聊天](q-in-IDE-inline-chat.md)) 所產生的訊息。  | 
|  Chat\$1MessagesSent  |  往返 Amazon Q 的訊息數量。此指標包括 [Amazon Q 聊天](q-in-IDE-chat.md) (非[內嵌聊天](q-in-IDE-inline-chat.md)) 中的使用者提示和 Amazon Q 回應。  | 
|  CodeFix\$1AcceptanceEventCount  |  Amazon Q 建議且使用者接受的程式碼修正數量。此指標適用於透過程式碼[檢閱功能產生的程式碼](code-reviews.md)修正。  | 
|  CodeFix\$1AcceptedLines  |  Amazon Q 建議且使用者接受的程式碼行。此指標適用於透過程式碼[檢閱功能產生的程式碼](code-reviews.md)行。  | 
|  CodeFix\$1GeneratedLines  |  Amazon Q 建議的程式碼行。此指標適用於透過程式碼[檢閱功能產生的程式碼](code-reviews.md)行。  | 
|  CodeFix\$1GenerationEventCount  |  Amazon Q 建議的程式碼修正次數。此指標適用於透過程式碼[檢閱功能產生的程式碼](code-reviews.md)修正。  | 
|  CodeReview\$1FailedEventCount  |  雖找到但 Amazon Q 無法建議程式碼修正的程式碼問題數量。此指標適用於使用程式碼[檢閱功能產生的程式碼](code-reviews.md)問題。  | 
|  CodeReview\$1FindingsCount  |  Amazon Q 發現的程式碼問題數量。此指標適用於使用程式碼[檢閱功能發現的程式碼](code-reviews.md)問題。  | 
|  CodeReview\$1SucceededEventCount  |  找到且 Amazon Q 能夠產生建議程式碼修正的程式碼問題數量。此指標適用於使用程式碼[檢閱功能發現的程式碼](code-reviews.md)問題。  | 
|  Dev\$1AcceptanceEventCount  |  Amazon Q 建議且使用者接受的程式碼功能數量。此指標適用於透過 [/dev 命令](q-in-IDE-chat.md#develop-code)產生的程式碼功能。  | 
|  Dev\$1AcceptedLines  |  Amazon Q 建議且使用者接受的程式碼行。此指標適用於透過 [/dev 命令](q-in-IDE-chat.md#develop-code)產生的程式碼行。  | 
|  Dev\$1GeneratedLines  |  Amazon Q 建議的程式碼行。此指標適用於透過 [/dev 命令](q-in-IDE-chat.md#develop-code)產生的程式碼行。  | 
|  Dev\$1GenerationEventCount  |  Amazon Q 建議的程式碼功能數量。此指標適用於透過 [/dev 命令](q-in-IDE-chat.md#develop-code)產生的程式碼功能。  | 
|  DocGeneration\$1AcceptedFileUpdates  |  Amazon Q 建議且使用者接受的檔案更新數量。此指標適用於透過 [/doc 命令](q-in-IDE-chat.md#doc-generation)產生的檔案更新。  | 
|  DocGeneration\$1AcceptedFilesCreations  |  Amazon Q 建議且使用者接受的檔案建立數量。此指標適用於透過 [/doc 命令](q-in-IDE-chat.md#doc-generation)產生的檔案建立。  | 
|  DocGeneration\$1AcceptedLineAdditions  |  Amazon Q 建議且使用者接受的文件新增行。此指標適用於透過 [/doc 命令](q-in-IDE-chat.md#doc-generation)產生的文件。  | 
|  DocGeneration\$1AcceptedLineUpdates  |  Amazon Q 建議且使用者接受的文件更新行。此指標適用於使用 [/doc 命令](q-in-IDE-chat.md#doc-generation)產生的文件。  | 
|  DocGeneration\$1EventCount  |  使用者使用 [/doc 命令](q-in-IDE-chat.md#doc-generation)與 Amazon Q 互動的次數。  | 
|  DocGeneration\$1RejectedFileCreations  |  Amazon Q 建議且使用者拒絕的檔案建立數量。此指標適用於透過 [/doc 命令](q-in-IDE-chat.md#doc-generation)產生的檔案建立。  | 
|  DocGeneration\$1RejectedFileUpdates  |  Amazon Q 建議且使用者拒絕的檔案更新數量。此指標適用於透過 [/doc 命令](q-in-IDE-chat.md#doc-generation)產生的檔案更新。  | 
|  DocGeneration\$1RejectedLineAdditions  |  Amazon Q 建議且使用者拒絕的文件新增行。此指標適用於透過 [/doc 命令](q-in-IDE-chat.md#doc-generation)產生的文件。  | 
|  DocGeneration\$1RejectedLineUpdates  |  Amazon Q 建議且使用者拒絕的文件更新行。此指標適用於使用 [/doc 命令](q-in-IDE-chat.md#doc-generation)產生的文件。  | 
|  InlineChat\$1AcceptedLineAdditions  |  Amazon Q 建議且使用者接受的程式碼新增行。此指標包含透過[內嵌聊天](q-in-IDE-inline-chat.md) (而非 [Amazon Q 聊天](q-in-IDE-chat.md)) 產生的程式碼新增。  | 
|  InlineChat\$1AcceptedLineDeletions  |  Amazon Q 建議且使用者接受的程式碼刪除行。此指標包含透過[內嵌聊天](q-in-IDE-inline-chat.md) (而非 [Amazon Q 聊天](q-in-IDE-chat.md)) 建議的程式碼刪除。  | 
|  InlineChat\$1AcceptanceEventCount  |  使用者接受的[內嵌聊天](q-in-IDE-inline-chat.md) (非 [Amazon Q 聊天](q-in-IDE-chat.md)) 建議數量。  | 
|  InlineChat\$1DismissalEventCount  |  使用者捨棄的[內嵌聊天](q-in-IDE-inline-chat.md) (非 [Amazon Q 聊天](q-in-IDE-chat.md)) 建議數量。「捨棄」表示程式碼建議已顯示，但使用者在其 IDE 中繼續輸入或執行其他操作，且未明確接受或拒絕程式碼建議。  | 
|  InlineChat\$1DismissedLineAdditions  |  Amazon Q 建議且使用者捨棄的程式碼新增行。「捨棄」表示程式碼建議已顯示，但使用者在其 IDE 中繼續輸入或執行其他操作，且未明確接受或拒絕程式碼建議。此指標包含透過[內嵌聊天](q-in-IDE-inline-chat.md) (而非 [Amazon Q 聊天](q-in-IDE-chat.md)) 產生的程式碼新增。  | 
|  InlineChat\$1DismissedLineDeletions  |  Amazon Q 建議且使用者捨棄的程式碼刪除行。「捨棄」表示程式碼建議已顯示，但使用者在其 IDE 中繼續輸入或執行其他操作，且未明確接受或拒絕程式碼建議。此指標包含透過[內嵌聊天](q-in-IDE-inline-chat.md) (而非 [Amazon Q 聊天](q-in-IDE-chat.md)) 建議的程式碼刪除。  | 
|  InlineChat\$1EventCount  |  使用者參與的[內嵌聊天](q-in-IDE-inline-chat.md) (而非 [Amazon Q 聊天](q-in-IDE-chat.md)) 工作階段數量。  | 
|  InlineChat\$1RejectedLineAdditions  |  Amazon Q 建議且使用者拒絕的程式碼新增行。此指標包含透過[內嵌聊天](q-in-IDE-inline-chat.md) (而非 [Amazon Q 聊天](q-in-IDE-chat.md)) 產生的程式碼新增。  | 
|  InlineChat\$1RejectedLineDeletions  |  Amazon Q 建議且使用者拒絕的程式碼刪除行。此指標包含透過[內嵌聊天](q-in-IDE-inline-chat.md) (而非 [Amazon Q 聊天](q-in-IDE-chat.md)) 建議的程式碼刪除。  | 
|  InlineChat\$1RejectionEventCount  |  使用者拒絕的[內嵌聊天](q-in-IDE-inline-chat.md) (非 [Amazon Q 聊天](q-in-IDE-chat.md)) 建議數量。  | 
|  Inline\$1AICodeLines  |  Amazon Q 建議且使用者接受的程式碼行。此指標包含作為[內嵌建議](inline-suggestions.md)接受的程式碼。  | 
|  Inline\$1AcceptanceCount  |  使用者接受的[內嵌建議](inline-suggestions.md)數量。  | 
|  Inline\$1SuggestionsCount  |  對使用者顯示的[內嵌建議](inline-suggestions.md)數量。  | 
|  TestGeneration\$1AcceptedLines  |  Amazon Q 建議且使用者接受的程式碼行。此指標適用於透過 [/test 命令](q-in-IDE-chat.md#unit-tests)產生的程式碼行。  | 
|  TestGeneration\$1AcceptedTests  |  Amazon Q 建議且使用者接受的單元測試數量。此指標適用於透過 [/test 命令](q-in-IDE-chat.md#unit-tests)產生的單元測試。  | 
|  TestGeneration\$1EventCount  |  使用者透過 [/test 命令](q-in-IDE-chat.md#unit-tests)與 Amazon Q 互動的次數。  | 
|  TestGeneration\$1GeneratedLines  |  Amazon Q 建議的程式碼行。此指標適用於透過 [/test 命令](q-in-IDE-chat.md#unit-tests)產生的程式碼行。  | 
|  TestGeneration\$1GeneratedTests  |  Amazon Q 建議的單元測試數量。此指標適用於透過 [/test 命令](q-in-IDE-chat.md#unit-tests)產生的單元測試。  | 
|  Transformation\$1EventCount  |  使用者透過 [/transform 命令](transform-in-IDE.md)與 Amazon Q 互動的次數，不包括使用者[在命令列上轉換程式碼](transform-CLI.md)的次數。  | 
|  Transformation\$1LinesGenerated  |  Amazon Q 建議的程式碼行。此指標適用於透過 [/transform 命令](transform-in-IDE.md)產生的程式碼，不包括[在命令行上轉換](transform-CLI.md)的程式碼。  | 
|  Transformation\$1LinesIngested  |  提供給 Amazon Q 進行轉換的程式碼行。此指標適用於透過 [/transform 命令](transform-in-IDE.md)提供的程式碼，不包括提供用於[命令列上轉換](transform-CLI.md)或 [SQL 轉換](transform-sql.md)的程式碼。  | 

# 在 Amazon Q Developer 中記錄使用者的提示
<a name="q-admin-prompt-logging"></a>

管理員可以在整合式開發環境 (IDE) 中，啟用使用者在 Amazon Q 的所有[內嵌建議](inline-suggestions.md)和[聊天對話](q-in-IDE-chat.md)的記錄功能。這些日誌有助於稽核、偵錯、分析和確保合規。

當開發人員使用內嵌建議時，Amazon Q 會記錄接受和主動拒絕的建議。當開發人員與 Amazon Q 聊天時，Amazon Q 會記錄開發人員的提示和 Amazon Q 的回應。當開發人員使用 **/dev** 命令與[適用於軟體開發的 Amazon Q 代理程式](q-in-IDE-chat.md#develop-code)聊天時，只會記錄提示。

Amazon Q 會將日誌儲存在您建立的 Amazon S3 儲存貯體中，路徑如下：

`bucketName/prefix/AWSLogs/accountId/QDeveloperLogs/log-type/region/year/month/day/utc-hour/zipFile.gz/logFile.json`

在上方路徑中，`log-type` 是下列其中一項：
+ `GenerateAssistantResponse` — 保留聊天日誌
+ `GenerateCompletions` — 保留內嵌完成日誌
+ `StartTaskAssistCodeGeneration` — 保留 **/dev** 日誌

如需日誌檔案內容的範例和說明，請參閱 [Amazon Q Developer 中的提示日誌範例](q-admin-prompt-log-examples.md)。

除了用於保留日誌的 Amazon S3 儲存貯體須支付儲存費用之外，提示記錄功能不須付費，而選用 KMS 金鑰來加密儲存貯體時，須支付少許費用。

使用下列指示來啟用提示記錄。

**先決條件**
+ 確定使用者已在獨立帳戶中訂閱，如果您使用 [AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html)，則是在管理帳戶中訂閱。目前，Q Developer 不支援記錄在 AWS Organizations的成員帳戶中訂閱的使用者提示。
+ 建立 Amazon S3 儲存貯體以保留提示日誌。儲存貯體必須：
  + 位於安裝 Amazon Q Developer 設定檔 AWS 的區域。此設定檔是在您第一次向 Amazon Q Developer 專業方案訂閱使用者時安裝。如需此設定檔及支援該設定檔之區域的詳細資訊，請參閱 [什麼是 Amazon Q Developer 設定檔？](subscribe-understanding-profile.md) 和 [Q Developer 主控台和 Q Developer 設定檔支援的區域](q-admin-setup-subscribe-regions.md#qdev-console-and-profile-regions)。
  + 位於使用者訂閱 AWS 的帳戶。
  + 備妥儲存貯體政策，類似下方所示。將 *bucketName*、*region*、*accountId* 和 *prefix* 取代為您自己的資訊。

------
#### [ JSON ]

****  

    ```
    {
        "Version":"2012-10-17",		 	 	 
        "Statement": [
            {
                "Sid": "QDeveloperLogsWrite",
                "Effect": "Allow",
                "Principal": {
                    "Service": "q.amazonaws.com"
                },
                "Action": [
                    "s3:PutObject"
                ],
                "Resource": [
                    "arn:aws:s3:::bucketName/prefix/*"
                ],
                "Condition": {
                    "StringEquals": {
                        "aws:SourceAccount": "111122223333"
                    },
                    "ArnLike": {
                    "aws:SourceArn": "arn:aws:codewhisperer:us-east-1:111122223333:*"
                    }
                }
            }
        ]
    }
    ```

------

    (選用) 如果您在儲存貯體上設定 SSE-KMS，請在 KMS 金鑰上新增下列政策：

    ```
    {
        "Effect": "Allow",
        "Principal": {
            "Service": "q.amazonaws.com"
        },
        "Action": "kms:GenerateDataKey",
        "Resource": "*",
        "Condition": {
            "StringEquals": {
              "aws:SourceAccount": "accountId" 
            },
            "ArnLike": {
               "aws:SourceArn": "arn:aws:codewhisperer:region:accountId:*"
            }
        }
    }
    ```

    若要了解如何保護 Amazon S3 儲存貯體中的資料，請參閱《Amazon Simple Storage Service 使用者指南》**中的[使用加密保護資料](https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingEncryption.html)。

**若要啟用提示記錄**

1. 開啟 Amazon Q Developer 主控台。

   若要使用 Amazon Q Developer 主控台，您必須具有 [允許管理員使用 Amazon Q Developer 主控台](id-based-policy-examples-admins.md#q-admin-setup-admin-users) 中定義的許可。
**注意**  
您必須以獨立帳戶管理員或管理帳戶管理員的身分登入。成員帳戶管理員無法啟用提示記錄，因為不支援成員帳戶中訂閱之使用者的提示記錄功能。

1. 選擇**設定**。

1. 在**偏好設定**下，選擇**編輯**。

1. 在「編輯偏好設定」視窗中，切換 **Q Developer 提示記錄**。

1. 在 Amazon S3 位置下，輸入您將用來接收日誌的 Amazon S3 URI。範例：`s3://amzn-s3-demo-bucket/qdev-prompt-logs/`

# Amazon Q Developer 中的提示日誌範例
<a name="q-admin-prompt-log-examples"></a>

本節提供 Amazon Q Developer 產生的提示日誌範例。

以下每一個範例都是描述日誌檔案欄位的表格。

如需提示日誌的詳細資訊，請參閱 [在 Amazon Q Developer 中記錄使用者的提示](q-admin-prompt-logging.md)。

**Topics**
+ [

## 內嵌建議日誌範例
](#prompt-log-examples-inline)
+ [

## 聊天日誌範例
](#prompt-log-examples-chat)
+ [

## /dev 日誌範例
](#prompt-log-examples-dev)

## 內嵌建議日誌範例
<a name="prompt-log-examples-inline"></a>

下列範例顯示使用者接受內嵌建議時產生的日誌檔案。

```
{
    "records": [
        {
            "generateCompletionsEventRequest": {
                "leftContext": "import * cdk from 'aws-cdk-lib';\r\nimport * s3 from 'aws-cdk-lib/aws-s3';\r\nimport { Stack, StackProps } from 'constructs';\r\nexport class MyStack extends Stack {\r\n  constructor(scope: cdk.App, id: string, props?: StackProps) {\r\n    super(scope, id, props);\r\n\r\n    new s3.Bucket(this, 'XXXXXXXX', {\r\n      versioned: true\r\n    });\r\n  }\r\n  ",
                "rightContext": "",
                "fileName": "cdk-modified.ts",
                "customizationArn": null,
                "userId": "d-92675051d5.b8f1f340-9081-70ad-5fc5-0f37151937a6",
                "timeStamp": "2025-01-06T15:09:16.412719Z"
            },
            "generateCompletionsEventResponse": {
                "completions": ["synth() {\n    return cdk.App.prototype.synth.apply(this, arguments);\n  }"],
                "requestId": "797c70ee-abc9-4cc7-a148-b9df17f6ce48"
            }
        }
    ]
}
```

下表說明內嵌建議日誌檔案中的各個欄位。


| 欄位名稱 | Description | 
| --- | --- | 
|  `records`  |  最上層欄位包含一組內嵌建議，也稱為內嵌完成。  | 
|  `generateCompletionsEventRequest`  |  描述內嵌程式碼建議的請求。Amazon Q 會代表使用者提出請求。  | 
|  `leftContext`  |  指出游標之前的程式碼，Amazon Q 會用該程式碼產生內嵌建議的內容。  | 
|  `rightContext`  |  指出游標之後的程式碼，Amazon Q 會用該程式碼產生內嵌建議的內容。  | 
|  `fileName`  |  指出請求內嵌建議所在檔案的名稱。  | 
|  `customizationArn`  |  指出套用至內嵌建議之自訂的 Amazon Resource Name (ARN)。此範例中沒有自訂。  | 
|  `userId`  |  指出請求內嵌建議之使用者的使用者 ID。  | 
|  `timeStamp`  |  指出請求內嵌建議的日期和時間。時間戳記是以國際標準時間 (UTC) 表示。  | 
|  `generateCompletionsEventResponse`  |  描述 Amazon Q 產生的內嵌建議。  | 
|  `completions`  |  指出 Amazon Q 所提供且使用者接受的內嵌建議。  | 
|  `requestId`  |  作為事件之唯一識別的內嵌請求 ID。  | 

## 聊天日誌範例
<a name="prompt-log-examples-chat"></a>

下列範例顯示使用者在其 IDE 中使用 Amazon Q 聊天時，產生的日誌檔案。

```
{
    "records": [
        {
            "generateAssistantResponseEventRequest": {
                "prompt": "Can you explain how to set up object-level access control in an S3 bucket using AWS CDK?",
                "chatTriggerType": "MANUAL",
                "customizationArn": null,
                "userId": "d-92675051d5.b8f1f340-9081-70ad-5fc5-0f37151937a6",
                "timeStamp": "2025-01-06T15:05:56.313070Z"
            },
            "generateAssistantResponseEventResponse": {
                "assistantResponse": "I'll explain how to set up object-level access control for an S3 bucket using AWS CDK. Here's how you can implement different access control configurations: [[1]](https://docs.aws.amazon.com/AmazonS3/latest/API/s3_example_s3_Scenario_ManageACLs_section.html)\n\n1. Using Bucket Owner Enforced (Recommended Modern Approach):\n```typescript\nimport * as cdk from 'aws-cdk-lib';\nimport * as s3 from 'aws-cdk-lib/aws-s3';\n\nnew s3.Bucket(this, 'XXXXXXXX', {\n  objectOwnership: s3.ObjectOwnership.BUCKET_OWNER_ENFORCED,\n  blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL\n});\n```\n\n2. Using Public Access Block Configuration:\n```typescript\nimport * as cdk from 'aws-cdk-lib';\nimport * as s3 from 'aws-cdk-lib/aws-s3';\n\nnew s3.Bucket(this, 'XXXXXXXX', {\n  blockPublicAccess: new s3.BlockPublicAccess({\n    blockPublicAcls: true,\n    blockPublicPolicy: true,\n    ignorePublicAcls: true,\n    restrictPublicBuckets: true\n  })\n});\n```\n\n3. Setting Access Control for Specific Use Cases:\n```typescript\nimport * as cdk from 'aws-cdk-lib';\nimport * as s3 from 'aws-cdk-lib/aws-s3';\nimport * as iam from 'aws-cdk-lib/aws-iam';\n\nconst bucket = new s3.Bucket(this, 'XXXXXXXX', {\n  // Enable versioning for object-level recovery\n  versioned: true,\n  \n  // Enforce encryption\n  encryption: s3.BucketEncryption.S3_MANAGED,\n  \n  // Block all public access\n  blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,\n  \n  // Enforce object ownership\n  objectOwnership: s3.ObjectOwnership.BUCKET_OWNER_ENFORCED,\n  \n  // Enable server access logs\n  serverAccessLogsPrefix: 'logs/'\n});\n\n// Grant read access to specific IAM role\nconst role = new iam.Role(this, 'MyRole', {\n  assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),\n});\nbucket.grantRead(role);\n\n// Grant write access to specific objects with prefix\nbucket.addToResourcePolicy(new iam.PolicyStatement({\n  actions: ['s3:PutObject'],\n  resources: [bucket.arnForObjects('uploads/*')],\n  principals: [new iam.AccountRootPrincipal()]\n}));\n```\n\n4. Setting up Lifecycle Rules for Objects:\n```typescript\nimport * as cdk from 'aws-cdk-lib';\nimport * as s3 from 'aws-cdk-lib/aws-s3';\n\nnew s3.Bucket(this, 'XXXXXXXX', {\n  lifecycle: [\n    {\n      transitions: [\n        {\n          storageClass: s3.StorageClass.INFREQUENT_ACCESS,\n          transitionAfter: cdk.Duration.days(30)\n        },\n        {\n          storageClass: s3.StorageClass.GLACIER,\n          transitionAfter: cdk.Duration.days(90)\n        }\n      ],\n      expiration: cdk.Duration.days(365)\n    }\n  ]\n});\n```\n\nKey points to remember:\n- Always use the principle of least privilege\n- Block public access by default unless explicitly required\n- Use BUCKET_OWNER_ENFORCED for object ownership when possible\n- Consider implementing lifecycle rules for cost optimization\n- Use versioning for sensitive data\n- Implement server-side encryption\n- Use resource policies and IAM roles for access control instead of ACLs\n- Monitor access patterns using server access logging\n\nThese configurations help create a secure and well-managed S3 bucket with appropriate access controls at both bucket and object levels.",
                "followupPrompts": "How can you implement multi-factor authentication for S3 bucket access using AWS CDK?What are the best practices for setting up object-level versioning in AWS S3 using CDK?How can you use AWS CDK to create a custom error message for unauthorized access attempts on an S3 bucket?",
                "messageMetadata": {
                    "conversationId": "491bd3cd-d70d-40c0-a452-5ef3f0878422",
                    "utteranceId": null
                },
                "codeReferenceEvents": [],
                "supplementaryWebLinksEvent": [
                    {
                        "uri": "https://docs.aws.amazon.com/AmazonS3/latest/API/s3_example_s3_Scenario_ManageACLs_section.html",
                        "title": "[1] Manage access control lists (ACLs) for Amazon S3 buckets using an AWS SDK - Amazon Simple Storage Service",
                        "snippet": "The following code example shows how to manage access control lists (ACLs) for Amazon S3 buckets.\n\n.NET\n\n**AWS SDK for .NET**\n\n```\n    using System;\n    using System.Collections.Generic;\n    using System.Threading.Tasks;\n    using Amazon.S3;\n    using Amazon.S3.Model;\n\n    /// <summary>\n    /// This example shows how to manage Amazon Simple Storage Service\n    /// (Amazon S3) access control lists (ACLs) to control Amazon S3 bucket\n    /// access.\n    /// </summary>\n    public class ManageACLs\n    {\n        public static async Task Main()\n        {\n            string bucketName = \"amzn-s3-demo-bucket1\";\n            string newBucketName = \"amzn-s3-demo-bucket2\";\n            string keyName = \"sample-object.txt\";\n            string emailAddress = \"someone@example.com\";\n\n            // If the AWS Region where your bucket is located is different from\n            // the Region defined for the default user, pass the Amazon S3 bucket's\n            // name to the client constructor. It should look like this:\n            // RegionEndpoint bucketRegion = RegionEndpoint.USEast1;\n            IAmazonS3 client = new AmazonS3Client();\n\n            await TestBucketObjectACLsAsync(client, bucketName, newBucketName, keyName, emailAddress);\n        }\n\n        /// <summary>\n        /// Creates a new Amazon S3 bucket with a canned ACL, then retrieves the ACL\n        /// information and then adds a new ACL to one of the objects in the\n        /// Amazon S3 bucket.\n        /// </summary>\n        /// <param name=\"client\">The initialized Amazon S3 client object used to call\n        /// methods to create a bucket, get an ACL, and add a different ACL to\n        /// one of the objects.</param>\n        /// <param name=\"bucketName\">A string representing the original Amazon S3\n        /// bucket name.</param>\n        /// <param name=\"newBucketName\">A string representing the name of the\n        /// new bucket that will be created.</param>\n        /// <param name=\"keyName\">A string representing the key name of an Amazon S3\n        /// object for which we will change the ACL.</param>\n        /// <param name=\"emailAddress\">A string representing the email address\n        /// belonging to the person to whom access to the Amazon S3 bucket will be\n        /// granted.</param>\n        public static async Task TestBucketObjectACLsAsync(\n            IAmazonS3 client,\n            string bucketName,\n            string newBucketName,\n            string keyName,\n            string emailAddress)\n        {\n            try\n            {\n                // Create a new Amazon S3 bucket and specify canned ACL.\n                var success = await CreateBucketWithCannedACLAsync(client, newBucketName);\n\n                // Get the ACL on a bucket.\n                await GetBucketACLAsync(client, bucketName);\n\n                // Add (replace) the ACL on an object in a bucket.\n                await AddACLToExistingObjectAsync(client, bucketName, keyName, emailAddress);\n            }\n            catch (AmazonS3Exception amazonS3Exception)\n            {\n                Console.WriteLine($\"Exception: {amazonS3Exception.Message}\");\n            }\n        }\n\n        /// <summary>\n        /// Creates a new Amazon S3 bucket with a canned ACL attached.\n        /// </summary>\n        /// <param name=\"client\">The initialized client object used to call\n        /// PutBucketAsync.</param>\n        /// <param name=\"newBucketName\">A string representing the name of the\n        /// new Amazon S3 bucket.</param>\n        /// <returns>Returns a boolean value indicating success or failure.</returns>\n        public static async Task<bool> CreateBucketWithCannedACLAsync(IAmazonS3 client, string newBucketName)\n        {\n            var request = new PutBucketRequest()\n            {\n                BucketName = newBucketName,\n                BucketRegion = S3Region.EUWest1,\n\n                // Add a canned ACL.\n                CannedACL = S3CannedACL.LogDeliveryWrite,\n            };\n\n            var response = await client.PutBucketAsync(request);\n            return response.HttpStatusCode == System.Net.HttpStatusCode.OK;\n        }\n\n\n        /// <summary>\n        /// Retrieves the ACL associated with the Amazon S3 bucket name in the\n        /// bucketName parameter.\n        /// </summary>\n        /// <param name=\"client\">The initialized client object used to call\n        /// PutBucketAsync.</param>\n        /// <param name=\"bucketName\">The Amazon S3 bucket for which we want to get the\n        /// ACL list.</param>\n        /// <returns>Returns an S3AccessControlList returned from the call to\n        /// GetACLAsync.</returns>\n        public static async Task<S3AccessControlList> GetBucketACLAsync(IAmazonS3 client, string bucketName)\n        {\n            GetACLResponse response = await client.GetACLAsync(new GetACLRequest\n            {\n                BucketName = bucketName,\n            });\n\n            return response.AccessControlList;\n        }\n\n\n\n        /// <summary>\n        /// Adds a new ACL to an existing object in the Amazon S3 bucket.\n        /// </summary>\n        /// <param name=\"client\">The initialized client object used to call\n        /// PutBucketAsync.</param>\n        /// <param name=\"bucketName\">A string representing the name of the Amazon S3\n        /// bucket containing the object to which we want to apply a new ACL.</param>\n        /// <param name=\"keyName\">A string representing the name of the object\n        /// to which we want to apply the new ACL.</param>\n        /// <param name=\"emailAddress\">The email address of the person to whom\n        /// we will be applying to whom access will be granted.</param>\n        public static async Task AddACLToExistingObjectAsync(IAmazonS3 client, string bucketName, string keyName, string emailAddress)\n        {\n            // Retrieve the ACL for an object.\n            GetACLResponse aclResponse = await client.GetACLAsync(new GetACLRequest\n            {\n                BucketName = bucketName,\n                Key = keyName,\n            });\n\n            S3AccessControlList acl = aclResponse.AccessControlList;\n\n            // Retrieve the owner.\n            Owner owner = acl.Owner;\n\n            // Clear existing grants.\n            acl.Grants.Clear();\n\n            // Add a grant to reset the owner's full permission\n            // (the previous clear statement removed all permissions).\n            var fullControlGrant = new S3Grant\n            {\n                Grantee = new S3Grantee { CanonicalUser = acl.Owner.Id },\n            };\n            acl.AddGrant(fullControlGrant.Grantee, S3Permission.FULL_CONTROL);\n\n            // Specify email to identify grantee for granting permissions.\n            var grantUsingEmail = new S3Grant\n            {\n                Grantee = new S3Grantee { EmailAddress = emailAddress },\n                Permission = S3Permission.WRITE_ACP,\n            };\n\n            // Specify log delivery group as grantee.\n            var grantLogDeliveryGroup = new S3Grant\n            {\n                Grantee = new S3Grantee { URI = \"http://acs.amazonaws.com/groups/s3/LogDelivery\" },\n                Permission = S3Permission.WRITE,\n            };\n\n            // Create a new ACL.\n            var newAcl = new S3AccessControlList\n            {\n                Grants = new List<S3Grant> { grantUsingEmail, grantLogDeliveryGroup },\n                Owner = owner,\n            };\n\n            // Set the new ACL. We're throwing away the response here.\n            _ = await client.PutACLAsync(new PutACLRequest\n            {\n                BucketName = bucketName,\n                Key = keyName,\n                AccessControlList = newAcl,\n            });\n        }\n\n    }\n\n\n```\n\n* For API details, see the following topics in _AWS SDK for .NET API Reference_.\n  \n  * GetBucketAcl\n\n* GetObjectAcl\n\n* PutBucketAcl\n\n* PutObjectAcl\n\nFor a complete list of AWS SDK developer guides and code examples, see Developing with Amazon S3 using the AWS SDKs. This topic also includes information about getting started and details about previous SDK versions.\n"
                    }
                ],
                "requestId": "dad38fc0-815c-45f7-970a-db916cb7f131"
            }
        }
    ]
}
```


| 欄位名稱 | Description | 
| --- | --- | 
|  `records`  |  最上層欄位包含一組提示和回應。  | 
|  `generateAssistantResponseEventRequest`  |  描述使用者在其 IDE 的聊天視窗中輸入的 提示。  | 
|  `prompt`  |  指出使用者在聊天視窗中輸入的 提示。  | 
|  `chatTriggerType`  |  `MANUAL` 表示使用者在聊天視窗中輸入了提示，或在聊天視窗中按一下其中一個建議的問題。`INLINE_CHAT` 表示使用者在主要編碼視窗中的小型輸入畫面輸入了提示。如需內嵌聊天的詳細資訊，請參閱 [與 Amazon Q Developer 進行內嵌聊天](q-in-IDE-inline-chat.md)。  | 
|  `customizationArn`  |  指出套用至聊天之自訂的 Amazon Resource Name (ARN)。此範例中沒有自訂。用於   | 
|  `userId`  |  指出輸入提示之使用者的使用者 ID。  | 
|  `timeStamp`  |  指出使用者輸入提示的日期和時間。時間戳記以國際標準時間 (UTC) 表示。  | 
|  `generateAssistantResponseEventResponse`  |  描述 Amazon Q 產生的回應。  | 
|  `assistantResponse`  |  指出 Amazon Q 對使用者提示提供的回應。  | 
|  `followupPrompts`  |  指出在回應結束時對使用者顯示的後續範例提示。  | 
|  `messageMetadata`  |  描述與回應相關聯的中繼資料。  | 
|  `conversationId`  |  指出回應的對話 ID。對話 ID 會將聊天工作階段中將訊息集結成一組。  | 
|  `utteranceId`  |  指出回應的表達用語 ID。表達用語 ID 是一個標籤，用於區分對話或資料集內的各個提示。  | 
|  `codeReferenceEvents`  |  描述回應中包含的程式碼參考連結。  | 
|  `supplementaryWebLinksEvent`  |  指出在回應結束時對使用者顯示的連結。  | 
|  `requestId`  |  作為事件之唯一識別的回應 ID。  | 

## /dev 日誌範例
<a name="prompt-log-examples-dev"></a>

下列範例顯示隨著使用者在其 IDE 中的 Amazon Q 聊天內輸入 **/dev** 命令，所產生的日誌檔案。

```
{
    "records": [
        {
            "startTaskAssistCodeGenerationEventRequest": {
                "prompt": "write a python application that prints 'hello world!' text to the screen and format it in red bold text",
                "chatTriggerType": "MANUAL",
                "conversationId": "da1c95b6-84e1-46a2-9ef9-fe92f5ee169e",
                "customizationArn": null,
                "userId": "d-92675051d5.b8f1f340-9081-70ad-5fc5-0f37151937a6",
                "timeStamp": "2025-01-13T15:40:27.808027101Z"
            },
            "startTaskAssistCodeGenerationEventResponse": {
                "requestId": "e504f126-7197-4e3c-a046-1a10d5a3f3e0"
            }
        }
    ]
}
```


| 欄位名稱 | Description | 
| --- | --- | 
|  `records`  |  最上層欄位包含一組提示和回應。  | 
|  `startTaskAssistCodeGenerationEventRequest`  |  描述使用者在其 IDE 的聊天視窗中輸入的 **/dev** 提示。  | 
|  `prompt`  |  指出使用者在聊天視窗中輸入的 **/dev** 提示。  | 
|  `chatTriggerType`  |  `MANUAL` 表示使用者在聊天視窗中輸入了提示，或在聊天視窗中按一下其中一個建議的問題。`INLINE_CHAT` 表示使用者在主要編碼視窗中的小型輸入畫面輸入了提示。如需內嵌聊天的詳細資訊，請參閱 [與 Amazon Q Developer 進行內嵌聊天](q-in-IDE-inline-chat.md)。  | 
|  `conversationId`  |  指出回應的對話 ID。對話 ID 會將聊天工作階段中將訊息集結成一組。  | 
|  `customizationArn`  |  指出套用至聊天之自訂的 Amazon Resource Name (ARN)。此範例中沒有自訂。用於   | 
|  `userId`  |  指出輸入提示之使用者的使用者 ID。  | 
|  `timeStamp`  |  指出使用者輸入提示的日期和時間。時間戳記以國際標準時間 (UTC) 表示。  | 
|  `startTaskAssistCodeGenerationEventResponse`  |  描述 Amazon Q 產生的回應。目前不支援記錄對 **/dev** 命令的回應，因此欄位不會包含回應。  | 
|  `assistantResponse`  |  指出 Amazon Q 對使用者提示提供的回應。  | 
|  `requestId`  |  作為事件之唯一識別的回應 ID。  | 