Google Cloud Gemini Enterprise and AI Applications
Collect agent invocations, engine requests, response latency, and text generation quotas from Google Cloud Gemini Enterprise. A separate pipeline can ingest inference, user activity, and API error logs.
Enable the Cloud Monitoring API in the target GCP project and grant roles/monitoring.viewer to the collector service account. To collect engine assets, also enable the Cloud Asset Inventory API and grant roles/cloudasset.viewer.
Configuration¶
Install Func¶
We recommend enabling Managed Func under Integrations > Extensions in Guance. The managed service sets up all prerequisites automatically. Continue by installing the script.
For a self-hosted instance, see Deploy Func yourself.
Install the script¶
- Sign in to the Func console and select Script Market to open the Guance Script Market. Search for
integration_gcp_discoveryengine. - Select Install and enter the account file name, Target Principal, and account name.
- Select Deploy Startup Script. Func creates the
Startupscript set and configures the startup script automatically. - Once enabled, the trigger appears under Management > Auto Trigger Configuration. Select Run to execute it once immediately. Wait briefly, then review the task history and logs.
Verify the integration¶
- Under Management > Auto Trigger Configuration, confirm the task exists and check its history and logs for errors.
- In Guance, go to Infrastructure > Custom and check for the collected assets.
- In Guance, go to Metrics and check for the
gcp_discoveryenginemeasurement and its data.
Metrics¶
Gemini Enterprise metrics are reported to gcp_discoveryengine and come from discoveryengine.googleapis.com/ in Cloud Monitoring. The table lists the fields and common dimensions used in the built-in views and check library. Google Cloud Gemini Enterprise metrics reference
| Metric Name | Description | Dimensions | Unit |
|---|---|---|---|
agent_session_count |
Cumulative agent sessions | engine_id, agent_id |
count |
agent_turn_count |
Cumulative agent interaction turns | engine_id, agent_id |
count |
agent_total_latencies_avg |
Average total agent invocation latency | account_name, project_id, engine_id, agent_id, status |
ms |
agent_total_latencies_p95 |
P95 total agent invocation latency | account_name, project_id, engine_id, agent_id, status |
ms |
agent_total_latencies_p99 |
P99 total agent invocation latency | account_name, project_id, engine_id, agent_id, status |
ms |
agent_total_latencies_samplecount |
Sample count in the total agent invocation latency distribution | account_name, project_id, engine_id, agent_id, status |
count |
engine_request_count |
Cumulative engine requests | account_name, project_id, engine_id, model_id, method, query_type, response_code, response_code_class |
count |
engine_request_total_latency_avg |
Average total engine request latency | account_name, project_id, engine_id, model_id, method, query_type, response_code, response_code_class |
ms |
engine_request_total_latency_p95 |
P95 total engine request latency | account_name, project_id, engine_id, model_id, method, query_type, response_code, response_code_class |
ms |
engine_request_total_latency_p99 |
P99 total engine request latency | account_name, project_id, engine_id, model_id, method, query_type, response_code, response_code_class |
ms |
engine_request_total_latency_samplecount |
Sample count in the total engine request latency distribution | account_name, project_id, engine_id, model_id, method, query_type, response_code, response_code_class |
count |
engine_time_to_first_token_latency_avg |
Average engine time to first token | account_name, project_id, engine_id, model_id, method, query_type, response_code, response_code_class |
ms |
engine_time_to_first_token_latency_p95 |
P95 engine time to first token | account_name, project_id, engine_id, model_id, method, query_type, response_code, response_code_class |
ms |
engine_time_to_first_token_latency_p99 |
P99 engine time to first token | account_name, project_id, engine_id, model_id, method, query_type, response_code, response_code_class |
ms |
engine_time_to_first_answer_latency_avg |
Average engine time to first answer | account_name, project_id, engine_id, model_id, method, query_type, response_code, response_code_class |
ms |
engine_time_to_first_answer_latency_p95 |
P95 engine time to first answer | account_name, project_id, engine_id, model_id, method, query_type, response_code, response_code_class |
ms |
engine_time_to_first_answer_latency_p99 |
P99 engine time to first answer | account_name, project_id, engine_id, model_id, method, query_type, response_code, response_code_class |
ms |
quota_text_answer_gen_tier_enterprise_plus_regional_usage |
Enterprise Plus daily regional quota usage for text answer generation | account_name, project_name, project_id, regional_location, limit_name |
count |
quota_text_answer_gen_tier_enterprise_plus_regional_limit |
Enterprise Plus daily regional quota limit for text answer generation | account_name, project_name, project_id, regional_location, limit_name |
count |
agent_session_count, agent_turn_count, and engine_request_count are cumulative counters. Read the counter level within the window for cumulative totals. To count new events, calculate the change in the counter to avoid summing repeated samples. agent_total_latencies_samplecount reports incremental sample counts that you can sum over a time window.
Objects¶
Find the gcp_discoveryengine_engine engine resources under Infrastructure > Custom.
{
"measurement": "gcp_discoveryengine_engine",
"tags": {
"account_name": "example-account",
"cloud_provider": "gcp",
"project_id": "example-project",
"location": "global",
"collection_id": "default_collection",
"engine_id": "example-engine"
},
"fields": {
"projectName": "Example Project",
"assetType": "discoveryengine.googleapis.com/Engine",
"resourceCreateTime": "2026-01-01T00:00:00Z",
"resourceUpdateTime": "2026-01-01T01:00:00Z"
}
}
The fields in tags and fields may change in future updates.
Logs¶
Log collection is optional. The forwarding path is Cloud Logging Sink → Pub/Sub → Cloud Run → DataWay. The integration uses the dataway/ variant of TrueWatchTech's open-source google-cloud-log-forwarder. Pub/Sub in the same project delivers the logs, and the adapter running in Cloud Run receives, processes, and writes them to DataWay over HTTPS. The upstream forwarder places the entire jsonPayload in message. This integration builds on it to map Gemini fields within the same Cloud Run service. Upstream DataWay forwarder
Configure forwarding¶
- Enable OpenTelemetry collection in the Gemini Enterprise observability settings. To view question and answer text, enable prompt input and response output logging in accordance with your data access and retention requirements. Gemini Enterprise observability settings
-
Create a dedicated Pub/Sub topic and a Cloud Logging sink. Set the topic as the sink destination and grant the sink's
writerIdentitytheroles/pubsub.publisherrole on the topic. Use the following inclusion filter to match the three log streams that containjsonPayload. Cloud Logging sink configuration -
Deploy a Cloud Run service with IAM authentication in the same GCP project. Configure the image, environment variables, and secret references as described below. Gemini adapter configuration
- Create an OIDC-enabled push subscription for the topic. Set its endpoint to the Cloud Run service URL plus
/pubsuband its audience to the service's base URL. You can set the acknowledgment deadline to 60 seconds. Grant the push service accountroles/run.invokeron the service, verify that the Pub/Sub service agent can mint OIDC tokens, and enable the sink once the downstream components are ready. Pub/Sub push authentication with OIDC
Configure the Gemini adapter¶
Before writing to DataWay, the adapter extracts text, token usage, status codes, and trace IDs from allowed fields. Prepare the gcp-gemini-enterprise/log-forwarder/ source directory before deploying. Set PROJECT_ID in main.py to the target GCP project and build the image using the directory's Dockerfile. The source sets MEASUREMENT to gcp_gemini_enterprise, which is the source name of the ingested logs.
Deploy the Cloud Run service with internal ingress and retain its default run.app address. Make sure the Pub/Sub push service account in the same project has permission to invoke the service. Cloud Run ingress configuration
Add the following environment variables to the Cloud Run container configuration.
| Environment Variable | Value |
|---|---|
FORWARDER_MODE |
Set to production to accept only the three Gemini log types in the sink filter. |
DATAWAY_URL |
HTTPS DataWay base URL for the target workspace's site, such as https://<DATAWAY_HOST>. |
EXPECTED_SUBSCRIPTION |
Full name of the push subscription in the same project, projects/<PROJECT_ID>/subscriptions/<SUBSCRIPTION_ID>. |
DATAWAY_TOKEN |
Store a dedicated Client Token for the target workspace in Secret Manager and inject it by numeric version. |
Grant the Cloud Run runtime service account roles/secretmanager.secretAccessor on the secret. When deploying via the CLI, you can pin the numeric version with --set-secrets=DATAWAY_TOKEN=<SECRET_NAME>:<VERSION>. To switch from synthetic acceptance testing to production collection, set FORWARDER_MODE to production and remove ACCEPTANCE_ID. Cloud Run secrets configuration
Query logs¶
The sink forwards only entries generated after it is enabled. After setup, run a test question and answer without sensitive data. In Logs > Explorer, select the default index and filter on source=gcp_gemini_enterprise. Use log_name to distinguish the three log streams and google_insert_id to match the original Cloud Logging entry. Check the push status to verify successful delivery and confirm the subscription has no backlog.
Expand an entry to view message under Content and see individual numeric and correlation fields under Extended Fields. The three log types contain the following data.
| Log Type | Content and Fields |
|---|---|
| Model inference | message contains the model's input and output messages. If the source entry provides the corresponding fields, the adapter writes input_tokens, output_tokens, and cache_read_input_tokens as separate integers for filtering and aggregation. |
| User activity | message contains the user's question from request.query and the final answer from serviceTextReply. If the source entry provides a status code, the adapter writes it to status_code. |
| API errors | message.requestPayload contains the failed request body recorded by GCP. If the source entry provides a status code, the adapter writes it to status_code. |
Each GCP LogEntry is forwarded independently, so one question and answer can produce several entries. If an entry includes a valid top-level trace, the adapter extracts gcp_trace_id. Filter by that value to correlate entries in the same trace, such as model inference and user activity logs. Queryable text, token usage, status codes, and gcp_trace_id depend on the fields available in the original GCP entries.