Skip to content

Observability — logs, metrics, and traces for agent#360

Open
clintjeff2 wants to merge 4 commits into
Bitcoindefi:mainfrom
clintjeff2:Observability-—-logs,-metrics,-and-traces-for-agent

Hidden character warning

The head ref may contain hidden characters: "Observability-\u2014-logs,-metrics,-and-traces-for-agent"
Open

Observability — logs, metrics, and traces for agent#360
clintjeff2 wants to merge 4 commits into
Bitcoindefi:mainfrom
clintjeff2:Observability-—-logs,-metrics,-and-traces-for-agent

Conversation

@clintjeff2

Copy link
Copy Markdown
Contributor

Motivation

  • Provide structured logging, counters, gauges, and duration histograms to make agent and payment flows diagnosable.
  • Expose a lightweight metrics snapshot endpoint for dashboards and the admin console to surface request/error rates, queue depth, agent health, and x402 revenue.
  • Instrument critical paths (agent lifecycle, task queue, API routes, x402 settle) so operations emit consistent logs/metrics for troubleshooting and billing visibility.

Description

  • Added a structured logger with Logtail support and safe JSON console fallback in lib/observability/logger.ts and a metrics registry in lib/observability/metrics.ts (counters, gauges, histograms, 24h buckets).
  • Added a dynamic metrics endpoint at app/api/internal/metrics/route.ts that returns the getMetricsSnapshot() payload for dashboards and scraping.
  • Replaced/adapted API route logging in lib/api-logging.ts to use the new logger and emit metric samples (request counters and api.route.duration_ms histogram).
  • Instrumented agent runtime and queue: lib/agent-runtime/agent.ts now logs agent.started/agent.stopped/task.started/task.completed/task.failed and records task metrics; lib/agent-runtime/task-queue.ts updates tasks.queue.depth gauges and emits structured queue transition logs.
  • Instrumented x402 settlement flows in app/api/protocol/x402/settle/route.ts to record x402.payments metrics and emit x402.settle.completed / x402.settle.failed logs.
  • Added an Observability tab in the admin console UI components/admin/admin-console.tsx with request/error charts, top failing agents, task duration percentiles, x402 revenue, and mini bar charts.

Testing

  • Ran linting: npx eslint lib/observability/logger.ts lib/observability/metrics.ts app/api/internal/metrics/route.ts components/admin/admin-console.tsx app/api/protocol/x402/settle/route.ts lib/api-logging.ts lib/agent-runtime/agent.ts lib/agent-runtime/task-queue.ts — succeeded.
  • Attempted npm test -- --runInBand (flag unsupported by Vitest) — failed due to unsupported flag.
  • Ran npm test (Vitest): test run completed but there are failures in task-drain tests (3 failing assertions): two expectations of processed count expected 200 but received 100, and one test attempted to read processed from an undefined result; overall test suite shows 3 failed / 412+ passed.
  • Typecheck attempt: repository has no typecheck script; running npx tsc --noEmit surfaced unrelated environment/test issues (e.g., missing external types referenced by the repo).

Closes #40

clintjeff2 and others added 4 commits June 27, 2026 08:18
…r-agents

Add structured observability: logger, metrics, metrics API, and admin UI
- Fixed type errors in `drain` route handler and `task-drain.test.ts` by adding missing `await` and correcting `publishSystemEvent` payload.
- Increased `MAX_PENDING_PER_AGENT` to 500 to support high-volume task tests.
- Escaped single quotes in `offline/page.tsx` to satisfy ESLint.
- Added `@base-org/account` and `@metamask/connect-evm` to resolve production build warnings.
- Suppressed unsafe declaration merging in Soroban client.
- Verified all checks (tsc, lint, test, build, size-limit) pass locally.

Co-authored-by: clintjeff2 <119521983+clintjeff2@users.noreply.github.com>
…7262

Fix CI failures (Typecheck, tests, build, and guards)
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Observability — logs, metrics, and traces for agent activity

1 participant