11# Local development guide
22
33This guide provides instructions for setting up and using local development
4- features, such as development tracing.
4+ features, such as tracing.
55
6- ## Development tracing
6+ ## Tracing
77
8- Development traces (dev traces) are OpenTelemetry (OTel) traces that help you
9- debug your code by instrumenting interesting events like model calls, tool
10- scheduler, tool calls, etc .
8+ Traces are OpenTelemetry (OTel) records that help you debug your code by
9+ instrumenting key events like model calls, tool scheduler operations, and tool
10+ calls.
1111
12- Dev traces are verbose and are specifically meant for understanding agent
13- behavior and debugging issues. They are disabled by default.
12+ Traces provide deep visibility into agent behavior and are invaluable for
13+ debugging complex issues. They are captured automatically when telemetry is
14+ enabled.
1415
15- To enable dev traces, set the ` GEMINI_DEV_TRACING=true ` environment variable
16- when running Gemini CLI.
16+ ### Viewing traces
1717
18- ### Viewing dev traces
19-
20- You can view dev traces using either Jaeger or the Genkit Developer UI.
18+ You can view traces using either Jaeger or the Genkit Developer UI.
2119
2220#### Using Genkit
2321
@@ -37,13 +35,12 @@ Genkit provides a web-based UI for viewing traces and other telemetry data.
3735 Genkit Developer UI: http://localhost:4000
3836 ```
3937
40- 2. ** Run Gemini CLI with dev tracing :**
38+ 2. ** Run Gemini CLI:**
4139
42- In a separate terminal, run your Gemini CLI command with the
43- ` GEMINI_DEV_TRACING` environment variable:
40+ In a separate terminal, run your Gemini CLI command:
4441
4542 ` ` ` bash
46- GEMINI_DEV_TRACING=true gemini
43+ gemini
4744 ` ` `
4845
49463. ** View the traces:**
@@ -53,7 +50,7 @@ Genkit provides a web-based UI for viewing traces and other telemetry data.
5350
5451# ### Using Jaeger
5552
56- You can view dev traces in the Jaeger UI. To get started, follow these steps:
53+ You can view traces in the Jaeger UI. To get started, follow these steps:
5754
58551. ** Start the telemetry collector:**
5956
@@ -67,13 +64,12 @@ You can view dev traces in the Jaeger UI. To get started, follow these steps:
6764 This command also configures your workspace for local telemetry and provides
6865 a link to the Jaeger UI (usually ` http://localhost:16686` ).
6966
70- 2. ** Run Gemini CLI with dev tracing :**
67+ 2. ** Run Gemini CLI:**
7168
72- In a separate terminal, run your Gemini CLI command with the
73- ` GEMINI_DEV_TRACING` environment variable:
69+ In a separate terminal, run your Gemini CLI command:
7470
7571 ` ` ` bash
76- GEMINI_DEV_TRACING=true gemini
72+ gemini
7773 ` ` `
7874
79753. ** View the traces:**
@@ -84,10 +80,10 @@ You can view dev traces in the Jaeger UI. To get started, follow these steps:
8480For more detailed information on telemetry, see the
8581[telemetry documentation](./cli/telemetry.md).
8682
87- # ## Instrumenting code with dev traces
83+ # ## Instrumenting code with traces
8884
89- You can add dev traces to your own code for more detailed instrumentation. This
90- is useful for debugging and understanding the flow of execution.
85+ You can add traces to your own code for more detailed instrumentation. This is
86+ useful for debugging and understanding the flow of execution.
9187
9288Use the ` runInDevTraceSpan` function to wrap any section of code in a trace
9389span.
@@ -96,29 +92,39 @@ Here is a basic example:
9692
9793` ` ` typescript
9894import { runInDevTraceSpan } from ' @google/gemini-cli-core' ;
99-
100- await runInDevTraceSpan({ name: ' my-custom-span' }, async ({ metadata }) => {
101- // The ` metadata` object allows you to record the input and output of the
102- // operation as well as other attributes.
103- metadata.input = { key: ' value' };
104- // Set custom attributes.
105- metadata.attributes[' gen_ai.request.model' ] = ' gemini-4.0-mega' ;
106-
107- // Your code to be traced goes here
108- try {
109- const output = await somethingRisky ();
110- metadata.output = output;
111- return output;
112- } catch (e) {
113- metadata.error = e;
114- throw e;
115- }
116- });
95+ import { GeminiCliOperation } from ' @google/gemini-cli-core/lib/telemetry/constants.js' ;
96+
97+ await runInDevTraceSpan(
98+ {
99+ operation: GeminiCliOperation.ToolCall,
100+ attributes: {
101+ [GEN_AI_AGENT_NAME]: ' gemini-cli' ,
102+ },
103+ },
104+ async ({ metadata }) => {
105+ // The ` metadata` object allows you to record the input and output of the
106+ // operation as well as other attributes.
107+ metadata.input = { key: ' value' };
108+ // Set custom attributes.
109+ metadata.attributes[' custom.attribute' ] = ' custom.value' ;
110+
111+ // Your code to be traced goes here
112+ try {
113+ const output = await somethingRisky ();
114+ metadata.output = output;
115+ return output;
116+ } catch (e) {
117+ metadata.error = e;
118+ throw e;
119+ }
120+ },
121+ );
117122` ` `
118123
119124In this example:
120125
121- - ` name` : The name of the span, which will be displayed in the trace.
126+ - ` operation` : The operation type of the span, represented by the
127+ ` GeminiCliOperation` enum.
122128- ` metadata.input` : (Optional) An object containing the input data for the
123129 traced operation.
124130- ` metadata.output` : (Optional) An object containing the output data from the
0 commit comments