Skip to content

Observability with OpenTelemetry

Observability is the key to turning experimental AI into reliable software. Gemini CLI provides built-in support for OpenTelemetry, transforming every agent interaction into a rich stream of logs, metrics, and traces. This three-pillar approach gives you the high-fidelity visibility needed to understand agent behavior, optimize performance, and ensure reliability across your entire workflow.

Whether you are debugging a complex tool interaction locally or monitoring enterprise-wide usage in the cloud, Gemini CLI’s observability system provides the actionable intelligence needed to move from “black box” AI to predictable, high-performance systems.

Gemini CLI integrates with OpenTelemetry, a vendor-neutral, industry-standard observability framework.

The 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.

You control telemetry behavior through the .gemini/settings.json file. Environment variables can override these settings.

SettingEnvironment VariableDescriptionValuesDefault
enabledGEMINI_TELEMETRY_ENABLEDEnable or disable telemetrytrue/falsefalse
targetGEMINI_TELEMETRY_TARGETWhere to send telemetry data"gcp"/"local""local"
otlpEndpointGEMINI_TELEMETRY_OTLP_ENDPOINTOTLP collector endpointURL stringhttp://localhost:4317
otlpProtocolGEMINI_TELEMETRY_OTLP_PROTOCOLOTLP transport protocol"grpc"/"http""grpc"
outfileGEMINI_TELEMETRY_OUTFILESave telemetry to file (overrides otlpEndpoint)file path-
logPromptsGEMINI_TELEMETRY_LOG_PROMPTSInclude prompts in telemetry logstrue/falsetrue
useCollectorGEMINI_TELEMETRY_USE_COLLECTORUse external OTLP collector (advanced)true/falsefalse
useCliAuthGEMINI_TELEMETRY_USE_CLI_AUTHUse CLI credentials for telemetry (GCP target only)true/falsefalse
-GEMINI_CLI_SURFACEOptional custom label for traffic reportingstring-

Note on boolean environment variables: For boolean settings like enabled, setting the environment variable to true or 1 enables the feature.

For detailed configuration information, see the Configuration guide.

You can export telemetry data directly to Google Cloud Trace, Cloud Monitoring, and Cloud Logging.

You must complete several setup steps before enabling Google Cloud telemetry.

  1. Set your Google Cloud project ID:

    • To send telemetry to a separate project:

      macOS/Linux

      Terminal window
      export OTLP_GOOGLE_CLOUD_PROJECT="your-telemetry-project-id"

      Windows (PowerShell)

      Terminal window
      $env:OTLP_GOOGLE_CLOUD_PROJECT="your-telemetry-project-id"
    • To send telemetry to the same project as inference:

      macOS/Linux

      Terminal window
      export GOOGLE_CLOUD_PROJECT="your-project-id"

      Windows (PowerShell)

      Terminal window
      $env:GOOGLE_CLOUD_PROJECT="your-project-id"
  2. Authenticate with Google Cloud using one of these methods:

    • Method A: Application Default Credentials (ADC): Use this method for service accounts or standard gcloud authentication.
      • For user accounts:

        Terminal window
        gcloud auth application-default login
      • For service accounts:

        macOS/Linux

        Terminal window
        export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account.json"

        Windows (PowerShell)

        Terminal window
        $env:GOOGLE_APPLICATION_CREDENTIALS="C:\path\to\your\service-account.json"
    • Method B: CLI Auth (Direct export only): Simplest method for local users. Gemini CLI uses the same OAuth credentials you used for login. To enable this, set useCliAuth: true in your .gemini/settings.json:

      {
      "telemetry": {
      "enabled": true,
      "target": "gcp",
      "useCliAuth": true
      }
      }
  1. Ensure your account or service account has these IAM roles:

    • Cloud Trace Agent
    • Monitoring Metric Writer
    • Logs Writer
  2. Enable the required Google Cloud APIs:

    Terminal window
    gcloud services enable \
    cloudtrace.googleapis.com \
    monitoring.googleapis.com \
    logging.googleapis.com \
    --project="$OTLP_GOOGLE_CLOUD_PROJECT"

We recommend using direct export to send telemetry directly to Google Cloud services.

  1. Enable telemetry in .gemini/settings.json:
    {
    "telemetry": {
    "enabled": true,
    "target": "gcp"
    }
    }
  2. Run Gemini CLI and send prompts.
  3. View logs, metrics, and traces in the Google Cloud Console. See View Google Cloud telemetry for details.

After you enable telemetry and run Gemini CLI, you can view your data in the Google Cloud Console.

For detailed information on how to use these tools, see the following official Google Cloud documentation:

Gemini CLI provides a pre-configured Google Cloud Monitoring dashboard to visualize your telemetry.

Find this dashboard under Google Cloud Monitoring Dashboard Templates as “Gemini CLI Monitoring”.

Gemini CLI Monitoring Dashboard Overview

Gemini CLI Monitoring Dashboard Metrics

Gemini CLI Monitoring Dashboard Logs

To learn more, see Instant insights: Gemini CLI’s pre-configured monitoring dashboards.

You can capture telemetry data locally for development and debugging. We recommend using file-based output for local development.

  1. Enable telemetry in .gemini/settings.json:
    {
    "telemetry": {
    "enabled": true,
    "target": "local",
    "outfile": ".gemini/telemetry.log"
    }
    }
  2. Run Gemini CLI and send prompts.
  3. View logs and metrics in .gemini/telemetry.log.

For advanced local telemetry setups (such as Jaeger or Genkit), see the Local development guide.

Gemini CLI includes identifiers in its User-Agent header to help you differentiate and report on API traffic from different environments (for example, identifying calls from Gemini Code Assist versus a standard terminal).

Most integrated environments are identified automatically without additional configuration. The identifier is included as a prefix to the User-Agent and as a “surface” tag in the parenthetical metadata.

EnvironmentUser-Agent PrefixSurface Tag
Gemini Code Assist (Agent Mode)GeminiCLI-a2a-servervscode
Zed (via ACP)GeminiCLI-acp-zedzed
XCode (via ACP)GeminiCLI-acp-xcodexcode
IntelliJ IDEA (via ACP)GeminiCLI-acp-intellijideajetbrains
Standard TerminalGeminiCLIterminal

Example User-Agent: GeminiCLI-a2a-server/0.34.0/gemini-pro (linux; x64; vscode)

You can provide a custom identifier for your own scripts or automation by setting the GEMINI_CLI_SURFACE environment variable. This is useful for tracking specific internal tools or distribution channels in your GCP logs.

macOS/Linux

Terminal window
export GEMINI_CLI_SURFACE="my-custom-tool"

Windows (PowerShell)

Terminal window
$env:GEMINI_CLI_SURFACE="my-custom-tool"

When set, the value appears at the end of the User-Agent parenthetical: GeminiCLI/0.34.0/gemini-pro (linux; x64; my-custom-tool)

This section describes the structure of logs, metrics, and traces generated by Gemini CLI.

Gemini CLI includes session.id, installation.id, active_approval_mode, and user.email (when authenticated) as common attributes on all data.

Logs provide timestamped records of specific events. Gemini CLI logs events across several categories.

Session logs capture startup configuration and prompt submissions.

Emitted 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)
  • mcp_tools (string)
  • mcp_tools_count (int)
  • output_format (string)
  • extensions (string)
  • extension_ids (string)
  • extensions_count (int)
  • auth_type (string)
  • worktree_active (boolean)
  • github_workflow_name (string, optional)
  • github_repository_hash (string, optional)
  • github_event_name (string, optional)
  • github_pr_number (string, optional)
  • github_issue_number (string, optional)
  • github_custom_tracking_id (string, optional)

Emitted when you submit a prompt.

Attributes
  • prompt_length (int)
  • prompt_id (string)
  • prompt (string; excluded if telemetry.logPrompts is false)
  • auth_type (string)

These logs track changes to and usage of different approval modes.

Logs when you change the approval mode.

Attributes
  • from_mode (string)
  • to_mode (string)

Records time spent in an approval mode.

Attributes
  • mode (string)
  • duration_ms (int)

Logs when you execute a plan and switch from plan mode to active execution.

Attributes
  • approval_mode (string)

Tool logs capture executions, truncation, and edit behavior.

Emitted for each tool (function) call.

Attributes
  • function_name (string)
  • function_args (string)
  • duration_ms (int)
  • success (boolean)
  • decision (string: “accept”, “reject”, “auto_accept”, or “modify”)
  • error (string, optional)
  • error_type (string, optional)
  • prompt_id (string)
  • tool_type (string: “native” or “mcp”)
  • mcp_server_name (string, optional)
  • extension_name (string, optional)
  • extension_id (string, optional)
  • content_length (int, optional)
  • start_time (number, optional)
  • end_time (number, optional)
  • metadata (object, optional), which may include:
    • model_added_lines (number)
    • model_removed_lines (number)
    • user_added_lines (number)
    • user_removed_lines (number)
    • ask_user (object)

Logs when tool output is truncated.

