Skip to content

feat(plan): create a metric for execution of plans generated in plan mode#18236

Merged
jerop merged 5 commits intomainfrom
adibakm/execution-metric-plan-mode
Feb 6, 2026
Merged

feat(plan): create a metric for execution of plans generated in plan mode#18236
jerop merged 5 commits intomainfrom
adibakm/execution-metric-plan-mode

Conversation

@Adib234
Copy link
Copy Markdown
Contributor

@Adib234 Adib234 commented Feb 3, 2026

Summary

This PR instruments a new telemetry metric, PLAN_EXECUTION_COUNT, to track the execution of "Plan Mode". Specifically, it records an event whenever a user successfully exits Plan Mode via the ExitPlanMode tool with an approved plan, capturing the subsequent approval mode (e.g., default, autoEdit). This data will help quantify how often generated plans lead to execution.

Details

  • Metric: Added gemini_cli.plan.execution.count to metrics.ts.
  • Event: Created PlanExecutionEvent in types.ts to carry the approval_mode payload.
  • Logging:
    • Implemented logPlanExecution in loggers.ts to bridge the event to both OpenTelemetry (metrics) and Clearcut (logs).
    • Added logPlanExecutionEvent to ClearcutLogger for structured logging.
  • Integration: Updated ExitPlanModeTool to trigger this log only upon successful plan approval and mode switch.

Related Issues

Closes #16862

How to Validate

Enable plan mode and approve a plan, once the exit plan mode tool gets triggered a log should be emitted. I've verified that the log appears here https://cloudlogging.app.goo.gl/5omQxcqXPFzhFSih9

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@Adib234 Adib234 self-assigned this Feb 3, 2026
@Adib234 Adib234 requested a review from a team as a code owner February 3, 2026 21:53
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Adib234, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the application's telemetry capabilities by adding a new metric to quantify how often generated plans are actually executed. This will provide valuable insights into user behavior within 'Plan Mode' and the effectiveness of the plan generation process, allowing for data-driven improvements.

Highlights

  • New Telemetry Metric: Introduced a new telemetry metric, PLAN_EXECUTION_COUNT, to track the successful execution of plans generated in 'Plan Mode'.
  • Event Tracking: The metric is recorded when a user successfully exits 'Plan Mode' via the ExitPlanModeTool with an approved plan, capturing the specific approval_mode (e.g., default, autoEdit).
  • Logging Integration: Implemented logPlanExecution in loggers.ts to bridge the new PlanExecutionEvent to both OpenTelemetry for metrics and Clearcut for structured logs.
  • Tool Integration: The ExitPlanModeTool has been updated to trigger this logging event only upon successful plan approval and subsequent mode switch.
Changelog
  • packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts
    • Added PlanExecutionEvent to the imported types.
    • Extended the EventNames enum with PLAN_EXECUTION.
    • Implemented logPlanExecutionEvent to handle logging of plan execution events to Clearcut, including the approval_mode.
  • packages/core/src/telemetry/loggers.ts
    • Imported PlanExecutionEvent and recordPlanExecution.
    • Added a new logPlanExecution function to log plan execution events to both Clearcut and OpenTelemetry, and to record the corresponding metric.
  • packages/core/src/telemetry/metrics.test.ts
    • Imported recordPlanExecution for testing purposes.
    • Added new test cases for recordPlanExecution to verify its behavior, ensuring metrics are recorded correctly when initialized and not recorded otherwise.
  • packages/core/src/telemetry/metrics.ts
    • Defined a new constant PLAN_EXECUTION_COUNT for the metric name.
    • Added PLAN_EXECUTION_COUNT to COUNTER_DEFINITIONS, specifying its description and approval_mode attribute.
    • Declared planExecutionCounter to manage the new metric.
    • Implemented the recordPlanExecution function to increment the PLAN_EXECUTION_COUNT metric with relevant attributes.
  • packages/core/src/telemetry/types.ts
    • Extended the TelemetryEvent union type to include the new PlanExecutionEvent.
    • Defined the PlanExecutionEvent class, which encapsulates the event name and approval_mode, and provides methods for OpenTelemetry attributes and log body generation.
  • packages/core/src/tools/exit-plan-mode.test.ts
    • Mocked the logPlanExecution function for testing.
    • Added a test case to ensure that logPlanExecution is invoked with the correct approval_mode when a plan is successfully approved and executed.
  • packages/core/src/tools/exit-plan-mode.ts
    • Imported logPlanExecution and PlanExecutionEvent.
    • Integrated the call to logPlanExecution within the ExitPlanModeInvocation to log the event when a plan is approved and the approval mode is set.
Activity
  • The pull request is currently marked as a Work In Progress (WIP), indicating ongoing development.
  • Initial implementation of a new telemetry metric and associated logging for 'Plan Mode' execution has been completed.
  • Unit tests have been added to validate the correct recording of the new plan execution metric.
  • The author, Adib234, has provided a detailed summary and implementation steps in the PR description.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Adib234 Adib234 marked this pull request as draft February 3, 2026 21:54
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new telemetry metric, PLAN_EXECUTION_COUNT, to track the execution of plans generated in Plan Mode. The changes are well-structured and consistently follow existing patterns for adding new telemetry events and metrics. I've identified one critical issue in the implementation of the PlanExecutionEvent class where it fails to initialize required properties, leading to data loss in telemetry. This also includes ensuring telemetry keys accurately reflect semantic meaning, as per repository guidelines. My review includes a code suggestion to fix this.

I am having trouble creating individual review comments. Click here to see my feedback.

packages/core/src/telemetry/types.ts (1927-1939)

critical

The PlanExecutionEvent class doesn't initialize the event.name and event.timestamp properties required by the BaseTelemetryEvent interface. This leads to missing timestamp information in the telemetry data for OpenTelemetry. Additionally, the attribute key for the event name should be 'event.name' for consistency with OpenTelemetry semantic conventions and other events in the codebase, rather than event_name.

This change initializes the properties in the constructor and corrects the attribute in toOpenTelemetryAttributes to ensure complete and consistent event logging.

  constructor(approvalMode: ApprovalMode) {
    this['event.name'] = this.eventName;
    this['event.timestamp'] = new Date().toISOString();
    this.approval_mode = approvalMode;
  }
  'event.name': string;
  'event.timestamp': string;

  toOpenTelemetryAttributes(config: Config): LogAttributes {
    return {
      ...getCommonAttributes(config),
      'event.name': this.eventName,
      'event.timestamp': this['event.timestamp'],
      approval_mode: this.approval_mode,
    };
  }
References
  1. When logging events, ensure that the keys used for telemetry data accurately reflect the semantic meaning of the data being logged to avoid misinterpretation. Introduce new, more specific keys when existing ones are semantically confusing in a given context.

@Adib234 Adib234 force-pushed the adibakm/execution-metric-plan-mode branch from ab8ae74 to 122cbdd Compare February 3, 2026 21:57
@Adib234 Adib234 marked this pull request as ready for review February 3, 2026 22:00
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 3, 2026

Size Change: +2.69 kB (+0.01%)

Total Size: 23.7 MB

Filename Size Change
./bundle/gemini.js 23.7 MB +2.69 kB (+0.01%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB

compressed-size-action

@gemini-cli gemini-cli bot added area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Feb 3, 2026
@Adib234 Adib234 changed the title [WIP] feat(plan): create a metric for execution of plans generated in plan mode feat(plan): create a metric for execution of plans generated in plan mode Feb 4, 2026
Copy link
Copy Markdown
Contributor

@jerop jerop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Adib234 Adib234 requested a review from a team as a code owner February 5, 2026 21:08
@jerop jerop added this pull request to the merge queue Feb 5, 2026
Merged via the queue into main with commit 4ffc349 Feb 6, 2026
25 of 26 checks passed
@jerop jerop deleted the adibakm/execution-metric-plan-mode branch February 6, 2026 00:01
sidwan02 pushed a commit to sidwan02/gemini-cli-gemma that referenced this pull request Feb 6, 2026
aswinashok44 pushed a commit to aswinashok44/gemini-cli that referenced this pull request Feb 9, 2026
kuishou68 pushed a commit to iOfficeAI/aioncli that referenced this pull request Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a metric for execution of plans generated in plan mode

3 participants