Observability with OpenTelemetry
Learn how to enable and setup OpenTelemetry for Gemini CLI.
- Observability with OpenTelemetry
Key Benefits
Section titled “Key Benefits”- 🔍 Usage Analytics: Understand interaction patterns and feature adoption across your team
- ⚡ Performance Monitoring: Track response times, token consumption, and resource utilization
- 🐛 Real-time Debugging: Identify bottlenecks, failures, and error patterns as they occur
- 📊 Workflow Optimization: Make informed decisions to improve configurations and processes
- 🏢 Enterprise Governance: Monitor usage across teams, track costs, ensure compliance, and integrate with existing monitoring infrastructure
OpenTelemetry Integration
Section titled “OpenTelemetry Integration”Built on OpenTelemetry — the vendor-neutral, industry-standard observability framework — Gemini CLI’s observability system provides:
- Universal Compatibility: Export to any OpenTelemetry backend (Google Cloud, Jaeger, Prometheus, Datadog, etc.)
- Standardized Data: Use consistent formats and collection methods across your toolchain
- Future-Proof Integration: Connect with existing and future observability infrastructure
- No Vendor Lock-in: Switch between backends without changing your instrumentation
Configuration
Section titled “Configuration”All telemetry behavior is controlled through your .gemini/settings.json file.
Environment variables can be used to override the settings in the file.
| Setting | Environment Variable | Description | Values | Default |
|---|---|---|---|---|
enabled | GEMINI_TELEMETRY_ENABLED | Enable or disable telemetry | true/false | false |
target | GEMINI_TELEMETRY_TARGET | Where to send telemetry data | "gcp"/"local" | "local" |
otlpEndpoint | GEMINI_TELEMETRY_OTLP_ENDPOINT | OTLP collector endpoint | URL string | http://localhost:4317 |
otlpProtocol | GEMINI_TELEMETRY_OTLP_PROTOCOL | OTLP transport protocol | "grpc"/"http" | "grpc" |
outfile | GEMINI_TELEMETRY_OUTFILE | Save telemetry to file (overrides otlpEndpoint) | file path | - |
logPrompts | GEMINI_TELEMETRY_LOG_PROMPTS | Include prompts in telemetry logs | true/false | true |
useCollector | GEMINI_TELEMETRY_USE_COLLECTOR | Use external OTLP collector (advanced) | true/false | false |
Note on boolean environment variables: For the boolean settings (enabled,
logPrompts, useCollector), setting the corresponding environment variable to
true or 1 will enable the feature. Any other value will disable it.
For detailed information about all configuration options, see the Configuration Guide.
Google Cloud Telemetry
Section titled “Google Cloud Telemetry”Prerequisites
Section titled “Prerequisites”Before using either method below, complete these steps:
-
Set your Google Cloud project ID:
- For telemetry in a separate project from inference:
Terminal window export OTLP_GOOGLE_CLOUD_PROJECT="your-telemetry-project-id" - For telemetry in the same project as inference:
Terminal window export GOOGLE_CLOUD_PROJECT="your-project-id"
- For telemetry in a separate project from inference:
-
Authenticate with Google Cloud:
- If using a user account:
Terminal window gcloud auth application-default login - If using a service account:
Terminal window export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account.json"
- If using a user account:
-
Make sure your account or service account has these IAM roles:
- Cloud Trace Agent
- Monitoring Metric Writer
- Logs Writer
-
Enable the required Google Cloud APIs (if not already enabled):
Terminal window gcloud services enable \cloudtrace.googleapis.com \monitoring.googleapis.com \logging.googleapis.com \--project="$OTLP_GOOGLE_CLOUD_PROJECT"
Direct Export (Recommended)
Section titled “Direct Export (Recommended)”Sends telemetry directly to Google Cloud services. No collector needed.
- Enable telemetry in your
.gemini/settings.json:{"telemetry": {"enabled": true,"target": "gcp"}} - Run Gemini CLI and send prompts.
- View logs and metrics:
- Open the Google Cloud Console in your browser after sending prompts:
Collector-Based Export (Advanced)
Section titled “Collector-Based Export (Advanced)”For custom processing, filtering, or routing, use an OpenTelemetry collector to forward data to Google Cloud.
- Configure your
.gemini/settings.json:{"telemetry": {"enabled": true,"target": "gcp","useCollector": true}} - Run the automation script:
This will:
Terminal window npm run telemetry -- --target=gcp- Start a local OTEL collector that forwards to Google Cloud
- Configure your workspace
- Provide links to view traces, metrics, and logs in Google Cloud Console
- Save collector logs to
~/.gemini/tmp/<projectHash>/otel/collector-gcp.log - Stop collector on exit (e.g.
Ctrl+C)
- Run Gemini CLI and send prompts.
- View logs and metrics:
- Open the Google Cloud Console in your browser after sending prompts:
- Open
~/.gemini/tmp/<projectHash>/otel/collector-gcp.logto view local collector logs.
Local Telemetry
Section titled “Local Telemetry”For local development and debugging, you can capture telemetry data locally:
File-based Output (Recommended)
Section titled “File-based Output (Recommended)”- Enable telemetry in your
.gemini/settings.json:{"telemetry": {"enabled": true,"target": "local","otlpEndpoint": "","outfile": ".gemini/telemetry.log"}} - Run Gemini CLI and send prompts.
- View logs and metrics in the specified file (e.g.,
.gemini/telemetry.log).
Collector-Based Export (Advanced)
Section titled “Collector-Based Export (Advanced)”- Run the automation script:
This will:
Terminal window npm run telemetry -- --target=local- Download and start Jaeger and OTEL collector
- Configure your workspace for local telemetry
- Provide a Jaeger UI at http://localhost:16686
- Save logs/metrics to
~/.gemini/tmp/<projectHash>/otel/collector.log - Stop collector on exit (e.g.
Ctrl+C)
- Run Gemini CLI and send prompts.
- View traces at http://localhost:16686 and logs/metrics in the collector log file.
Logs and Metrics
Section titled “Logs and Metrics”The following section describes the structure of logs and metrics generated for Gemini CLI.
The session.id, installation.id, and user.email (available only when
authenticated with a Google account) are included as common attributes on all
logs and metrics.
Logs are timestamped records of specific events. The following events are logged for Gemini CLI, grouped by category.
Sessions
Section titled “Sessions”Captures startup configuration and user prompt submissions.
-
gemini_cli.config: Emitted once at startup with the CLI configuration.- Attributes:
model(string)embedding_model(string)sandbox_enabled(boolean)core_tools_enabled(string)approval_mode(string)api_key_enabled(boolean)vertex_ai_enabled(boolean)log_user_prompts_enabled(boolean)file_filtering_respect_git_ignore(boolean)debug_mode(boolean)mcp_servers(string)mcp_servers_count(int)extensions(string)extension_ids(string)extension_count(int)mcp_tools(string, if applicable)mcp_tools_count(int, if applicable)output_format(“text”, “json”, or “stream-json”)
- Attributes:
-
gemini_cli.user_prompt: Emitted when a user submits a prompt.- Attributes:
prompt_length(int)prompt_id(string)prompt(string; excluded iftelemetry.logPromptsisfalse)auth_type(string)
- Attributes:
Captures tool executions, output truncation, and Smart Edit behavior.
-
gemini_cli.tool_call: Emitted for each tool (function) call.- Attributes:
function_namefunction_argsduration_mssuccess(boolean)decision(“accept”, “reject”, “auto_accept”, or “modify”, if applicable)error(if applicable)error_type(if applicable)prompt_id(string)tool_type(“native” or “mcp”)mcp_server_name(string, if applicable)extension_name(string, if applicable)extension_id(string, if applicable)content_length(int, if applicable)metadata(if applicable)
- Attributes:
-
gemini_cli.tool_output_truncated: Output of a tool call was truncated.- Attributes:
tool_name(string)original_content_length(int)truncated_content_length(int)threshold(int)lines(int)prompt_id(string)
- Attributes:
-
gemini_cli.smart_edit_strategy: Smart Edit strategy chosen.- Attributes:
strategy(string)
- Attributes:
-
gemini_cli.smart_edit_correction: Smart Edit correction result.- Attributes:
correction(“success” | “failure”)
- Attributes:
-
gen_ai.client.inference.operation.details: This event provides detailed information about the GenAI operation, aligned with OpenTelemetry GenAI semantic conventions for events.- Attributes:
gen_ai.request.model(string)gen_ai.provider.name(string)gen_ai.operation.name(string)gen_ai.input.messages(json string)gen_ai.output.messages(json string)gen_ai.response.finish_reasons(array of strings)gen_ai.usage.input_tokens(int)gen_ai.usage.output_tokens(int)gen_ai.request.temperature(float)gen_ai.request.top_p(float)gen_ai.request.top_k(int)gen_ai.request.max_tokens(int)gen_ai.system_instructions(json string)server.address(string)server.port(int)
- Attributes:
Tracks file operations performed by tools.
gemini_cli.file_operation: Emitted for each file operation.- Attributes:
tool_name(string)operation(“create” | “read” | “update”)lines(int, optional)mimetype(string, optional)extension(string, optional)programming_language(string, optional)
- Attributes:
Captures Gemini API requests, responses, and errors.
-
gemini_cli.api_request: Request sent to Gemini API.- Attributes:
model(string)prompt_id(string)request_text(string, optional)
- Attributes:
-
gemini_cli.api_response: Response received from Gemini API.- Attributes:
model(string)status_code(int|string)duration_ms(int)input_token_count(int)output_token_count(int)cached_content_token_count(int)thoughts_token_count(int)tool_token_count(int)total_token_count(int)response_text(string, optional)prompt_id(string)auth_type(string)
- Attributes:
-
gemini_cli.api_error: API request failed.- Attributes:
model(string)error(string)error_type(string)status_code(int|string)duration_ms(int)prompt_id(string)auth_type(string)
- Attributes:
-
gemini_cli.malformed_json_response:generateJsonresponse could not be parsed.- Attributes:
model(string)
- Attributes:
Model Routing
Section titled “Model Routing”Tracks model selections via slash commands and router decisions.
-
gemini_cli.slash_command: A slash command was executed.- Attributes:
command(string)subcommand(string, optional)status(“success” | “error”)
- Attributes:
-
gemini_cli.slash_command.model: Model was selected via slash command.- Attributes:
model_name(string)
- Attributes:
-
gemini_cli.model_routing: Model router made a decision.- Attributes:
decision_model(string)decision_source(string)routing_latency_ms(int)reasoning(string, optional)failed(boolean)error_message(string, optional)
- Attributes:
Chat and Streaming
Section titled “Chat and Streaming”Observes streaming integrity, compression, and retry behavior.
-
gemini_cli.chat_compression: Chat context was compressed.- Attributes:
tokens_before(int)tokens_after(int)
- Attributes:
-
gemini_cli.chat.invalid_chunk: Invalid chunk received from a stream.- Attributes:
error.message(string, optional)
- Attributes:
-
gemini_cli.chat.content_retry: Retry triggered due to a content error.- Attributes:
attempt_number(int)error_type(string)retry_delay_ms(int)model(string)
- Attributes:
-
gemini_cli.chat.content_retry_failure: All content retries failed.- Attributes:
total_attempts(int)final_error_type(string)total_duration_ms(int, optional)model(string)
- Attributes:
-
gemini_cli.conversation_finished: Conversation session ended.- Attributes:
approvalMode(string)turnCount(int)
- Attributes:
-
gemini_cli.next_speaker_check: Next speaker determination.- Attributes:
prompt_id(string)finish_reason(string)result(string)
- Attributes:
Resilience
Section titled “Resilience”Records fallback mechanisms for models and network operations.
-
gemini_cli.flash_fallback: Switched to a flash model as fallback.- Attributes:
auth_type(string)
- Attributes:
-
gemini_cli.ripgrep_fallback: Switched to grep as fallback for file search.- Attributes:
error(string, optional)
- Attributes:
-
gemini_cli.web_fetch_fallback_attempt: Attempted web-fetch fallback.- Attributes:
reason(“private_ip” | “primary_failed”)
- Attributes:
Extensions
Section titled “Extensions”Tracks extension lifecycle and settings changes.
-
gemini_cli.extension_install: An extension was installed.- Attributes:
extension_name(string)extension_version(string)extension_source(string)status(string)
- Attributes:
-
gemini_cli.extension_uninstall: An extension was uninstalled.- Attributes:
extension_name(string)status(string)
- Attributes:
-
gemini_cli.extension_enable: An extension was enabled.- Attributes:
extension_name(string)setting_scope(string)
- Attributes:
-
gemini_cli.extension_disable: An extension was disabled.- Attributes:
extension_name(string)setting_scope(string)
- Attributes:
-
gemini_cli.extension_update: An extension was updated.- Attributes:
extension_name(string)extension_version(string)extension_previous_version(string)extension_source(string)status(string)
- Attributes:
Agent Runs
Section titled “Agent Runs”Tracks agent lifecycle and outcomes.
-
gemini_cli.agent.start: Agent run started.- Attributes:
agent_id(string)agent_name(string)
- Attributes:
-
gemini_cli.agent.finish: Agent run finished.- Attributes:
agent_id(string)agent_name(string)duration_ms(int)turn_count(int)terminate_reason(string)
- Attributes:
Captures IDE connectivity and conversation lifecycle events.
gemini_cli.ide_connection: IDE companion connection.- Attributes:
connection_type(string)
- Attributes:
Tracks terminal rendering issues and related signals.
kitty_sequence_overflow: Terminal kitty control sequence overflow.- Attributes:
sequence_length(int)truncated_sequence(string)
- Attributes:
Metrics
Section titled “Metrics”Metrics are numerical measurements of behavior over time.
Custom
Section titled “Custom”Sessions
Section titled “Sessions”Counts CLI sessions at startup.
gemini_cli.session.count(Counter, Int): Incremented once per CLI startup.
Measures tool usage and latency.
-
gemini_cli.tool.call.count(Counter, Int): Counts tool calls.- Attributes:
function_namesuccess(boolean)decision(string: “accept”, “reject”, “modify”, or “auto_accept”, if applicable)tool_type(string: “mcp” or “native”, if applicable)
- Attributes:
-
gemini_cli.tool.call.latency(Histogram, ms): Measures tool call latency.- Attributes:
function_name
- Attributes:
Tracks API request volume and latency.
-
gemini_cli.api.request.count(Counter, Int): Counts all API requests.- Attributes:
modelstatus_codeerror_type(if applicable)
- Attributes:
-
gemini_cli.api.request.latency(Histogram, ms): Measures API request latency.- Attributes:
model
- Note: Overlaps with
gen_ai.client.operation.duration(GenAI conventions).
- Attributes:
Token Usage
Section titled “Token Usage”Tracks tokens used by model and type.
gemini_cli.token.usage(Counter, Int): Counts tokens used.- Attributes:
modeltype(“input”, “output”, “thought”, “cache”, or “tool”)
- Note: Overlaps with
gen_ai.client.token.usageforinput/output.
- Attributes:
Counts file operations with basic context.
-
gemini_cli.file.operation.count(Counter, Int): Counts file operations.- Attributes:
operation(“create”, “read”, “update”)lines(Int, optional)mimetype(string, optional)extension(string, optional)programming_language(string, optional)
- Attributes:
-
gemini_cli.lines.changed(Counter, Int): Number of lines changed (from file diffs).- Attributes:
function_nametype(“added” or “removed”)
- Attributes:
Chat and Streaming
Section titled “Chat and Streaming”Resilience counters for compression, invalid chunks, and retries.
-
gemini_cli.chat_compression(Counter, Int): Counts chat compression operations.- Attributes:
tokens_before(Int)tokens_after(Int)
- Attributes:
-
gemini_cli.chat.invalid_chunk.count(Counter, Int): Counts invalid chunks from streams. -
gemini_cli.chat.content_retry.count(Counter, Int): Counts retries due to content errors. -
gemini_cli.chat.content_retry_failure.count(Counter, Int): Counts requests where all content retries failed.
Model Routing
Section titled “Model Routing”Routing latency/failures and slash-command selections.
-
gemini_cli.slash_command.model.call_count(Counter, Int): Counts model selections via slash command.- Attributes:
slash_command.model.model_name(string)
- Attributes:
-
gemini_cli.model_routing.latency(Histogram, ms): Model routing decision latency.- Attributes:
routing.decision_model(string)routing.decision_source(string)
- Attributes:
-
gemini_cli.model_routing.failure.count(Counter, Int): Counts model routing failures.- Attributes:
routing.decision_source(string)routing.error_message(string)
- Attributes:
Agent Runs
Section titled “Agent Runs”Agent lifecycle metrics: runs, durations, and turns.
-
gemini_cli.agent.run.count(Counter, Int): Counts agent runs.- Attributes:
agent_name(string)terminate_reason(string)
- Attributes:
-
gemini_cli.agent.duration(Histogram, ms): Agent run durations.- Attributes:
agent_name(string)
- Attributes:
-
gemini_cli.agent.turns(Histogram, turns): Turns taken per agent run.- Attributes:
agent_name(string)
- Attributes:
UI stability signals such as flicker count.
gemini_cli.ui.flicker.count(Counter, Int): Counts UI frames that flicker (render taller than terminal).
Performance
Section titled “Performance”Optional performance monitoring for startup, CPU/memory, and phase timing.
-
gemini_cli.startup.duration(Histogram, ms): CLI startup time by phase.- Attributes:
phase(string)details(map, optional)
- Attributes:
-
gemini_cli.memory.usage(Histogram, bytes): Memory usage.- Attributes:
memory_type(“heap_used”, “heap_total”, “external”, “rss”)component(string, optional)
- Attributes:
-
gemini_cli.cpu.usage(Histogram, percent): CPU usage percentage.- Attributes:
component(string, optional)
- Attributes:
-
gemini_cli.tool.queue.depth(Histogram, count): Number of tools in the execution queue. -
gemini_cli.tool.execution.breakdown(Histogram, ms): Tool time by phase.- Attributes:
function_name(string)phase(“validation”, “preparation”, “execution”, “result_processing”)
- Attributes:
-
gemini_cli.api.request.breakdown(Histogram, ms): API request time by phase.- Attributes:
model(string)phase(“request_preparation”, “network_latency”, “response_processing”, “token_processing”)
- Attributes:
-
gemini_cli.token.efficiency(Histogram, ratio): Token efficiency metrics.- Attributes:
model(string)metric(string)context(string, optional)
- Attributes:
-
gemini_cli.performance.score(Histogram, score): Composite performance score.- Attributes:
category(string)baseline(number, optional)
- Attributes:
-
gemini_cli.performance.regression(Counter, Int): Regression detection events.- Attributes:
metric(string)severity(“low”, “medium”, “high”)current_value(number)baseline_value(number)
- Attributes:
-
gemini_cli.performance.regression.percentage_change(Histogram, percent): Percent change from baseline when regression detected.- Attributes:
metric(string)severity(“low”, “medium”, “high”)current_value(number)baseline_value(number)
- Attributes:
-
gemini_cli.performance.baseline.comparison(Histogram, percent): Comparison to baseline.- Attributes:
metric(string)category(string)current_value(number)baseline_value(number)
- Attributes:
GenAI Semantic Convention
Section titled “GenAI Semantic Convention”The following metrics comply with OpenTelemetry GenAI semantic conventions for standardized observability across GenAI applications:
-
gen_ai.client.token.usage(Histogram, token): Number of input and output tokens used per operation.- Attributes:
gen_ai.operation.name(string): The operation type (e.g., “generate_content”, “chat”)gen_ai.provider.name(string): The GenAI provider (“gcp.gen_ai” or “gcp.vertex_ai”)gen_ai.token.type(string): The token type (“input” or “output”)gen_ai.request.model(string, optional): The model name used for the requestgen_ai.response.model(string, optional): The model name that generated the responseserver.address(string, optional): GenAI server addressserver.port(int, optional): GenAI server port
- Attributes:
-
gen_ai.client.operation.duration(Histogram, s): GenAI operation duration in seconds.- Attributes:
gen_ai.operation.name(string): The operation type (e.g., “generate_content”, “chat”)gen_ai.provider.name(string): The GenAI provider (“gcp.gen_ai” or “gcp.vertex_ai”)gen_ai.request.model(string, optional): The model name used for the requestgen_ai.response.model(string, optional): The model name that generated the responseserver.address(string, optional): GenAI server addressserver.port(int, optional): GenAI server porterror.type(string, optional): Error type if the operation failed
- Attributes: