> ## Documentation Index
> Fetch the complete documentation index at: https://docs.idun-group.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Cloud Trace

> Set up Google Cloud Trace to capture distributed traces and analyze agent latency.

Set up Google Cloud Trace to capture distributed traces from your agents and analyze latency in the Google Cloud Console.

> [!TIP]
>
> Before starting, complete the [quickstart guide](https://docs.idun-group.com/quickstart.md) to have an agent running on Idun Engine.

## Set up GCP Trace observability

**1. Prepare your Google Cloud project**

1. Create a Google Cloud project if you do not have one
2. Enable the **Cloud Trace API** in your project
3. Verify that the environment where your agent runs has credentials with permission to write traces (the `Cloud Trace Agent` role)

> [tab] Running on Google Cloud
>
> If running on Cloud Run, GKE, or Compute Engine, the default service account typically has the required permissions if scopes are configured.

> [tab] Running locally or elsewhere
>
> Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to point to your service account key file, or configure application default credentials.

**2. Create an observability configuration**

1. On the Idun Engine main page, navigate to **Observability**
2. Click **Add configuration**
3. Select **GCP Trace**
4. Enter a **Configuration Name** (for example, "GCP Trace Prod")
5. Fill in the required details:
   * **Project ID**: Your Google Cloud Project ID (for example, `my-project-123`)
   * **Region**: (Optional) Specific region if applicable
   * **Trace Name**: (Optional) Name for the trace session
   * **Sampling Rate**: A number between 0.0 and 1.0 (for example, `1.0` for 100% sampling)
   * **Flush Interval**: Time in seconds to wait before sending traces (default `5`)
   * **Ignore URLs**: (Optional) Paths to exclude from tracing
6. Click **Create configuration**

**3. Attach GCP Trace to your agent**

1. Navigate to the agent you want to trace
2. Click **Edit Agent**
3. Click **Next** to reach the observability configuration step
4. Select **GCP Trace** as the observability provider
5. Select the configuration you created
6. Click **Next**
7. Click **Save changes** to finalize

After saving, click **Restart** on your agent page to reload the configuration.

## View trace data

Once your agent is running with observability enabled:

1. Interact with your agent
2. Open the [Google Cloud Console](https://console.cloud.google.com/)
3. Navigate to **Trace** > **Trace List**

You will see traces from your agent's execution. Use these to analyze latency and find bottlenecks.

## Best practices

* **Adjust sampling rate**: For high-traffic agents, lower the sampling rate to reduce costs and noise
* **Use meaningful trace names**: This helps when filtering traces in the GCP Console

## Troubleshooting

> [accordion] Traces not showing up?
>
> 1. **Check API**: Verify the Cloud Trace API is enabled in your project
> 2. **Check permissions**: Confirm the agent's service account has the `Cloud Trace Agent` role
> 3. **Wait for flush**: Traces are sent in batches. Wait a few seconds (based on your flush interval) after execution before checking the console

## Next steps

> [card] [GCP Logging](https://docs.idun-group.com/observability/gcp-logging.md)
>
> Pair tracing with structured logs in Google Cloud Logging.

> [card] [Local trace store](https://docs.idun-group.com/observability/traces.md)
>
> Inspect the same agent runs in the bundled admin UI.

> [card] [Deploy to Cloud Run](https://docs.idun-group.com/standalone/cloud-run.md)
>
> Run the standalone next to your traces with managed Postgres.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.