Skip to content

emit budget_remaining metric to OTel#87

Merged
cchinchilla-dev merged 2 commits intomainfrom
fix/tech-debt-budget-otel-15
Apr 3, 2026
Merged

emit budget_remaining metric to OTel#87
cchinchilla-dev merged 2 commits intomainfrom
fix/tech-debt-budget-otel-15

Conversation

@cchinchilla-dev
Copy link
Copy Markdown
Owner

Summary

  • Add OTel observable gauge agentloom_budget_remaining_usd in MetricsManager, following the same callback pattern as the circuit breaker gauge
  • Update set_budget_remaining() to write to both OTel and Prometheus backends (was Prometheus-only)
  • Add on_budget_remaining() hook to WorkflowObserver
  • Wire engine to emit remaining budget after each step with cost
  • Remove section separator comments (# ---) from observer.py, metrics.py, sandbox.py

Test plan

  • uv run pytest — 690 pass, 7 e2e deselected
  • uv run mypy src/ — no issues
  • uv run ruff check src/ tests/ — all checks passed
  • New tests for on_budget_remaining observer hook and _budget_remaining dict population

Closes #15

Copilot AI review requested due to automatic review settings April 3, 2026 16:45
@github-actions github-actions bot added core Core engine, DAG, state observability Tracing, metrics, logging labels Apr 3, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class OpenTelemetry emission for “budget remaining” by extending the observability surface (metrics + observer hooks) and wiring the engine to publish remaining budget updates during workflow execution.

Changes:

  • Add OTel observable gauge agentloom_budget_remaining_usd and store per-workflow remaining budget for callback-based export.
  • Introduce WorkflowObserver.on_budget_remaining() and wire WorkflowEngine to emit remaining budget after each costed step.
  • Update/extend tests to cover the new observer hook and _budget_remaining state updates.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/agentloom/observability/metrics.py Adds _budget_remaining store and an OTel observable gauge callback; updates set_budget_remaining() to populate both OTel (dict) and Prometheus (gauge).
src/agentloom/observability/observer.py Adds on_budget_remaining() hook to forward remaining budget to metrics.
src/agentloom/core/engine.py Emits on_budget_remaining after each successful, costed step when a workflow budget is configured.
tests/observability/test_observer.py Adds tests for the new observer hook behavior.
tests/observability/test_metrics.py Adds assertion that set_budget_remaining() populates _budget_remaining.
src/agentloom/tools/sandbox.py Removes section-separator comments only (no behavioral change).

@cchinchilla-dev cchinchilla-dev merged commit b4e1f61 into main Apr 3, 2026
9 checks passed
@cchinchilla-dev cchinchilla-dev deleted the fix/tech-debt-budget-otel-15 branch April 3, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core engine, DAG, state observability Tracing, metrics, logging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

emit budget_remaining metric to OTel (not just Prometheus)

2 participants