Skip to content

metrics: add kirocrew.app.run_time counter fed from emit_turn_duration #39773

Closed

Description

@chenmingwei23

Existing issues

  • I searched open issues and this is not already requested.

Problem

The app usage metrics plan (#38145) has no signal for how long an app's sessions work. Crew records turn duration for every session (kirocrew.turn.duration), but nothing attributes that time to the app that owns the session. So nobody can tell how much agent run time each app, and each version of it, consumes.

Why does this matter? (5 Whys)

  1. Why add a run time counter? App authors and Crew maintainers cannot see how much work an app's sessions do, so they cannot tell which apps are used heavily or which versions run long turns.
  2. Why can that not be read from kirocrew.turn.duration? That histogram has no app label, and turns of an app session cannot be told apart from all other turns.
  3. Why feed it from emit_turn_duration in src/kiro_crew/metrics/turns.py? It is the one boundary that both turn callers share (_emit_turn_metric in dashboard/chat_turn/turn_stats.py and _emit_turn_histogram in dashboard/handlers/usage.py), so every surface is counted once per turn and the app time can never exceed all turn time.
  4. Why is this its own change? It is RFC section 11 PR 5 of the app usage metrics plan (docs/request-for-change/rfc-app-usage-metrics.md on branch docs/rfc-app-usage-metrics). RFC PR docs(rfc): propose app usage metrics (installs, versions, sessions, run time) #39107 was closed unmerged; the owner wants the rest shipped as normal PRs. It needs app_public_version() from RFC PR 3 (feat(metrics): count app updates and uninstalls with the app's public version #39715, merged), and it is independent of the other rows.
  5. Why is it safe to add? The metric schema manifest is append-only, so one new row is an addition and breaks no reader.

Proposed behaviour

  • New counter kirocrew.app.run_time, unit s, scope kiro.crew, shape ("app", None, "app"), so it carries Feature, Activity and Entity like the other app rows.
  • Attributes beyond those: Entity is the app's public id, entity_version is the app's public version, and duration is the bucket of that one turn: le_10s, le_1m, le_5m, le_15m, le_1h, le_4h, gt_4h or other (the le_ / gt_ spelling of DURATION_BUCKETS in src/kiro_crew/metrics/work.py).
  • emit_turn_duration gains an owning_app argument. Both turn callers, _emit_turn_metric and _emit_turn_histogram, pass the session's trusted owning_app from the live provider. Sub-agent turns of an app session carry the same owning_app, so they count toward the app.
  • The value added is the turn's wall seconds, rounded up. A turn with no duration adds nothing, because a 0 would read as a measured instant turn.
  • A session with no owning_app adds nothing. The existing turn metric is unchanged.
  • A recorder that raises must not change the turn metric: the existing kirocrew.turn.duration and the other turn instruments are still emitted exactly as before.
  • The new row is added to the metric schema manifest (python test/metrics_schema_helpers.py --write), and the telemetry docs list it.
  • Tests: seconds are rounded up; bucket edges (10 s is le_10s, 11 s is le_1m; 4 h is le_4h, 4 h + 1 s is gt_4h); a turn with no duration adds nothing; both turn callers pass owning_app; no owning_app adds nothing; a raising recorder leaves the turn metric unchanged. Existing turn metric tests keep passing.

Alternatives considered

Add an app label to kirocrew.turn.duration. Rejected: the metric schema is append-only and that histogram is read by the Telemetry page, so a new label would split its existing series. A separate counter with the closed app shape is the same choice the other app rows made.

Anything else

No change to what users see. Done when the change is merged with tests and the manifest guard passes. Related: #38145 (umbrella), #39715 (RFC PR 3, merged).

Activity

  1. added
    enhancementNew feature or request
    area: appsApp Store, app-sdk, MCP apps, app runtime
    tier:T2Small additive feature; existing behaviour unchanged
    on Nov 20, 2026
  2. added 4 commits that reference this issue on Nov 20, 2026
    fb5da8a
    d48625a
    7e4b3cc
    b4b4670
  3. added a commit that references this issue on Nov 20, 2026
    f8a805a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: appsApp Store, app-sdk, MCP apps, app runtimeenhancementNew feature or requesttier:T2Small additive feature; existing behaviour unchanged

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions