2025-12-01 11:38:48 -08:00
|
|
|
# Local development guide
|
2025-10-27 19:16:44 -04:00
|
|
|
|
|
|
|
|
This guide provides instructions for setting up and using local development
|
2026-03-10 13:20:25 -04:00
|
|
|
features for Gemini CLI.
|
2025-10-27 19:16:44 -04:00
|
|
|
|
2026-02-26 18:26:16 -08:00
|
|
|
## Tracing
|
2025-10-27 19:16:44 -04:00
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
Gemini CLI uses OpenTelemetry (OTel) to record traces that help you debug agent
|
|
|
|
|
behavior. Traces instrument key events like model calls, tool scheduler
|
|
|
|
|
operations, and tool calls.
|
2025-10-27 19:16:44 -04:00
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
Traces provide deep visibility into agent behavior and help you debug complex
|
|
|
|
|
issues. They are captured automatically when you enable telemetry.
|
2025-10-27 19:16:44 -04:00
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
### View traces
|
2025-10-27 19:16:44 -04:00
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
You can view traces using Genkit Developer UI, Jaeger, or Google Cloud.
|
2025-10-27 23:37:43 -04:00
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
#### Use Genkit
|
2025-10-27 23:37:43 -04:00
|
|
|
|
|
|
|
|
Genkit provides a web-based UI for viewing traces and other telemetry data.
|
|
|
|
|
|
2025-12-01 11:38:48 -08:00
|
|
|
1. **Start the Genkit telemetry server:**
|
2025-10-27 23:37:43 -04:00
|
|
|
|
|
|
|
|
Run the following command to start the Genkit server:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
npm run telemetry -- --target=genkit
|
|
|
|
|
```
|
|
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
The script will output the URL for the Genkit Developer UI. For example:
|
|
|
|
|
`Genkit Developer UI: http://localhost:4000`
|
2025-10-27 23:37:43 -04:00
|
|
|
|
2026-02-26 18:26:16 -08:00
|
|
|
2. **Run Gemini CLI:**
|
2025-10-27 23:37:43 -04:00
|
|
|
|
2026-02-26 18:26:16 -08:00
|
|
|
In a separate terminal, run your Gemini CLI command:
|
2025-10-27 23:37:43 -04:00
|
|
|
|
|
|
|
|
```bash
|
2026-02-26 18:26:16 -08:00
|
|
|
gemini
|
2025-10-27 23:37:43 -04:00
|
|
|
```
|
|
|
|
|
|
2025-12-01 11:38:48 -08:00
|
|
|
3. **View the traces:**
|
2025-10-27 23:37:43 -04:00
|
|
|
|
|
|
|
|
Open the Genkit Developer UI URL in your browser and navigate to the
|
|
|
|
|
**Traces** tab to view the traces.
|
|
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
#### Use Jaeger
|
2025-10-27 23:37:43 -04:00
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
You can view traces in the Jaeger UI for local development.
|
2025-10-27 19:16:44 -04:00
|
|
|
|
|
|
|
|
1. **Start the telemetry collector:**
|
|
|
|
|
|
|
|
|
|
Run the following command in your terminal to download and start Jaeger and
|
2026-03-10 13:20:25 -04:00
|
|
|
an OTel collector:
|
2025-10-27 19:16:44 -04:00
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
npm run telemetry -- --target=local
|
|
|
|
|
```
|
|
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
This command configures your workspace for local telemetry and provides a
|
|
|
|
|
link to the Jaeger UI (usually `http://localhost:16686`).
|
|
|
|
|
- **Collector logs:** `~/.gemini/tmp/<projectHash>/otel/collector.log`
|
2025-10-27 19:16:44 -04:00
|
|
|
|
2026-02-26 18:26:16 -08:00
|
|
|
2. **Run Gemini CLI:**
|
2025-10-27 19:16:44 -04:00
|
|
|
|
2026-02-26 18:26:16 -08:00
|
|
|
In a separate terminal, run your Gemini CLI command:
|
2025-10-27 19:16:44 -04:00
|
|
|
|
|
|
|
|
```bash
|
2026-02-26 18:26:16 -08:00
|
|
|
gemini
|
2025-10-27 19:16:44 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
3. **View the traces:**
|
|
|
|
|
|
|
|
|
|
After running your command, open the Jaeger UI link in your browser to view
|
|
|
|
|
the traces.
|
|
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
#### Use Google Cloud
|
|
|
|
|
|
|
|
|
|
You can use an OpenTelemetry collector to forward telemetry data to Google Cloud
|
|
|
|
|
Trace for custom processing or routing.
|
|
|
|
|
|
|
|
|
|
> **Warning:** Ensure you complete the
|
|
|
|
|
> [Google Cloud telemetry prerequisites](./cli/telemetry.md#prerequisites)
|
|
|
|
|
> (Project ID, authentication, IAM roles, and APIs) before using this method.
|
|
|
|
|
|
|
|
|
|
1. **Configure `.gemini/settings.json`:**
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"telemetry": {
|
|
|
|
|
"enabled": true,
|
|
|
|
|
"target": "gcp",
|
|
|
|
|
"useCollector": true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
2. **Start the telemetry collector:**
|
|
|
|
|
|
|
|
|
|
Run the following command to start a local OTel collector that forwards to
|
|
|
|
|
Google Cloud:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
npm run telemetry -- --target=gcp
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The script outputs links to view traces, metrics, and logs in the Google
|
|
|
|
|
Cloud Console.
|
|
|
|
|
- **Collector logs:** `~/.gemini/tmp/<projectHash>/otel/collector-gcp.log`
|
|
|
|
|
|
|
|
|
|
3. **Run Gemini CLI:**
|
|
|
|
|
|
|
|
|
|
In a separate terminal, run your Gemini CLI command:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
gemini
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
4. **View logs, metrics, and traces:**
|
|
|
|
|
|
|
|
|
|
After sending prompts, view your data in the Google Cloud Console. See the
|
|
|
|
|
[telemetry documentation](./cli/telemetry.md#view-google-cloud-telemetry)
|
|
|
|
|
for links to Logs, Metrics, and Trace explorers.
|
|
|
|
|
|
2025-10-27 19:16:44 -04:00
|
|
|
For more detailed information on telemetry, see the
|
|
|
|
|
[telemetry documentation](./cli/telemetry.md).
|
|
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
### Instrument code with traces
|
2025-10-27 19:16:44 -04:00
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
You can add traces to your own code for more detailed instrumentation.
|
2025-10-27 19:16:44 -04:00
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
Adding traces helps you debug and understand the flow of execution. Use the
|
|
|
|
|
`runInDevTraceSpan` function to wrap any section of code in a trace span.
|
2025-10-27 19:16:44 -04:00
|
|
|
|
|
|
|
|
Here is a basic example:
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
import { runInDevTraceSpan } from '@google/gemini-cli-core';
|
2026-02-26 18:26:16 -08:00
|
|
|
import { GeminiCliOperation } from '@google/gemini-cli-core/lib/telemetry/constants.js';
|
|
|
|
|
|
|
|
|
|
await runInDevTraceSpan(
|
|
|
|
|
{
|
|
|
|
|
operation: GeminiCliOperation.ToolCall,
|
|
|
|
|
attributes: {
|
|
|
|
|
[GEN_AI_AGENT_NAME]: 'gemini-cli',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
async ({ metadata }) => {
|
2026-03-10 13:20:25 -04:00
|
|
|
// metadata allows you to record the input and output of the
|
2026-02-26 18:26:16 -08:00
|
|
|
// operation as well as other attributes.
|
|
|
|
|
metadata.input = { key: 'value' };
|
|
|
|
|
// Set custom attributes.
|
|
|
|
|
metadata.attributes['custom.attribute'] = 'custom.value';
|
|
|
|
|
|
2026-03-10 13:20:25 -04:00
|
|
|
// Your code to be traced goes here.
|
2026-02-26 18:26:16 -08:00
|
|
|
try {
|
|
|
|
|
const output = await somethingRisky();
|
|
|
|
|
metadata.output = output;
|
|
|
|
|
return output;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
metadata.error = e;
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
2025-10-27 19:16:44 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
In this example:
|
|
|
|
|
|
2026-02-26 18:26:16 -08:00
|
|
|
- `operation`: The operation type of the span, represented by the
|
|
|
|
|
`GeminiCliOperation` enum.
|
2025-10-27 19:16:44 -04:00
|
|
|
- `metadata.input`: (Optional) An object containing the input data for the
|
|
|
|
|
traced operation.
|
|
|
|
|
- `metadata.output`: (Optional) An object containing the output data from the
|
|
|
|
|
traced operation.
|
|
|
|
|
- `metadata.attributes`: (Optional) A record of custom attributes to add to the
|
|
|
|
|
span.
|
|
|
|
|
- `metadata.error`: (Optional) An error object to record if the operation fails.
|