Skip to content

feat(telemetry): count tool calls of the stage planner by tool and outcome #3240

Closed

Description

@dan-petty

Problem

To tune a toolset, a person must see which tools a plan run calls, which ones return nothing or fail, and how many tokens each answer costs. Today the RunTrace comment on the item lists the calls of one run as text. No metric exists, so no trend shows across runs. The alternatives check ran 34 times and searched about 4 times, and nothing showed it (#2950). The same blind spot can hide a tool that the planner never calls.

Proposed change

Declare these instruments and send them with emit, by tool name, job (stage, later implement) and toolset:

  • devops_cli_roadmap_tool_calls_total with the outcome ok, empty or error.
  • devops_cli_roadmap_tool_answer_chars (histogram), the size of each answer after the cut.
  • devops_cli_roadmap_tool_calls_per_run (histogram) by job and toolset.
  • devops_cli_roadmap_tool_limit_hits_total, with the limit that stopped the run (calls, requests, window).

The RunTrace comment adds one line per run: the calls for each tool and the number of empty answers.

Add one panel to the Roadmap dashboard that reads the first two, and one alert rule with a promtool unit test: a tool of the set that no run called for 7 days while runs happened.

Acceptance criteria

  1. The four instruments are declared in the metrics module, no label has an unbounded value, and docs/TELEMETRY.md lists them.
  2. A test shows one call of each outcome and checks the labels.
  3. The trace comment shows the counts for each tool.
  4. The alert rule and its unit test pass.

Related: #3238, #2950, #3239.

Alternatives check of 2026-11-05: none.
Tool: none found.

Proposed design

Problem statement

The stage planner calls read-only tools, and no metric shows which tools it calls or how each call ends. The RunTrace comment lists one run only, so no trend shows across runs, and a tool that no run calls stays hidden. This change adds four bounded instruments, one line for each run in the comment, one panel in the existing items dashboard, and one alert rule with a promtool unit test. The earlier proposal named a Roadmap dashboard that does not exist, and this proposal puts the panel in k8s/monitoring/dashboards/project-metrics.json.

Acceptance criteria

Requirement: Tool-call instruments are declared

The four roadmap tool-call instruments SHALL be entries of INSTRUMENTS in src/devops_cli/telemetry/instruments.py, each with a bounded label set, and docs/TELEMETRY.md SHALL list each one with its kind, unit and labels.

Scenario: The registry and the document list the four instruments

  • WHEN A test reads INSTRUMENTS and docs/TELEMETRY.md.
  • THEN Both list devops_cli_roadmap_tool_calls_total, devops_cli_roadmap_tool_answer_chars, devops_cli_roadmap_tool_calls_per_run and devops_cli_roadmap_tool_limit_hits_total with the same kind and unit.

Requirement: Tool outcomes carry bounded labels

The tool-call counter SHALL record one observation for each tool result with the outcome ok, empty or error, and with the tool, job and toolset labels.

Scenario: One call of each outcome

  • WHEN A test records one ok, one empty and one error result for the same tool, job and toolset.
  • THEN The counter holds three series, and each series has the expected tool, job, toolset and outcome labels.

Requirement: Answer size is measured after the cut

The answer-size histogram SHALL observe the character count of each tool answer after the toolbox cut, with the tool, job and toolset labels.

Scenario: A long answer is cut

  • WHEN A test returns an answer longer than the cut and records it.
  • THEN The histogram observes the cut length and not the original length.

Requirement: Each run gives every tool a series

A stage run SHALL emit a zero increment of the tool-call counter for each tool of the toolset before it calls any tool.

Scenario: A run that calls no tool

  • WHEN A test runs the planner with a toolset of three tools, and the run makes no tool call.
  • THEN The counter holds three series with value 0 and the label outcome="ok".

Requirement: Calls per run and limit hits are measured

The calls-per-run histogram SHALL observe the tool calls of each run with the job and toolset labels, and the limit-hits counter SHALL record the limit that stopped the run.

Scenario: A run stops at the call limit

  • WHEN A test runs the planner until the call limit stops it.
  • THEN The histogram observes one run, and the counter holds one series with the label limit="calls".

Requirement: Trace comment shows tool counts

The RunTrace comment SHALL add one line for each run that lists the call count and the empty-answer count of each tool.

Scenario: A run calls two tools and one answer is empty

  • WHEN A test renders the comment for a run that calls two tools and gets one empty answer.
  • THEN The line names both tools with their call counts and the empty count.

Requirement: Dashboard panel reads tool metrics

The dashboard k8s/monitoring/dashboards/project-metrics.json SHALL hold one panel that queries devops_cli_roadmap_tool_calls_total and devops_cli_roadmap_tool_answer_chars.

Scenario: The dashboard JSON holds the tool panel

  • WHEN A test reads k8s/monitoring/dashboards/project-metrics.json.
  • THEN One panel has a query for each of the two metric names.

Requirement: Unused tool alert has a unit test

The alert rule SHALL fire for a tool with no call in 7 days while stage runs happened, and its promtool unit test SHALL pass.

Scenario: A tool is not called while runs happen

  • WHEN The promtool test feeds zero calls for one tool and calls for another tool over 7 days.
  • THEN The alert fires for the unused tool and not for the called tool.

Existing Tool Considered

Alternatives check of 2026-11-05: verdict none, and no tool named. OpenTelemetry Python SDK, Prometheus, Grafana and promtool cover metric declaration, OTLP export, native histograms, dashboard panels and alert unit tests. They lack the four instruments with the bounded tool, job, toolset, outcome and limit labels, the per-run comment line and the unused-tool rule, so this repository adds that code. The written cost is about 30,000 tokens to build, about 8,000 tokens a month to keep and fix, and about 3 days elapsed.

Key questions

  • Where are the metric instruments declared, sent and documented?: Each instrument is an entry of INSTRUMENTS in src/devops_cli/telemetry/instruments.py, with its name, kind, unit and description. emit() sends it with its attributes, and docs/TELEMETRY.md lists it in its table. tests/telemetry/test_telemetry_instruments.py fails on a metric that a module writes by name and on an emit() of an instrument outside INSTRUMENTS. [sources: src/devops_cli/telemetry/instruments.py, docs/TELEMETRY.md, tests/telemetry/test_telemetry_instruments.py, CONTRIBUTING.md:132]
  • Does the repository have a Roadmap dashboard that can hold the tool panel?: No. k8s/monitoring/dashboards holds 15 dashboards, and none of them is a Roadmap dashboard. The items panels are in k8s/monitoring/dashboards/project-metrics.json. The earlier proposal named a Roadmap dashboard that does not exist, and this proposal puts the panel in project-metrics.json. [sources: openspec/changes/2919-stuck-item-age-metrics-and-one/proposal.md:44]
  • Which metric kinds and label sets do the four instruments use?: Counters for devops_cli_roadmap_tool_calls_total and devops_cli_roadmap_tool_limit_hits_total; histograms for devops_cli_roadmap_tool_answer_chars and devops_cli_roadmap_tool_calls_per_run. The labels are tool, job, toolset, outcome and limit. The stage tool registry, the job name and the limit name bound every value. (best practice) [sources: docs/TELEMETRY.md, src/devops_cli/telemetry/instruments.py, src/devops_cli/roadmap/stage_toolbox.py, CONTEXT.md]
    • Chosen: Counters and histograms as named. They match the devops_cli_* naming and give the series that the panel and the alert read.
    • Rejected: Traces and logs only. They give no trend across runs and no PromQL alert.
    • Rejected: One generic counter with a free-form label. A free-form label is unbounded and cannot support the panel or the alert.
  • How does the stage planner tally the calls and empty answers of each run?: The toolbox wrapper tallies each tool result as it returns, keeps the per-run counts in memory, and passes them to the comment renderer in stage.py. It never parses RunTrace messages after the run. (best practice) [sources: src/devops_cli/roadmap/stage_toolbox.py, src/devops_cli/roadmap/agent_run.py, src/devops_cli/roadmap/stage.py]
    • Chosen: Tally in the tool wrapper. The outcome and the answer size are known at the result, and the comment needs the same tally.
    • Rejected: Parse RunTrace messages after the run. RunTrace holds no outcome and no empty count.
    • Rejected: Query Prometheus from the comment path. The comment path must not depend on the metrics backend.
  • How does the alert find a tool of the set that no run called?: Each stage run emits a zero increment of the tool-call counter for every tool of the toolset. The rule fires when sum by (tool) (increase(devops_cli_roadmap_tool_calls_total[7d])) is 0 while histogram_count(increase(devops_cli_roadmap_tool_calls_per_run[7d])) is greater than 0. (best practice) [sources: docs/TELEMETRY.md, src/devops_cli/roadmap/stage_toolbox.py, src/devops_cli/telemetry/instruments.py]
    • Chosen: Zero increment for each tool of the toolset at the start of a run. It gives every tool a series and keeps the four instruments of the issue.
    • Rejected: A static absent_over_time list in the rule. The list drifts from the tool registry and needs one expression for each tool.
    • Rejected: A separate availability gauge. It adds a fifth instrument that the issue does not request.
  • What does the dashboard panel show, and which file holds it?: One breakdown panel in k8s/monitoring/dashboards/project-metrics.json. It shows the call rate by tool and outcome from devops_cli_roadmap_tool_calls_total, and the average answer size by tool from devops_cli_roadmap_tool_answer_chars, both with the filter job="stage". (best practice) [sources: openspec/changes/2919-stuck-item-age-metrics-and-one/proposal.md:44, docs/TELEMETRY.md, CONTEXT.md]
    • Chosen: One breakdown panel in project-metrics.json. The items panels are in that file, and no Roadmap dashboard exists.
    • Rejected: A new Roadmap dashboard file. No such file exists, and a new dashboard needs its own provisioning.
    • Rejected: Two separate panels. It adds dashboard space and splits one comparison.
  • Which text does the answer-size histogram measure?: The text of the tool return after the toolbox cut, measured where the wrapper tallies the call. A long answer gives the cut length, not the original length. (best practice) [sources: src/devops_cli/roadmap/stage_toolbox.py, src/devops_cli/roadmap/refine_investigation.py]
    • Chosen: The text after the cut. It shows the size that the model reads, and a test can check it offline.
    • Rejected: The raw return before the cut. It shows a size that the model never saw.
    • Rejected: The tokens of the answer. No token counter exists for a tool return, and the cut is in characters.
  • What format does the per-run tool line of the RunTrace comment use?: One compact line in a stable tool order, such as Tool calls: read_file=3 (empty=0), search=2 (empty=1). It names every called tool with its call count and its empty-answer count. (best practice) [sources: src/devops_cli/roadmap/stage.py, src/devops_cli/roadmap/agent_run.py]
    • Chosen: One compact text line. It fits the existing comment and shows the counts at a glance.
    • Rejected: A JSON block. It is harder to read in the comment and adds no data.
    • Rejected: A Markdown table. A table is too heavy for one run line.
  • When is a tool answer empty?: An answer is empty when its text after the cut holds no non-whitespace character. A result with text is ok, and an exception or an error result is error. (best practice) [sources: src/devops_cli/roadmap/stage_toolbox.py, src/devops_cli/roadmap/agent_run.py]
    • Chosen: Whitespace-only text is empty. It matches the wording 'return nothing' of the issue and is easy to test.
    • Rejected: Only a null result is empty. A whitespace-only answer gives no information and would count as ok.
    • Rejected: Any answer below a size threshold is empty. A short answer can be valid, and the threshold is arbitrary.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/feature
    scope/telemetry
    status/new
    value/medium
    effort/medium
    on Nov 2, 2026
  2. devops-cli-service commented on Nov 2, 2026

    @devops-cli-service
    Contributor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/telemetry. The (telemetry) scope of the title gives the scope.
    • Priority: P2-Medium. The metrics help tune toolsets but do not block delivery or fix a defect.
    • Value: Medium. A person can see which tools the planner calls and which return nothing, which is needed to tune a toolset.
    • Effort: Medium. Four instruments, a trace line, one dashboard panel, and one alert rule with a unit test are required.
    • Related: feat(roadmap): metrics for the pipeline outcomes #3069, which asks for a different change. Both add roadmap metrics, a dashboard panel, and an alert rule, but #3069 covers pipeline-level outcomes while this candidate covers per-tool call counts, answer sizes, and limit hits.
  3. added
    priority/p2-medium
    status/ready
    and removed
    status/new
    on Nov 2, 2026
  4. devops-cli-service commented on Nov 2, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at dc26693 (see proposed design in issue body).

  5. devops-cli-service commented on Nov 2, 2026

    @devops-cli-service
    Contributor

    The stage job returned the item to New. The premise of the issue does not hold at the staging commit, so the job planned no change and opened no pull request.

    Evidence:

    placeholder

  6. added
    status/new
    and removed
    status/ready
    on Nov 2, 2026
  7. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Tool: none found

    Lacks:

    • No existing library emits the four requested instruments (devops_cli_roadmap_tool_calls_total, devops_cli_roadmap_tool_answer_chars, devops_cli_roadmap_tool_calls_per_run, devops_cli_roadmap_tool_limit_hits_total) with the bounded tool, job, toolset, outcome and limit labels that the acceptance criteria and the repo's instrument registry require.
    • Agent/LLM instrumentation libraries (e.g. OpenLLMetry) record tool calls as spans with tool-name and status attributes; they do not give counters/histograms with an empty outcome, answer-size-after-cut observations, per-run call counts or stopping-limit breakdowns.
    • No tool renders the per-run tool-call and empty-answer line in the RunTrace comment.
    • No tool ships the Roadmap dashboard panel that queries the two tool metrics or the 7-day unused-tool alert rule with its promtool unit test.
    • Even the closest Prometheus-exposed agent proxy metrics (litellm) are reported as missing model tool-call count/tool-name/size series, so nothing off the shelf supplies this telemetry.

    Searches run:

    • OpenTelemetry instrumentation for LLM agent tool calls metrics
    • OpenLLMetry tool call metrics span attributes
    • library counter tool calls by tool name outcome empty error agent prometheus metrics

    Sources:

    Checked on 2026-11-05. A person decides what this means for the item. The check changes no label and closes no issue.

  8. removed
    status/new
    on Nov 5, 2026
  9. 6 remaining items

  10. removed
    status/in-review
    on Nov 5, 2026
  11. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-05 19:48 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/telemetrytype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions