Skip to content

[Task]: Add a /metrics endpoint to the orchestrator for observability #87

Description

@grantfox-oss

The orchestrator runs long-lived on Render and processes tasks asynchronously, but there is no way to observe its health beyond tailing logs. Basic operational questions — how many tasks are in flight, how many completed vs failed, how long steps take, how much USDC has been released — currently require scraping logs or querying the vault. That makes it hard to build a status dashboard or an alert, and hard to notice a slow degradation.

Goal

Add GET /metrics exposing process- and task-level counters, and wire the counters into the task/step lifecycle so they reflect reality.

Requirements & constraints

  • At minimum expose: process uptime; task counts (total / active / completed / failed); step counts (executed / failed / timed-out); total USDC released; and a step-duration summary (at least p50 / p95 / max).
  • Counters live in a small in-process module and are incremented from the executor and the task lifecycle. Seed from the existing stores where possible (orchestrator-store.ts, task-results.ts, activity-store.ts) so a restart doesn't zero everything that's already knowable.
  • Keep it dependency-free for the first version — a plain counters object with increment helpers. Do not pull in a heavyweight metrics library.

Design decisions left to the implementer

  • Output format. Plain JSON is the least-effort and easiest for the dashboard to consume; Prometheus text exposition is a reasonable alternative if you want Grafana compatibility. Pick one, document it, and keep the shape stable.
  • How step durations are sampled/stored to compute percentiles without unbounded memory (e.g. a bounded reservoir or a fixed-size ring).

Edge cases to consider

  • Concurrent tasks incrementing counters (JS is single-threaded, but async interleaving still needs correct increment ordering).
  • A task that fails mid-flight must move out of active and into failed, not linger in both.

Acceptance criteria

  • GET /metrics returns the counters above plus uptime, in the chosen format
  • Counters increment on task submit / complete / fail and step execute / timeout
  • usdc_released_total reflects released payments
  • Step-duration summary (≥ p50/p95/max) is included and memory-bounded
  • Endpoint documented in docs/development.md
  • Vitest coverage for the counter module and the endpoint shape
  • npm test passes

Relevant files

  • packages/orchestrator/src/server.ts, packages/orchestrator/src/executor.ts, new packages/orchestrator/src/metrics.ts, docs/development.md

Notes for contributors

If you'd like to work on this, comment below so we can assign it to you.
Questions welcome — see CONTRIBUTING.md for setup
and workflow.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions