Configure Gemini Code Assist Standard and Enterprise logging | Gemini for Google Cloud | Google Cloud Documentation
Skip to main content Configure Gemini Code Assist Standard and Enterprise logging Stay organized with collections Save and categorize content based on your preferences. Gemini Code Assist Standard and Enterprise logging lets you track developer interactions and usage across your projects. This document describes how to use the Google Cloud console or the REST API to configure logging for Gemini Code Assist. Limitations Gemini Code Assist Standard and Enterprise log data recording is limited to user interactions with Gemini Code Assist within an IDE.
By default, Gemini Code Assist logs are collected on a per-project basis. For instructions on how to configure a centralized project to collect logs from multiple projects, see Set up multi-project logging . Gemini Code Assist on GitHub doesn't support logging with Cloud Logging. Gemini Code Assist logs record a combined token count ( totalTokenCount ) for each chat and agent request ( CompleteTask ), and you can attribute it to a user with the labels.user_id label.
This count appears in the RequestLog.metadata.totalTokenCount , ResponseLog.metadata.totalTokenCount , and MetadataLog.apiRequest.totalTokenCount fields. Logs for code completion and code generation requests ( CompleteCode and GenerateCode ) and metadata logs that record telemetry events, such as codeExposure , codeAcceptance , chatExposure , and chatAcceptance events, don't include token counts. Logs and Cloud Monitoring metrics don't record separate prompt and response token counts.
To view aggregated token usage for your project, see Token and quota metrics . Before you begin Verify that your Google Cloud project is attached to a billing account. Verify IAM permissions To configure Gemini Code Assist logging, you need specific IAM permissions. To follow the principle of least privilege, grant a custom role that contains only the necessary permissions. Ask your administrator to create a custom role that includes the following permissions: serviceusage.services.enable —to enable APIs for your project. cloudaicompanion.loggingSettings.create —to create logging settings. cloudaicompanion.loggingSettings.get —to view logging settings. cloudaicompanion.loggingSettings.list —to list logging settings. cloudaicompanion.loggingSettings.update —to update logging settings. cloudaicompanion.loggingSettingBindings.create —to bind logging settings to a project. cloudaicompanion.loggingSettingBindings.get —to view logging setting bindings. cloudaicompanion.loggingSettingBindings.list —to list logging setting bindings.
Alternatively, you can grant the predefined roles Gemini for Google Cloud Settings Admin ( roles/cloudaicompanion.settingsAdmin ) and Service Usage Admin ( roles/serviceusage.serviceUsageAdmin ). However, these roles include permissions to configure other Gemini administrator settings in Google Cloud and manage service usage in Google Cloud, which might be more than needed to configure logging settings. Configure Gemini Code Assist logging The following sections provide steps required to enable the collection and storage of Gemini Code Assist Standard and Enterprise activity in Cloud Logging, including: Gemini Code Assist Standard and Enterprise prompts and response logs, such as user input, contextual information, and responses.
Gemini Code Assist Standard and Enterprise metadata logs, such as telemetry metadata and lines of code accepted by the user. For more details on both types of logs, see View Gemini Code Assist logs . Enable logging for Gemini Code Assist in a project Select one of the following options: Console Verify that you have enabled the Cloud Logging API in the project. In the Google Cloud console, go to the Admin for Gemini page.
Go to Admin for Gemini Click Settings in the left navigation menu. (Optional) Click Logging for Code Assist metadata to record the metadata generated by users of Gemini Code Assist Standard and Enterprise in the project. (Optional) Click Logging for Code Assist prompts and responses to record the prompts and responses generated by users of Gemini Code Assist Standard and Enterprise in the project. Click Save Changes .
API To enable logging for Gemini Code Assist Standard and Enterprise, use the loggingSettings resource to define the logging settings you want, and use the loggingSettings.settingBindings resource to bind the settings to a project: Verify that you have enabled the Cloud Logging API in the project. Create the setting and a setting-specific value: Obtain the token: TOKEN=$(gcloud auth print-access-token) Enable Gemini Code Assist Standard and Enterprise logs.
Users logs and metadata logs are enabled with the log_prompts_and_responses and log_metadata fields, respectively. If you don't want to enable one of the fields, exclude it from the request. Run the following command to create the setting: curl -X POST \ -H "Authorization: Bearer $TOKEN" \ -H 'Content-Type: application/json' \ -d '{ "log_prompts_and_responses": true, "log_metadata": true, } ' \ "https://cloudaicompanion.googleapis.com/v1/projects/ CONTAINER_PROJECT_NAME /locations/global/loggingSettings?logging_setting_id= LOGS_SETTING_ID " Replace the following: CONTAINER_PROJECT_NAME : Enter the project ID of the project where the binding resource is stored.
This is the parent project of the binding. LOGS_SETTING_ID : Enter a unique setting name, such as gcalm . If the command succeeds, it returns a response body that shows the log_prompts_and_responses and log_metadata set to true : { "name": "projects/ CONTAINER_PROJECT_NAME /locations/global/loggingSettings/ LOGS_SETTING_ID ", "createTime": "2025-01-23T15:22:49.717166932Z", "updateTime": "2025-01-23T15:22:49.717166932Z", "log_prompts_and_responses": true, "log_metadata": true } Run the following command to create the Gemini Code Assist Standard and Enterprise logs setting binding: curl -X POST \ -H "Authorization: Bearer $TOKEN" \ -H 'Content-Type: application/json' \ -d '{ "target": "projects/ TARGET_PROJECT_NAME " }' \ "https://cloudaicompanion.googleapis.com/v1/projects/ CONTAINER_PROJECT_NAME /locations/global/loggingSettings/ LOGS_SETTING_ID /settingBindings?setting_binding_id= LOGS_BINDING_ID " Replace the following: TARGET_PROJECT_NAME : Enter the target project to which the binding should be bound.
This is often the same as the container project. However, you can bind a setting to multiple projects so that the setting resource doesn't have to be duplicated. LOGS_BINDING_ID : Use the same LOGS_SETTING_ID when you created the setting, but append it with b1 . For example, use gcalmb1 . If the command succeeds, it returns the operation metadata in the following format: { "name": "projects/<var>CONTAINER_PROJECT_NAME</var>/locations/global/operations/operation-1737646069712-62c6140bb04bb-49261230-43701daf", "metadata": { "@type": "type.googleapis.com/google.cloud.cloudaicompanion.v1.OperationMetadata", "createTime": "2025-01-23T15:27:50.076075570Z", "target": "projects/<var>TARGET_PROJECT_NAME</var>/locations/global/loggingSettings/<var>LOGS_SETTING_ID</var>/settingBindings/<var>LOGS_BINDING_ID</var>", "verb": "create", "requestedCancellation": false, "apiVersion": "v1" }, "done": false } Disable logging for Gemini Code Assist in a project Select one of the following options: Console In the Google Cloud console, go to the Admin for Gemini page.
Go to Admin for Gemini Click Settings in the left navigation menu. Click Logging for Code Assist metadata to turn off recording the metadata from the usage of Gemini Code Assist Standard and Enterprise in the project. Click Save Changes . API To disable logging for Gemini Code Assist Standard and Enterprise, use the loggingSetting method. Create the setting and a setting-specific value: Obtain the token: TOKEN=$(gcloud auth print-access-token) Run the following command to disable the Gemini Code Assist Standard and Enterprise logs settings: curl -X POST \ -H "Authorization: Bearer $TOKEN" \ -H 'Content-Type: applicati
The rest of this page is on the live site.