Attributes
  • tool_name (string)
  • original_content_length (int)
  • truncated_content_length (int)
  • threshold (int)
  • lines (int)
  • prompt_id (string)

Records the chosen edit strategy.

Attributes
  • strategy (string)

Records the result of an edit correction.

Attributes
  • correction (string: “success” or “failure”)

Provides detailed GenAI operation data aligned with OpenTelemetry conventions.

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)

File logs track operations performed by tools.

Emitted for each file creation, read, or update.

Attributes
  • tool_name (string)
  • operation (string: “create”, “read”, or “update”)
  • lines (int, optional)
  • mimetype (string, optional)
  • extension (string, optional)
  • programming_language (string, optional)

API logs capture requests, responses, and errors from Gemini API.

Request sent to Gemini API.

Attributes
  • model (string)
  • prompt_id (string)
  • role (string: “user”, “model”, or “system”)
  • request_text (string, optional)

Response received from Gemini API.

Attributes
  • model (string)
  • status_code (int or 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)
  • prompt_id (string)
  • auth_type (string)
  • finish_reasons (array of strings)
  • response_text (string, optional)

Logs when an API request fails.

Attributes
  • error.message (string)
  • model_name (string)
  • duration (int)
  • prompt_id (string)
  • auth_type (string)
  • error_type (string, optional)
  • status_code (int or string, optional)
  • role (string, optional)

Logs when a JSON response cannot be parsed.

Attributes
  • model (string)

These logs track how Gemini CLI selects and routes requests to models.

Logs slash command execution.

Attributes
  • command (string)
  • subcommand (string, optional)
  • status (string: “success” or “error”)

Logs model selection via slash command.

Attributes
  • model_name (string)

Records model router decisions and reasoning.

Attributes
  • decision_model (string)
  • decision_source (string)
  • routing_latency_ms (int)
  • reasoning (string, optional)
  • failed (boolean)
  • error_message (string, optional)
  • approval_mode (string)

These logs track chat context compression and streaming chunk errors.

Logs chat context compression events.

Attributes
  • tokens_before (int)
  • tokens_after (int)

Logs invalid chunks received in a stream.

Attributes
  • error_message (string, optional)

Logs retries due to content errors.

Attributes
  • attempt_number (int)
  • error_type (string)
  • retry_delay_ms (int)
  • model (string)

Logs when all content retries fail.

Attributes
  • total_attempts (int)
  • final_error_type (string)
  • total_duration_ms (int, optional)
  • model (string)

Logs when a conversation session ends.

Attributes
  • approvalMode (string)
  • turnCount (int)

Resilience logs record fallback mechanisms and recovery attempts.

Logs switch to a flash model fallback.

Attributes
  • auth_type (string)

Logs fallback to standard grep.

Attributes
  • error (string, optional)

Logs web-fetch fallback attempts.

Attributes
  • reason (string: “private_ip” or “primary_failed”)

Logs attempts to recover from agent errors.

Attributes
  • agent_name (string)
  • attempt_number (int)
  • success (boolean)
  • error_type (string, optional)

Extension logs track lifecycle events and settings changes.

Logs when you install an extension.

Attributes
  • extension_name (string)
  • extension_version (string)
  • extension_source (string)
  • status (string)

Logs when you uninstall an extension.

Attributes
  • extension_name (string)
  • status (string)

Logs when you enable an extension.

Attributes
  • extension_name (string)
  • setting_scope (string)

Logs when you disable an extension.

Attributes
  • extension_name (string)
  • setting_scope (string)

Agent logs track the lifecycle of agent executions.

Logs when an agent run begins.

Attributes
  • agent_id (string)
  • agent_name (string)

Logs when an agent run completes.

Attributes
  • agent_id (string)
  • agent_name (string)
  • duration_ms (int)
  • turn_count (int)
  • terminate_reason (string)

IDE logs capture connectivity events for the IDE companion.

Logs IDE companion connections.

Attributes
  • connection_type (string)

UI logs track terminal rendering issues.

Logs terminal control sequence overflows.

Attributes
  • sequence_length (int)
  • truncated_sequence (string)

Logs when the conversation state is rewound.

Attributes
  • outcome (string)

Logs security verdicts from ConSeca.

Attributes
  • verdict (string)
  • decision (string: “accept”, “reject”, or “modify”)
  • reason (string, optional)
  • tool_name (string, optional)

Logs execution of lifecycle hooks.

Attributes
  • hook_name (string)
  • hook_type (string)
  • duration_ms (int)
  • success (boolean)

Logs when tool output is masked for privacy.

Attributes
  • tokens_before (int)
  • tokens_after (int)
  • masked_count (int)
  • total_prunable_tokens (int)

Logs keychain availability checks.

Attributes
  • available (boolean)

Logs detailed startup performance statistics.

Attributes
  • phases (json array of startup phases)
  • os_platform (string)
  • os_release (string)
  • is_docker (boolean)

Metrics provide numerical measurements of behavior over time.

Gemini CLI exports several custom metrics.

Incremented once per CLI startup.

Tracks onboarding flow from authentication to the user

  • gemini_cli.onboarding.start (Counter, Int): Incremented when the authentication flow begins.

  • gemini_cli.onboarding.success (Counter, Int): Incremented when the user onboarding flow completes successfully.

Attributes (Success)
  • user_tier (string)

Counts tool calls.

Attributes
  • function_name (string)
  • success (boolean)
  • decision (string: “accept”, “reject”, “modify”, or “auto_accept”)
  • tool_type (string: “mcp” or “native”)

Measures tool call latency (in ms).

Attributes
  • function_name (string)

Counts all API requests.

Attributes
  • model (string)
  • status_code (int or string)
  • error_type (string, optional)

Measures API request latency (in ms).

Attributes
  • model (string)

Counts input, output, thought, cache, and tool tokens.

Attributes
  • model (string)
  • type (string: “input”, “output”, “thought”, “cache”, or “tool”)

Counts file operations.

Attributes
  • operation (string: “create”, “read”, or “update”)
  • lines (int, optional)
  • mimetype (string, optional)
  • extension (string, optional)
  • programming_language (string, optional)

Counts added or removed lines.

Attributes
  • function_name (string, optional)
  • type (string: “added” or “removed”)

Counts compression operations.

Attributes
  • tokens_before (int)
  • tokens_after (int)

Counts invalid stream chunks.

Counts content error retries.

gemini_cli.chat.content_retry_failure.count
Section titled “gemini_cli.chat.content_retry_failure.count”

Counts requests where all retries failed.

Counts model selections.

Attributes
  • slash_command.model.model_name (string)

Measures routing decision latency.

Attributes
  • routing.decision_model (string)
  • routing.decision_source (string)
  • routing.approval_mode (string)

Counts routing failures.

Attributes
  • routing.decision_source (string)
  • routing.error_message (string)
  • routing.approval_mode (string)

Counts agent runs.

Attributes
  • agent_name (string)
  • terminate_reason (string)

Measures agent run duration.

Attributes
  • agent_name (string)

Counts turns per agent run.

Attributes
  • agent_name (string)

Counts plan executions.

Attributes
  • approval_mode (string)

Counts terminal flicker events.

Gemini CLI provides detailed performance metrics for advanced monitoring.

Measures startup time by phase.

Attributes
  • phase (string)
  • details (map, optional)

Measures heap and RSS memory.

Attributes
  • memory_type (string: “heap_used”, “heap_total”, “external”, “rss”)
  • component (string, optional)

Measures CPU usage percentage.

Attributes
  • component (string, optional)

Measures tool execution queue depth.

Breaks down tool time by phase.

Attributes
  • function_name (string)
  • phase (string: “validation”, “preparation”, “execution”, “result_processing”)

These metrics follow standard OpenTelemetry GenAI semantic conventions.

  • gen_ai.client.token.usage: Counts tokens used per operation.
  • gen_ai.client.operation.duration: Measures operation duration in seconds.

Traces provide an “under-the-hood” view of agent and backend operations. Use traces to debug tool interactions and optimize performance.

Every trace captures rich metadata via standard span attributes.

Standard span attributes
  • gen_ai.operation.name: High-level operation (for example, tool_call, llm_call, user_prompt, system_prompt, agent_call, or schedule_tool_calls).
  • gen_ai.agent.name: Set to gemini-cli.
  • gen_ai.agent.description: The service agent description.
  • gen_ai.input.messages: Input data or metadata.
  • gen_ai.output.messages: Output data or results.
  • gen_ai.request.model: Request model name.
  • gen_ai.response.model: Response model name.
  • gen_ai.prompt.name: The prompt name.
  • gen_ai.tool.name: Executed tool name.
  • gen_ai.tool.call_id: Unique ID for the tool call.
  • gen_ai.tool.description: Tool description.
  • gen_ai.tool.definitions: Tool definitions in JSON format.
  • gen_ai.usage.input_tokens: Number of input tokens.
  • gen_ai.usage.output_tokens: Number of output tokens.
  • gen_ai.system_instructions: System instructions in JSON format.
  • gen_ai.conversation.id: The CLI session ID.

For more details on semantic conventions for events, see the OpenTelemetry documentation.