本文說明如何啟用 Gemini for Google Cloud 活動的收集和儲存功能,包括:
- Gemini for Google Cloud 提示和回覆記錄,例如使用者輸入內容、背景資訊和回覆。
- Gemini 記錄中繼資料,例如遙測中繼資料和使用者接受的程式碼行數。 Google Cloud
如要生成 Gemini Code Assist 指標,請參閱「監控 Gemini for Google Cloud 使用情況」。
Gemini for Google Cloud 不會收集或傳送使用者與 Gemini for Google Cloud的任何其他互動 (包括書面意見回饋) 至 Cloud Logging。收集到的資料會傳送至 Cloud Logging 儲存。如要查看這項資料,請搜尋資源類型為 cloudaicompanion.googleapis.com/Instance 的記錄項目。
這項功能不會記錄 Vertex AI 中 Gemini 的提示或回覆。如要在 Vertex AI 中啟用 Gemini 的記錄,請參閱「啟用資料存取稽核記錄」。
主體能否存取記錄,取決於 Identity and Access Management (IAM) 角色。您可以將預先定義的角色授予主體,也可以建立自訂角色。如要進一步瞭解必要權限,請參閱存取權控管。
根據預設,Cloud Logging 會加密靜態儲存的客戶內容。記錄服務會使用金鑰加密金鑰,對儲存在記錄檔儲存空間中的資料進行加密,這個程序稱為「信封式加密」。如要存取記錄資料,必須存取這些金鑰加密金鑰,而 Google 會代您管理這些金鑰,您不必採取任何動作。
貴機構可能需要符合法規、法規遵循或進階加密要求,而預設的靜態加密機制無法滿足這些需求。為滿足貴機構的需求,您可以管理用來保護資料的加密金鑰,而不是由 Google 管理。
如要進一步瞭解如何使用客戶管理的加密金鑰 (CMEK),包括優點和限制,請參閱「客戶管理的加密金鑰」。
限制
Gemini in Google Cloud 記錄的記錄資料僅限於使用者在 IDE 中與 Gemini Code Assist 的互動。
事前準備
-
如要取得查看 Gemini for Google Cloud logs 所需的權限,請要求管理員授予您專案的記錄檢視者 (
roles/logging.viewer) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。 請先查看 Cloud Logging 定價和 Gemini for Google Cloud 定價,再啟用 Gemini for Google Cloud 記錄。
查看 Gemini for Google Cloud 使用者記錄和中繼資料記錄
如要查看 Gemini for Google Cloud 使用者記錄和中繼資料記錄,請執行下列任一操作:
控制台
-
前往 Google Cloud 控制台的「Logs Explorer」頁面:
如果您是使用搜尋列尋找這個頁面,請選取子標題為「Logging」的結果。
- 在工具列中,選取 Google Cloud 控制台專案。
- 在工具列中展開「所有資源」選單,然後選取「Cloud AI Companion Instance」資源。
gcloud
執行下列指令:
gcloud logging read "resource.type=cloudaicompanion.googleapis.com/Instance" --project PROJECT_ID --limit 3
將 PROJECT_ID 替換為要查看 Gemini for Google Cloud 記錄的專案 ID。
API
建立包含下列資訊的 JSON 檔案:
{ "resourceNames": [ "projects/PROJECT_ID" ], "pageSize": 5, "filter": "resource.type: cloudaicompanion.googleapis.com/Instance" }將
PROJECT_ID替換為要查看 Gemini for Google Cloud 記錄的專案 ID。取得驗證權杖:
TOKEN=$(gcloud auth print-access-token)使用
cURL呼叫entries.list方法:curl -X POST --data-binary @JSON_FILE_NAME \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ "https://logging.googleapis.com/v2/entries:list"
將
JSON_FILE_NAME替換為您在上一個步驟中建立的 JSON 檔案路徑。如要進一步瞭解驗證,請參閱「使用 REST 進行驗證」。
回應會傳回一組記錄項目。
Gemini for Google Cloud 記錄
LogEntry 是 Cloud Logging 中的基本資料單位。以下各節列出 LogEntry 中 Gemini for Google Cloud 平台事件的欄位,例如使用者要求和 Gemini for Google Cloud 回覆。
使用者要求數
下表列出使用者要求記錄項目中的欄位:
| 欄位 | 值和備註 |
|---|---|
LogEntry.resource.type |
Gemini for Google Cloud 資源類型:cloudaicompanion.googleapis.com/Instance。 |
LogEntry.resource.labels.resource_container |
使用 Gemini for Google Cloud 的資源容器專屬 ID。 |
LogEntry.resource.labels.location |
使用 Gemini for Google Cloud 的地點。 |
LogEntry.resource.labels.instance_id |
使用 Gemini for Google Cloud 的資源專屬 ID。 |
LogEntry.labels.method |
視呼叫 logEntry 的內容而定,可以是下列其中一種:CompleteTask:例如來自 Gemini Code Assist 或其他 Gemini for Google Cloud 服務的即時通訊要求。GenerateCode:例如生成程式碼的要求,像是 Gemini Code Assist 內的程式碼轉換要求。CompleteCode:例如在 IDE 中工作時完成程式碼的要求,像是 Gemini Code Assist 內的內嵌建議。 |
LogEntry.labels.product |
「服務名稱」 Google Cloud 專用 Gemini。如果 Gemini for Google Cloud 產品是 Gemini Code Assist,則這個值為 code_assist。如果 Gemini for Google Cloud 產品是 Gemini Cloud Assist,則這個值為 cloud_assist。否則,此值為 unknown。 |
LogEntry.labels.request_id |
專屬 ID,用於將要求與回應記錄項目建立關聯。 |
LogEntry.labels.user_id |
啟動這項要求的使用者 ID。 |
LogEntry.jsonPayload |
記錄項目的酬載。 |
LogEntry.logName |
識別記錄。 |
以下範例顯示聊天提示事件的記錄項目:
{
"insertId": "654581e30003b19e340bbd96",
"resource": {
"type": "cloudaicompanion.googleapis.com/Instance",
"labels": {
instance_id: "default"
location: "global"
resource_container: "my-project-id"
}
},
"timestamp": "2023-11-03T23:27:31.242078Z",
"labels": {
"product": "code_assist",
"request_id": "4ea1e265-ea5d-4d11-b3c8-39bad9c96326"
"user_id": "user@company.com"
},
"jsonPayload" : {
@type: "type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.RequestLog"
"taskCompletionRequest":
input: {
messages: [{
author: "USER"
content: "What are some best practices to save cost on my Google Cloud bill?"
}]
preamble: ""
}
}
"logName": "projects/my-project-id/logs/cloudaicompanion.googleapis.com%2Frequest",
"receiveTimestamp": "2023-11-03T23:27:31.255648319Z"
"severity": "INFO"
}
以下範例顯示自動內嵌程式碼建議提示和在程式碼檔案中提示 Gemini Google Cloud 的 RequestLog 項目範例。
內嵌程式碼建議的提示資料會使用 codeCompletionRequest 物件 (如下列範例所示),手動觸發的生成作業則會使用 codeGenerationRequest。
{
"insertId": "654581e30003b19e340bbd96",
"resource": {
"type": "cloudaicompanion.googleapis.com/Instance",
"labels": {
instance_id: "default"
location: "global"
resource_container: "my-project-id"
}
},
"timestamp": "2023-11-03T23:27:31.242078Z",
"labels": {
"product": "code_assist",
"request_id": "4ea1e265-ea5d-4d11-b3c8-39bad9c96326"
"user_id": "user@company.com"
},
"jsonPayload" : {
@type: "type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.RequestLog"
"codeCompletionRequest": {
"input_data_context": {
"additional_context": {
"files": [
{
"language": "go",
"path": "{/path/to/../current-file.go",
"segments": [
{
"content": "...Prefix Text..."
},
{
"content": "...Suffix Text..."
}
],
"state": ["EDITED"]
},
{
"language": "go",
"path": "/path/to/../recent-file.go",
"segments": [
{
"content": "...File Text..."
}
],
"state": ["RECENTLY_OPENED"]
}
]
}
}
}
}
"logName": "projects/my-project-id/logs/cloudaicompanion.googleapis.com%2Frequest",
"receiveTimestamp": "2023-11-03T23:27:31.255648319Z"
"severity": "INFO"
}
服務專員互動記錄
與 Gemini 的部分互動會為單一使用者動作產生多個記錄項目 (要求、回應和中繼資料)。這類互動的例子包括:
- 代理執行涉及使用工具的任務 (例如模型叫用
read_file或replace等內部函式,如記錄範例所示)。 - 代理程式與其他代理程式互動。
要求記錄項目
以下範例顯示啟動服務專員互動的要求記錄項目:
{
"insertId": "qe9xxub2r",
"jsonPayload": {
"taskCompletionRequest": {
"input": {
"messages": [
{
"author": "USER",
"content": "hi can you add one test here\nCurrent File Path:\n```cpp\n/usr/local/google/home/pdec/test.cpp\n```\n\n"
}
],
"preamble": ""
}
},
"@type": "type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.RequestLog"
},
"resource": {
"type": "cloudaicompanion.googleapis.com/Instance",
"labels": {
"resource_container": "my-project-id",
"instance_id": "default",
"location": "global"
}
},
"timestamp": "2025-10-08T10:09:52.225165428Z",
"severity": "INFO",
"labels": {
"request_id": "e60facb1485b17b7",
"client_version": "unknown",
"product": "code_assist",
"method": "CompleteTask",
"user_id": "user@company.com",
"client_name": "cloudcode_cli"
},
"logName": "projects/my-project-id/logs/cloudaicompanion.googleapis.com%2Frequest",
"receiveTimestamp": "2025-10-08T10:09:52.581787548Z"
}
回覆記錄項目
以下範例顯示代理程式互動的回應記錄項目,其中包含多則訊息:
{
"insertId": "qe9xxub2t",
"jsonPayload": {
"@type": "type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.ResponseLog",
"taskCompletionResponse": {
"output": {
"messages": [
{
"content": "**Reading File Contents**\n\nI'm currently focused on reading the contents of `/usr/local/google/home/pdec/test.cpp`. This will inform what kind of test needs to be written and how it should be structured.\n\n\n",
"author": "MODEL"
},
{
"author": "MODEL",
"content": "**File Inspection Begins**\n\nI've initiated the process of reading the test file. My immediate goal is to grasp its existing structure and identify the testing framework, if one exists. This will directly influence the design of the new test case I'll be adding.\n\n\n"
},
{
"author": "MODEL",
"content": "Of course. What is the test about? I'll read the file to understand the context."
},
{
"content": "read_file({\"absolute_path\":\"/usr/local/google/home/pdec/test.cpp\"})",
"author": "MODEL"
}
]
}
}
},
"resource": {
"type": "cloudaicompanion.googleapis.com/Instance",
"labels": {
"resource_container": "my-project-id",
"instance_id": "default",
"location": "global"
}
},
"timestamp": "2025-10-08T10:09:52.227354297Z",
"severity": "INFO",
"labels": {
"product": "code_assist",
"request_id": "e60facb1485b17b7",
"user_id": "user@company.com",
"client_version": "unknown",
"method": "CompleteTask",
"client_name": "cloudcode_cli"
},
"logName": "projects/my-project-id/logs/cloudaicompanion.googleapis.com%2Fresponse",
"receiveTimestamp": "2025-10-08T10:09:52.581787548Z"
}
中繼資料記錄項目
以下範例顯示代理程式互動的中繼資料記錄項目:
{
"insertId": "qe9xxub2s",
"jsonPayload": {
"apiRequest": {},
"clientName": "cloudcode_cli",
"requestId": "e60facb1485b17b7",
"@type": "type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.MetadataLog",
"clientVersion": "unknown"
},
"resource": {
"type": "cloudaicompanion.googleapis.com/Instance",
"labels": {
"location": "global",
"instance_id": "default",
"resource_container": "my-project-id"
}
},
"timestamp": "2025-10-08T10:09:52.226420727Z",
"severity": "INFO",
"labels": {
"method": "CompleteTask",
"product": "code_assist",
"user_id": "user@company.com"
},
"logName": "projects/my-project-id/logs/cloudaicompanion.googleapis.com%2Fmetadata",
"receiveTimestamp": "2025-10-08T10:09:52.581787548Z"
}
以下範例顯示代理程式互動的記錄項目,要求 ID 為 4b66a582bad9cf2c:
要求記錄項目
{
"insertId": "4qvt8nb2k",
"jsonPayload": {
"taskCompletionRequest": {
"input": {
"messages": [
{
"author": "USER",
"content": "FunctionResponse{name: read_file, response: {\"output\":\"#include <iostream>\\n\\n// Function to calculate the greatest common divisor (GCD) of two numbers.\\nint gcd(int a, int b) {\\n if (b == 0) {\\n return a;\\n }\\n return gcd(b, a % b);\\n}\\n\\n// Function to calculate the least common multiple (LCM) of two numbers.\\nint lcm(int a, int b) {\\n return (a * b) / gcd(a, b);\\n}\\n\\n// Function to check if a number is prime.\\nint is_prime(int a) {\\n if (a < 2) {\\n return 0;\\n }\\n for (int i = 2; i * i <= a; ++i) {\\n if (a % i == 0) {\\n return 0;\\n }\\n }\\n return 1;\\n}\\n\\n// Function for extended Euclidean algorithm.\\nint extended_gcd(int a, int b, int &x, int &y) {\\n if (b == 0) {\\n x = 1;\\n y = 0;\\n return a;\\n }\\n int x1, y1;\\n int d = extended_gcd(b, a % b, x1, y1);\\n x = y1;\\n y = x1 - (a / b) * y1;\\n return d;\\n}\\n\\n// Test function\\nvoid run_tests() {\\n // Test gcd\\n if (gcd(10, 15) == 5) {\\n std::cout << \\\"gcd(10, 15) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"gcd(10, 15) failed\\\" << std::endl;\\n }\\n\\n // Test lcm\\n if (lcm(10, 15) == 30) {\\n std::cout << \\\"lcm(10, 15) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"lcm(10, 15) failed\\\" << std::endl;\\n }\\n\\n // Test is_prime\\n if (is_prime(7) == 1) {\\n std::cout << \\\"is_prime(7) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"is_prime(7) failed\\\" << std::endl;\\n }\\n if (is_prime(10) == 0) {\\n std::cout << \\\"is_prime(10) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"is_prime(10) failed\\\" << std::endl;\\n }\\n\\n // Test extended_gcd\\n int x, y;\\n int g = extended_gcd(35, 15, x, y);\\n if (g == 5 && 35 * x + 15 * y == g) {\\n std::cout << \\\"extended_gcd(35, 15) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"extended_gcd(35, 15) failed\\\" << std::endl;\\n }\\n\\n // Test is_prime with 1\\n if (is_prime(1) == 0) {\\n std::cout << \\\"is_prime(1) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"is_prime(1) failed\\\" << std::endl;\\n }\\n\\n // Test is_prime with 9\\n if (is_prime(9) == 0) {\\n std::cout << \\\"is_prime(9) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"is_prime(9) failed\\\" << std::endl;\\n }\\n\\n // Test is_prime with 13\\n if (is_prime(13) == 1) {\\n std::cout << \\\"is_prime(13) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"is_prime(13) failed\\\" << std::endl;\\n }\\n\\n // Test lcm with 7 and 9\\n if (lcm(7, 9) == 63) {\\n std::cout << \\\"lcm(7, 9) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"lcm(7, 9) failed\\\" << std::endl;\\n }\\n\\n // Test gcd with 12 and 18\\n if (gcd(12, 18) == 6) {\\n std::cout << \\\"gcd(12, 18) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"gcd(12, 18) failed\\\" << std::endl;\\n }\\n\\n // Test gcd with two primes\\n if (gcd(7, 13) == 1) {\\n std::cout << \\\"gcd(7, 13) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"gcd(7, 13) failed\\\" << std::endl;\\n }\\n\\n // Test is_prime with 97\\n if (is_prime(97) == 1) {\\n std::cout << \\\"is_prime(97) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"is_prime(97) failed\\\" << std::endl;\\n }\\n\\n // Test extended_gcd with 48 and 18\\n int x2, y2;\\n int g2 = extended_gcd(48, 18, x2, y2);\\n if (g2 == 6 && 48 * x2 + 18 * y2 == g2) {\\n std::cout << \\\"extended_gcd(48, 18) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"extended_gcd(48, 18) failed\\\" << std::endl;\\n }\\n\\n // Test gcd with 27 and 18\\n if (gcd(27, 18) == 9) {\\n std::cout << \\\"gcd(27, 18) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"gcd(27, 18) failed\\\" << std::endl;\\n }\\n // test 999 and 123\\n if (gcd(999, 123) == 3) {\\n std::cout << \\\"gcd(999, 123) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"gcd(999, 123) failed\\\" << std::endl;\\n }\\n \\n \\n}\\n\\nint main() {\\n run_tests();\\n return 0;\\n}\"}}"
}
],
"preamble": ""
}
},
"@type": "type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.RequestLog"
},
"resource": {
"type": "cloudaicompanion.googleapis.com/Instance",
"labels": {
"resource_container": "my-project-id",
"instance_id": "default",
"location": "global"
}
},
"timestamp": "2025-10-08T10:10:03.457717366Z",
"severity": "INFO",
"labels": {
"request_id": "4b66a582bad9cf2c",
"method": "CompleteTask",
"client_version": "unknown",
"product": "code_assist",
"client_name": "cloudcode_cli",
"user_id": "user@company.com"
},
"logName": "projects/my-project-id/logs/cloudaicompanion.googleapis.com%2Frequest",
"receiveTimestamp": "2025-10-08T10:10:03.606059154Z"
}
回應記錄項目
{
"insertId": "4qvt8nb2m",
"jsonPayload": {
"taskCompletionResponse": {
"output": {
"messages": [
{
"author": "MODEL",
"content": "**Testing the functions**\\n\\nI'm focusing on adding a new test case to `test.cpp`. The existing `run_tests` function is a great starting point. I'm considering which function to test further – maybe `extended_gcd`? I'll review the current tests for that function and then devise a new test scenario to add.\\n\\n\\n"
},
{
"author": "MODEL",
"content": "**Evaluating LCM Test**\\n\\nI've finalized the new test case for the `lcm` function within the `test.cpp` file. I'm adding a test for `lcm(12, 18)` to confirm the result is 36. I plan to use the `replace` command to inject this new test directly before the closing brace of the `run_tests` function. I've identified a unique line in `test.cpp` as the anchor for replacement.\\n\\n\\n"
},
{
"author": "MODEL",
"content": "**Inserting the new test**\\n\\nI've created a test case for `lcm(12, 18)`, confirming the expected result of 36. To implement this, I'm targeting the `run_tests` function. I'll use the `replace` command and will search the end of the `run_tests` function to inject the new test, right before the closing brace. I'm ready to implement this and confirm that it passes.\\n\\n\\n"
},
{
"author": "MODEL",
"content": "I've reviewed the file. I'll add a test case for the `lcm` function with inputs 12 and 18."
},
{
"content": "replace({\"file_path\":\"/usr/local/google/home/pdec/test.cpp\",\"instruction\":\"add a test for the lcm function with 12 and 18\",\"new_string\":\" // test 999 and 123\\n if (gcd(999, 123) == 3) {\\n std::cout << \\\"gcd(999, 123) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"gcd(999, 123) failed\\\" << std::endl;\\n }\\n \\n // Test lcm with 12 and 18\\n if (lcm(12, 18) == 36) {\\n std::cout << \\\"lcm(12, 18) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"lcm(12, 18) failed\\\" << std::endl;\\n }\\n \\n}\",\"old_string\":\" // test 999 and 123\\n if (gcd(999, 123) == 3) {\\n std::cout << \\\"gcd(999, 123) passed\\\" << std::endl;\\n } else {\\n std::cout << \\\"gcd(999, 123) failed\\\" << std::endl;\\n }\\n \\n \\n}\"})",
"author": "MODEL"
}
]
}
},
"@type": "type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.ResponseLog"
},
"resource": {
"type": "cloudaicompanion.googleapis.com/Instance",
"labels": {
"location": "global",
"resource_container": "my-project-id",
"instance_id": "default"
}
},
"timestamp": "2025-10-08T10:10:03.461137399Z",
"severity": "INFO",
"labels": {
"client_name": "cloudcode_cli",
"client_version": "unknown",
"method": "CompleteTask",
"request_id": "4b66a582bad9cf2c",
"product": "code_assist",
"user_id": "user@company.com"
},
"logName": "projects/my-project-id/logs/cloudaicompanion.googleapis.com%2Fresponse",
"receiveTimestamp": "2025-10-08T10:10:03.606059154Z"
}
中繼資料記錄項目
{
"insertId": "4qvt8nb2l",
"jsonPayload": {
"clientVersion": "unknown",
"apiRequest": {},
"clientName": "cloudcode_cli",
"requestId": "4b66a582bad9cf2c",
"@type": "type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.MetadataLog"
},
"resource": {
"type": "cloudaicompanion.googleapis.com/Instance",
"labels": {
"resource_container": "my-project-id",
"location": "global",
"instance_id": "default"
}
},
"timestamp": "2025-10-08T10:10:03.459902984Z",
"severity": "INFO",
"labels": {
"product": "code_assist",
"user_id": "user@company.com",
"method": "CompleteTask"
},
"logName": "projects/my-project-id/logs/cloudaicompanion.googleapis.com%2Fmetadata",
"receiveTimestamp": "2025-10-08T10:10:03.606059154Z"
}
Gemini for Google Cloud 回覆
下表列出 Gemini for Google Cloud 回應欄位和說明:
| 欄位 | 值和備註 |
|---|---|
LogEntry.resource.type |
Gemini for Google Cloud 資源類型:cloudaicompanion.googleapis.com/Instance。 |
LogEntry.resource.labels.resource_container |
使用 Gemini for Google Cloud 的資源容器專屬 ID。 |
LogEntry.resource.labels.location |
使用 Gemini for Google Cloud 的地點。 |
LogEntry.resource.labels.instance_id |
使用 Gemini for Google Cloud 的資源專屬 ID。 |
LogEntry.labels.method |
視呼叫 logEntry 的內容而定,可以是下列其中一種:CompleteTask:例如來自 Gemini Code Assist 或其他 Gemini for Google Cloud 服務的即時通訊要求。GenerateCode:例如生成程式碼的要求,像是 Gemini Code Assist 內的程式碼轉換要求。CompleteCode:例如在 IDE 中工作時完成程式碼的要求,像是 Gemini Code Assist 內的內嵌建議。 |
LogEntry.labels.product |
「服務名稱」 Google Cloud 專用 Gemini。如果 Gemini for Google Cloud 產品是 Gemini Code Assist,則這個值為 code_assist。如果 Gemini for Google Cloud 產品是 Gemini Cloud Assist,則這個值為 cloud_assist。否則,此值為 unknown。 |
LogEntry.labels.request_id |
專屬 ID,用於將要求與回應記錄項目建立關聯。 |
LogEntry.labels.user_id |
啟動這項要求的使用者 ID。 |
LogEntry.jsonPayload |
記錄項目的酬載。用來生成回覆的任何來源引用資料都會以 attribution_context 形式納入這個物件。 |
LogEntry.logName |
識別記錄。 |
Gemini for Google Cloud 中繼資料記錄
如要產生中繼資料記錄,請為 VS Code 和 IntelliJ 擴充功能啟用 Gemini Code Assist 擴充功能遙測設定。此外,如果是使用 VS Code,也必須啟用全域遙測資料收集設定。
Gemini for Google Cloud 中繼資料記錄的結構與 Gemini for Google Cloud 記錄相同,但指定了不同的欄位。下表列出使用者要求記錄項目中的欄位:
| 欄位 | 值和備註 |
|---|---|
LogEntry.@type |
Gemini for Google Cloud metadata resource type:type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.MetadataLog。 |
LogEntry.labels.method |
如果是中繼資料記錄,這個標籤值為 Export.Metrics。 |
LogEntry.labels.product |
「服務名稱」 Google Cloud 專用 Gemini。如果 Gemini for Google Cloud 產品是 Gemini Code Assist,則這個值為 code_assist。如果 Gemini for Google Cloud 產品是 Gemini Cloud Assist,這個值就是 cloud_assist。否則,此值為 unknown。 |
LogEntry.labels.user_id |
啟動這項要求的使用者 ID。 |
LogEntry.jsonPayload |
指出是 codeExposure 事件還是 code.Acceptance 事件。codeExposure 事件表示向使用者顯示程式碼建議。code.Acceptance 事件表示使用者接受了某些內容,例如輸入、按 Tab 鍵或完全接受。 |
LogEntry.jsonPayload.clientName |
IDE 名稱,例如 CloudCodeVscode。 |
LogEntry.jsonPayload.clientVersion |
IDE 版本號碼。 |
LogEntry.jsonPayload.codeAcceptance |
僅適用於 VS Code 和 IntelliJ IDE,表示使用者已接受部分建議,例如輸入、按下 Tab 鍵或完全接受建議。也包含下列欄位: |
LogEntry.jsonPayload.codeExposure |
僅適用於 VS Code 和 IntelliJ IDE,表示系統向使用者顯示程式碼建議。也包含下列欄位: |
LogEntry.jsonPayload.chatExposure |
表示使用者看到聊天室回覆。也包含下列欄位: |
LogEntry.jsonPayload.chatAcceptance |
表示使用者在聊天回覆中的程式碼區塊上,執行了某項接受事件。也包含下列欄位:
|
以下範例顯示 codeExposure 記錄項目:
{
insertId: "whfrqgc1gj"
jsonPayload: {
@type: "type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.MetadataLog"
clientName: "CloudCodeVscode"
clientVersion: "1.93.1"
codeExposure: {
originalRequestId: "cac019824a0b25ba"
programmingLanguage: "python"
}
requestId: "0c5178fe-446f-4ab6-b996-520dec100cf8"
}
labels: {
method: "Export.Metrics"
product: "code_assist"
user_id: "user@company.com"
}
logName: "projects/my-project-id/logs/cloudaicompanion.googleapis.com%2Fmetadata"
receiveTimestamp: "2025-02-03T23:34:35.662837985Z"
resource: {
labels: {
instance_id: "default"
location: "global"
resource_container: "my-project-id"
}
type: "cloudaicompanion.googleapis.com/Instance"
}
severity: "INFO"
timestamp: "2025-02-03T23:34:35.021564463Z"
}
以下提供 codeAcceptance 記錄項目範例:
{
insertId: "whfrqgc1gk"
jsonPayload: {
@type: "type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.MetadataLog"
clientName: "CloudCodeVscode"
clientVersion: "1.93.1"
codeAcceptance: {
linesCount: 2
originalRequestId: "cac019824a0b25ba"
programmingLanguage: "python"
}
requestId: "ddf11040-c315-452e-b7cd-928c3f97984e"
}
labels: {
method: "Export.Metrics"
product: "code_assist"
user_id: "user@company.com"
}
logName: "projects/my-project-id/logs/cloudaicompanion.googleapis.com%2Fmetadata"
receiveTimestamp: "2025-02-03T23:34:37.632662272Z"
resource: {
labels: {
instance_id: "default"
location: "global"
resource_container: "my-project-id"
}
type: "cloudaicompanion.googleapis.com/Instance"
}
severity: "INFO"
timestamp: "2025-02-03T23:34:36.778692483Z"
}
以下範例顯示 chatAcceptance 記錄項目:
{
"insertId": "1oru1grbow",
"jsonPayload": {
"clientVersion": "1.103.2",
"requestId": "32a0b0b8c967d8e8",
"clientName": "CloudCodeVscode",
"chatAcceptance": {
"interactionType": "ACCEPT_CODE_BLOCK",
"programmingLanguage": "go",
"linesCount": "15",
"originalRequestId": "75f7c41e63162567"
},
"@type": "type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.MetadataLog"
},
"resource": {
"type": "cloudaicompanion.googleapis.com/Instance",
"labels": {
"resource_container": "my-project-id",
"instance_id": "default",
"location": "global"
}
},
"timestamp": "2025-08-25T09:34:01.240377123Z",
"severity": "INFO",
"labels": {
"product": "code_assist",
"method": "Export.Metrics",
"user_id": "user@company.com"
},
"logName": "projects/my-project-id/logs/cloudaicompanion.googleapis.com%2Fmetadata",
"receiveTimestamp": "2025-08-25T09:34:01.704925625Z"
}
以下範例顯示 chatExposure 記錄項目:
{
insertId: "3diaj2c208"
jsonPayload: {
@type: "type.googleapis.com/google.cloud.cloudaicompanion.logging.v1.MetadataLog"
clientName: "CloudCodeVscode"
clientVersion: "1.93.1"
chatExposure: {
originalRequestId: "cac019824a0b25ba"
}
requestId: "0c5178fe-446f-4ab6-b996-520dec100cf8"
}
labels: {
method: "Export.Metrics"
product: "code_assist"
user_id: "user@company.com"
}
logName: "projects/my-project-id/logs/cloudaicompanion.googleapis.com%2Fmetadata"
receiveTimestamp: "2025-02-03T23:34:35.662837985Z"
resource: {
labels: {
instance_id: "default"
location: "global"
resource_container: "my-project-id"
}
type: "cloudaicompanion.googleapis.com/Instance"
}
severity: "INFO"
timestamp: "2025-02-03T23:34:35.021564463Z"
}
計算接受率
以下章節說明如何使用 Gemini Code Assist 中繼資料記錄,計算程式碼建議接受率、即時通訊回覆接受率,以及總合併接受率。
計算程式碼接受率
如要使用 Gemini Code Assist 中繼資料記錄計算程式碼接受率,請找出事件中 codeAcceptance.originalRequestId 的不重複 ID 總數,然後除以事件中 codeExposure.originalRequestId 的不重複 ID 總數。
您可以使用相應的中繼資料記錄事件欄位,依程式設計語言和使用者進一步調整這項計算。
計算即時通訊接受率
如要使用 Gemini Code Assist 中繼資料記錄計算即時通訊接受率,請找出 chatAcceptance.originalRequestId 事件的不重複 ID 總數,然後除以 chatExposure.originalRequestId 事件的不重複 ID 總數。
您可以使用相應的中繼資料記錄事件欄位,依程式設計語言和使用者進一步調整這項計算。
計算總接受率
如要使用 Gemini Code Assist 中繼資料記錄計算總接受率,請找出接受事件總數,然後除以曝光事件總數:
總接受率 = 接受的事件總數 ÷ 曝光事件總數
- 接受的事件總數:來自事件的不重複 ID 總數 (含
codeAcceptance.originalRequestId) 加上來自事件的不重複 ID 總數 (含chatAcceptance.originalRequestId)。 - 曝光事件總數:來自
codeExposure.originalRequestId事件的不重複 ID 總數,加上來自chatExposure.originalRequestId事件的不重複 ID 總數。
這項公式提供的接受率,反映了所有 Gemini Code Assist 功能中,任何建議獲得接受的整體機率。
計算接受的程式碼行數
以下章節說明如何使用 Gemini Code Assist 中繼資料記錄,計算接受程式碼建議的程式碼行數、接受對話的程式碼行數,以及接受的程式碼總行數。
計算接受的程式碼行數
如要計算接受的程式碼行數,請找出每個不重複 codeAcceptance.originalRequestId 的 codeAcceptance.linesCount 最大值。接著加總這些最大值,計算出接受的程式碼總行數。
您可以使用相應的中繼資料記錄事件欄位,依程式設計語言和使用者進一步調整這項計算。
計算從對話接受的程式碼行數
如要計算從對話接受的程式碼行數,請找出每個不重複 chatAcceptance.originalRequestId 的 chatAcceptance.linesCount 欄位值。然後加總這些最大值,計算接受的總行數。
計算接受的程式碼行數總計
如要使用 Gemini Code Assist 中繼資料記錄計算接受的總行數,請將「接受的程式碼行數」和「接受的對話程式碼行數」相加。
後續步驟
- 瞭解如何在 Google Cloud 中查看、分析及監控記錄檔。
- 進一步瞭解如何監控 Gemini for Google Cloud 的用量。