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](https://docs.cloud.google.com/gemini/docs/configure-logging.md.txt#multi-project-logging).

- [Gemini Code Assist on GitHub](https://developers.google.com/gemini-code-assist/docs/review-repo-code)
  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](https://docs.cloud.google.com/gemini/docs/codeassist/monitor-gemini-code-assist.md.txt#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](https://docs.cloud.google.com/iam/docs/creating-custom-roles.md.txt) 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**](https://docs.cloud.google.com/iam/docs/roles-permissions/cloudaicompanion.md.txt#cloudaicompanion.settingsAdmin)
(`roles/cloudaicompanion.settingsAdmin`) and
[**Service Usage Admin**](https://docs.cloud.google.com/iam/docs/understanding-roles#service-usage-roles)
(`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](https://docs.cloud.google.com/gemini/docs/log-gemini.md.txt).

### Enable logging for Gemini Code Assist in a project

Select one of the following options:

### Console

1. Verify that you have enabled the
   [**Cloud Logging**](https://console.cloud.google.com/marketplace/product/google/logging.googleapis.com)
   API in the project.

2. In the Google Cloud console, go to the **Admin for Gemini** page.

   [Go to Admin for Gemini](https://console.cloud.google.com/gemini-admin)
3. Click **Settings** in the left navigation menu.

4. (Optional) Click **Logging for Code Assist metadata** to record the
   metadata generated by users of Gemini Code Assist
   Standard and Enterprise in the project.

5. (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.

6. 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:

1. Verify that you have enabled the
   [**Cloud Logging**](https://docs.cloud.google.com/logging/docs/reference/v2/rest.md.txt) API
   in the project.

2. Create the setting and a setting-specific value:

   1. Obtain the token:

          TOKEN=$(gcloud auth print-access-token)

3. 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.

   1. 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
          }

   2. 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

1. In the Google Cloud console, go to the **Admin for Gemini** page.

   [Go to Admin for Gemini](https://console.cloud.google.com/gemini-admin)
2. Click **Settings** in the left navigation menu.

3. 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.

4. Click **Save Changes**.

### API

To disable logging for Gemini Code Assist Standard and
Enterprise, use the `loggingSetting` method.

1. Create the setting and a setting-specific value:

   1. Obtain the token:

          TOKEN=$(gcloud auth print-access-token)

2. 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: application/json' \
           -d '{
             "log_prompts_and_responses": false,
             "log_metadata": false,
             } ' \
           "https://cloudaicompanion.googleapis.com/v1/projects/CONTAINER_PROJECT_NAME/locations/global/loggingSettings?logging_metadata_id=LOGS_SETTING_ID"

   Replace the following:
   - `CONTAINER_PROJECT_NAME`: Enter the parent project ID.
   - `LOGS_SETTING_ID`: Enter the existing
     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 `false`:

         {
           "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": false,
           "log_metadata": false
         }

### Set up multi-project logging

You can use logs from Gemini Code Assist to create metrics and
dashboards for monitoring per-project usage. If your organization has multiple
projects, you can configure a centralized logging project to collect logs from
multiple projects and generate dashboards across those projects.

#### Create a centralized logging project

This project will serve as a hub for logs from your other projects.

1. In the Google Cloud console, go to the **Project creation** page.

   [Go to Create Project](https://console.cloud.google.com/projectcreate)
2. In the **New Project** window, enter values for the following fields:

   - **Project name**: a name for your centralized logging project.
   - **Billing account**: select a billing account.
   - **Organization**: select your organization. A centralized project can only collect logs from projects in the same organization.
   - **Location**: select a location.
3. Click **Create**.

#### Configure log sinks

To direct logs to the centralized project, configure log sinks in each of the
individual projects that you want to collect logs from.

> [!NOTE]
> **Note:** Ensure that logs are sent to the `_Default` bucket in the `global` region.

To configure log sinks for each project, do the following:

1. In the Google Cloud console, switch to a project that you want to collect logs from.
2. Go to the **Log Router** page:

   [Go to Log Router](https://console.cloud.google.com/logs/router)
3. Click **Create sink**.

4. For **Sink details** , enter a name and description for the sink, and then
   click **Next**.

5. For **Sink destination**, do the following:

   1. In the **Select sink service** menu, select **Logging bucket**.
   2. In the **Log bucket** menu, select **Use log bucket in another project**.
   3. In the **Sink destination** field, enter the following:

          logging.googleapis.com/projects/CENTRALIZED_PROJECT_ID/locations/global/buckets/_Default

      Replace `CENTRALIZED_PROJECT_ID` with the project ID of
      the centralized logging project that you created.
   4. Click **Next**.

6. For **Choose logs to include in sink** , build an inclusion filter by entering
   the following in the **Inclusion filter** field:

       resource.type="cloudaicompanion.googleapis.com/Instance"

7. Click **Next**.

8. For **Choose logs to filter out of sink** , leave the exclusion filter blank and click **Create sink**.

9. After the sink is created, in **Log Router** page, find the sink that you
   created.

10. In the **Writer Identity** column, copy the full service account email
    address.

#### Configure access

To grant access for your sink to write logs to the centralized project, do the
following:

1. In the Google Cloud console, switch to the centralized project that you created.
2. Go to the **IAM** page:

   [Go to IAM](https://console.cloud.google.com/iam-admin/iam)
3. Click **Grant access**.

4. In the **New principals** field, paste the service account email address that
   you copied in the preceding section.

5. Click **Add another role**.

6. Search for and select the **Logs Bucket Writer** role
   (`roles/logging.bucketWriter`).

7. Click **Save**.

#### Create a dashboard in centralized project

After you configure your centralized project to receive logs, you can create a
dashboard to view metrics from multiple projects:

1. In the Google Cloud console, go to **Monitoring** \> **Dashboards**:

   [Go to Dashboards](https://console.cloud.google.com/monitoring/dashboards)
2. Click **Create dashboard**.

3. In the toolbar, click **Settings** , and then select **JSON** \> **JSON Editor**.

4. In JSON Editor, paste the following code:

   ```json
   {
     "displayName": "Multi-Project Gemini Code Assist Overview from Metadata Logs",
     "dashboardFilters": [],
     "labels": {},
     "mosaicLayout": {
       "columns": 48,
       "tiles": [
         {
           "height": 16,
           "width": 24,
           "widget": {
             "title": "Active Users by Day",
             "id": "",
             "xyChart": {
               "chartOptions": {
                 "displayHorizontal": false,
                 "mode": "COLOR",
                 "showLegend": false
               },
               "dataSets": [
                 {
                   "breakdowns": [],
                   "dimensions": [
                     {
                       "column": "event_date",
                       "columnType": "DATE",
                       "maxBinCount": 0,
                       "sortColumn": "event_date",
                       "sortOrder": "SORT_ORDER_ASCENDING",
                       "timeBinSize": "0s",
                       "xMax": 0,
                       "xMin": 0
                     }
                   ],
                   "legendTemplate": "",
                   "measures": [
                     {
                       "aggregationFunction": {
                         "parameters": [],
                         "type": "average"
                       },
                       "column": "DAU"
                     }
                   ],
                   "plotType": "LINE",
                   "targetAxis": "Y1",
                   "timeSeriesQuery": {
                     "opsAnalyticsQuery": {
                       "queryExecutionRules": {
                         "useReservedSlots": false
                       },
                       "queryHandle": "",
                       "savedQueryId": "",
                       "sql": "SELECT\n COUNT (DISTINCT JSON_VALUE(labels, '$.user_id')) as DAU, CAST(timestamp AS DATE) AS event_date\nFROM\n `CENTRALIZED_PROJECT_ID.global._Default._Default`\nWHERE\n JSON_VALUE(labels, '$.user_id') is not NULL\n AND (\n   JSON_VALUE(json_payload, '$.chatExposure.originalRequestId') is not NULL\n   OR JSON_VALUE(json_payload, '$.codeAcceptance.originalRequestId') is not NULL\n   OR JSON_VALUE(json_payload, '$.codeExposure.originalRequestId') is not NULL\n )\n AND resource.type = \"cloudaicompanion.googleapis.com/Instance\"\n AND (JSON_VALUE(resource.labels, '$.resource_container') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2') or JSON_VALUE(resource.labels, '$.project_id') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2'))\nGROUP BY\nevent_date\nORDER BY\nevent_date\n"
                     },
                     "outputFullDuration": false,
                     "unitOverride": ""
                   }
                 }
               ],
               "thresholds": [],
               "yAxis": {
                 "label": "",
                 "scale": "LINEAR"
               }
             }
           }
         },
         {
           "xPos": 24,
           "height": 16,
           "width": 24,
           "widget": {
             "title": "Acceptance Rate by Day",
             "id": "",
             "xyChart": {
               "chartOptions": {
                 "displayHorizontal": false,
                 "mode": "COLOR",
                 "showLegend": false
               },
               "dataSets": [
                 {
                   "breakdowns": [],
                   "dimensions": [
                     {
                       "column": "exposures_date",
                       "columnType": "DATE",
                       "maxBinCount": 0,
                       "sortColumn": "exposures_date",
                       "sortOrder": "SORT_ORDER_ASCENDING",
                       "timeBinSize": "0s",
                       "xMax": 0,
                       "xMin": 0
                     }
                   ],
                   "legendTemplate": "",
                   "measures": [
                     {
                       "aggregationFunction": {
                         "parameters": [],
                         "type": "average"
                       },
                       "column": "acceptance_rate"
                     }
                   ],
                   "plotType": "LINE",
                   "targetAxis": "Y1",
                   "timeSeriesQuery": {
                     "opsAnalyticsQuery": {
                       "queryExecutionRules": {
                         "useReservedSlots": false
                       },
                       "queryHandle": "",
                       "savedQueryId": "",
                       "sql": "SELECT\nexposures_date,\nacceptances_count / exposures_count as acceptance_rate\nFROM\n(\nSELECT\nCOUNT (DISTINCT JSON_VALUE(json_payload, '$.codeAcceptance.originalRequestId')) as acceptances_count, CAST(timestamp AS DATE) AS acceptances_date\nFROM\n`CENTRALIZED_PROJECT_ID.global._Default._Default`\nWHERE\nJSON_VALUE(json_payload, '$.codeAcceptance.originalRequestId') is not NULL\nAND resource.type = \"cloudaicompanion.googleapis.com/Instance\"\nAND (JSON_VALUE(resource.labels, '$.resource_container') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2') or JSON_VALUE(resource.labels, '$.project_id') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2'))\nGROUP BY\nacceptances_date\n) as acceptances\nJOIN\n(\nSELECT\nCOUNT (DISTINCT JSON_VALUE(json_payload, '$.codeExposure.originalRequestId')) as exposures_count, CAST(timestamp AS DATE) AS exposures_date\nFROM\n`CENTRALIZED_PROJECT_ID.global._Default._Default`\nWHERE\nJSON_VALUE(json_payload, '$.codeExposure.originalRequestId') is not NULL\nAND resource.type = \"cloudaicompanion.googleapis.com/Instance\"\nAND (JSON_VALUE(resource.labels, '$.resource_container') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2') or JSON_VALUE(resource.labels, '$.project_id') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2'))\nGROUP BY\nexposures_date\n) as exposures\nON\nexposures.exposures_date = acceptances.acceptances_date\nORDER BY\nexposures_date ASC"
                     },
                     "outputFullDuration": false,
                     "unitOverride": ""
                   }
                 }
               ],
               "thresholds": [],
               "yAxis": {
                 "label": "",
                 "scale": "LINEAR"
               }
             }
           }
         },
         {
           "yPos": 16,
           "height": 16,
           "width": 24,
           "widget": {
             "title": "Code Suggestions by Day",
             "id": "",
             "xyChart": {
               "chartOptions": {
                 "displayHorizontal": false,
                 "mode": "COLOR",
                 "showLegend": false
               },
               "dataSets": [
                 {
                   "breakdowns": [],
                   "dimensions": [
                     {
                       "column": "exposures_date",
                       "columnType": "DATE",
                       "maxBinCount": 0,
                       "sortColumn": "exposures_date",
                       "sortOrder": "SORT_ORDER_ASCENDING",
                       "timeBinSize": "0s",
                       "xMax": 0,
                       "xMin": 0
                     }
                   ],
                   "legendTemplate": "",
                   "measures": [
                     {
                       "aggregationFunction": {
                         "parameters": [],
                         "type": "average"
                       },
                       "column": "exposures_count"
                     }
                   ],
                   "plotType": "STACKED_BAR",
                   "targetAxis": "Y1",
                   "timeSeriesQuery": {
                     "opsAnalyticsQuery": {
                       "queryExecutionRules": {
                         "useReservedSlots": false
                       },
                       "queryHandle": "",
                       "savedQueryId": "",
                       "sql": "SELECT\n  COUNT (DISTINCT JSON_VALUE(json_payload, '$.codeExposure.originalRequestId')) as exposures_count, CAST(timestamp AS DATE) AS exposures_date\nFROM\n  `CENTRALIZED_PROJECT_ID.global._Default._Default`\nWHERE\n  JSON_VALUE(json_payload, '$.codeExposure.originalRequestId') is not NULL\n  AND resource.type = \"cloudaicompanion.googleapis.com/Instance\"\n  AND (JSON_VALUE(resource.labels, '$.resource_container') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2') or JSON_VALUE(resource.labels, '$.project_id') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2'))\nGROUP BY\n  exposures_date\nORDER BY\n  exposures_date"
                     },
                     "outputFullDuration": false,
                     "unitOverride": ""
                   }
                 }
               ],
               "thresholds": [],
               "yAxis": {
                 "label": "",
                 "scale": "LINEAR"
               }
             }
           }
         },
         {
           "yPos": 16,
           "xPos": 24,
           "height": 16,
           "width": 24,
           "widget": {
             "title": "Code Acceptances by Day",
             "id": "",
             "xyChart": {
               "chartOptions": {
                 "displayHorizontal": false,
                 "mode": "COLOR",
                 "showLegend": false
               },
               "dataSets": [
                 {
                   "breakdowns": [],
                   "dimensions": [
                     {
                       "column": "acceptances_date",
                       "columnType": "DATE",
                       "maxBinCount": 0,
                       "sortColumn": "acceptances_date",
                       "sortOrder": "SORT_ORDER_ASCENDING",
                       "timeBinSize": "0s",
                       "xMax": 0,
                       "xMin": 0
                     }
                   ],
                   "legendTemplate": "",
                   "measures": [
                     {
                       "aggregationFunction": {
                         "parameters": [],
                         "type": "average"
                       },
                       "column": "acceptances_count"
                     }
                   ],
                   "plotType": "STACKED_BAR",
                   "targetAxis": "Y1",
                   "timeSeriesQuery": {
                     "opsAnalyticsQuery": {
                       "queryExecutionRules": {
                         "useReservedSlots": false
                       },
                       "queryHandle": "",
                       "savedQueryId": "",
                       "sql": "SELECT\n  COUNT (DISTINCT JSON_VALUE(json_payload, '$.codeAcceptance.originalRequestId')) as acceptances_count, CAST(timestamp AS DATE) AS acceptances_date\nFROM\n  `CENTRALIZED_PROJECT_ID.global._Default._Default`\nWHERE\n  JSON_VALUE(json_payload, '$.codeAcceptance.originalRequestId') is not NULL\n  AND resource.type = \"cloudaicompanion.googleapis.com/Instance\"\n  AND (JSON_VALUE(resource.labels, '$.resource_container') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2') or JSON_VALUE(resource.labels, '$.project_id') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2'))\nGROUP BY\n  acceptances_date\nORDER BY\n  acceptances_date\n"
                     },
                     "outputFullDuration": false,
                     "unitOverride": ""
                   }
                 }
               ],
               "thresholds": [],
               "yAxis": {
                 "label": "",
                 "scale": "LINEAR"
               }
             }
           }
         },
         {
           "yPos": 32,
           "height": 16,
           "width": 24,
           "widget": {
             "title": "Lines of Code Accepted by Day",
             "id": "",
             "xyChart": {
               "chartOptions": {
                 "displayHorizontal": false,
                 "mode": "COLOR",
                 "showLegend": false
               },
               "dataSets": [
                 {
                   "breakdowns": [],
                   "dimensions": [
                     {
                       "column": "line_count_day",
                       "columnType": "DATE",
                       "maxBinCount": 0,
                       "sortColumn": "line_count_day",
                       "sortOrder": "SORT_ORDER_ASCENDING",
                       "timeBinSize": "0s",
                       "xMax": 0,
                       "xMin": 0
                     }
                   ],
                   "legendTemplate": "",
                   "measures": [
                     {
                       "aggregationFunction": {
                         "parameters": [],
                         "type": "average"
                       },
                       "column": "lines_count"
                     }
                   ],
                   "plotType": "STACKED_BAR",
                   "targetAxis": "Y1",
                   "timeSeriesQuery": {
                     "opsAnalyticsQuery": {
                       "queryExecutionRules": {
                         "useReservedSlots": false
                       },
                       "queryHandle": "",
                       "savedQueryId": "",
                       "sql": "SELECT\n SUM(lines) as lines_count,\n CAST(max_timestamp AS DATE) AS line_count_day\nFROM\n(\n SELECT\n   JSON_VALUE(json_payload, '$.codeAcceptance.originalRequestId') as request_id,\n   MAX(CAST(JSON_VALUE(json_payload, '$.codeAcceptance.linesCount') AS INT)) as lines,\n   MAX(timestamp) as max_timestamp\n FROM\n   `CENTRALIZED_PROJECT_ID.global._Default._Default`\n WHERE\n   JSON_VALUE(json_payload, '$.codeAcceptance.originalRequestId') is not NULL\n   AND resource.type = \"cloudaicompanion.googleapis.com/Instance\"\n   AND (JSON_VALUE(resource.labels, '$.resource_container') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2') or JSON_VALUE(resource.labels, '$.project_id') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2'))\n GROUP BY\n   request_id\n )\nGROUP BY\n line_count_day\nORDER BY\n line_count_day"
                     },
                     "outputFullDuration": false,
                     "unitOverride": ""
                   }
                 }
               ],
               "thresholds": [],
               "yAxis": {
                 "label": "",
                 "scale": "LINEAR"
               }
             }
           }
         },
         {
           "yPos": 32,
           "xPos": 24,
           "height": 16,
           "width": 24,
           "widget": {
             "title": "Chat Exposures by Day",
             "id": "",
             "xyChart": {
               "chartOptions": {
                 "displayHorizontal": false,
                 "mode": "COLOR",
                 "showLegend": false
               },
               "dataSets": [
                 {
                   "breakdowns": [],
                   "dimensions": [
                     {
                       "column": "chat_exposures_date",
                       "columnType": "DATE",
                       "maxBinCount": 0,
                       "sortColumn": "chat_exposures_date",
                       "sortOrder": "SORT_ORDER_ASCENDING",
                       "timeBinSize": "0s",
                       "xMax": 0,
                       "xMin": 0
                     }
                   ],
                   "legendTemplate": "",
                   "measures": [
                     {
                       "aggregationFunction": {
                         "parameters": [],
                         "type": "average"
                       },
                       "column": "chat_exposures_count"
                     }
                   ],
                   "plotType": "STACKED_BAR",
                   "targetAxis": "Y1",
                   "timeSeriesQuery": {
                     "opsAnalyticsQuery": {
                       "queryExecutionRules": {
                         "useReservedSlots": false
                       },
                       "queryHandle": "",
                       "savedQueryId": "",
                       "sql": "SELECT\n COUNT (DISTINCT JSON_VALUE(json_payload, '$.chatExposure.originalRequestId')) as chat_exposures_count, CAST(timestamp AS DATE) AS chat_exposures_date\nFROM\n   `CENTRALIZED_PROJECT_ID.global._Default._Default`\nWHERE\n JSON_VALUE(json_payload, '$.chatExposure.originalRequestId') is not NULL\n AND resource.type = \"cloudaicompanion.googleapis.com/Instance\"\n AND (JSON_VALUE(resource.labels, '$.resource_container') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2') or JSON_VALUE(resource.labels, '$.project_id') in ('SOURCE_PROJECT_ID_1', 'SOURCE_PROJECT_ID_2'))\nGROUP BY\n chat_exposures_date\nORDER BY\n chat_exposures_date"
                     },
                     "outputFullDuration": false,
                     "unitOverride": ""
                   }
                 }
               ],
               "thresholds": [],
               "yAxis": {
                 "label": "",
                 "scale": "LINEAR"
               }
             }
           }
         }
       ]
     }
   }
   ```
5. Replace the following:

   - `CENTRALIZED_PROJECT_ID`: The project ID of the centralized logging project that you created.
   - `SOURCE_PROJECT_ID_1` and `SOURCE_PROJECT_ID_2`: The project IDs of the projects that you want to collect logs from. If you want to collect logs from more than two projects, then you can add more project IDs to the `in` clauses of the query.

### Disable multi-project logging

If you configured Gemini Code Assist logging for multiple
projects, you can disable it by deleting the log sinks that route logs to the
centralized project. To stop sending logs from an individual project to the
centralized project, delete the log sink that you created in that project:

1. In the Google Cloud console, switch to a project that you want to stop collecting logs from.
2. Go to the **Log Router** page:

   [Go to Log Router](https://console.cloud.google.com/logs/router)
3. Identify the sink that routes logs to your centralized project.

4. In the row for that sink, click **More actions** , and then select
   **Delete sink**.

5. In the dialog that appears, click **Delete**.

Repeat these steps for each project that you want to stop sending logs to
the centralized project.

## What's next

- [View Gemini Code Assist logs](https://docs.cloud.google.com/gemini/docs/log-gemini.md.txt).
- [View other Gemini Code Assist administrator settings](https://docs.cloud.google.com/gemini/docs/admin-settings.md.txt).