UAT: cost_budget_service.py uses standard logging instead of spec-required structlog #3763

Open
opened 2026-04-05 22:32:47 +00:00 by freemo · 0 comments
Owner

Bug Report

What Was Tested

Code-level analysis of src/cleveragents/application/services/cost_budget_service.py against the observability specification in docs/specification.md §Observability → Structured Logging.

Expected Behavior (from spec)

The specification (line ~45890) explicitly mandates:

All logging uses structlog with JSON output format.

This requirement applies to all modules in the codebase. The structlog library is listed as a required dependency (>= 24.4.0).

Actual Behavior

cost_budget_service.py uses the standard Python logging module instead of structlog:

# Line 16 — WRONG
import logging

# Line 30 — WRONG
logger = logging.getLogger(__name__)

Note: The logger variable is defined but never actually used in the current implementation — _emit_warning and _emit_exceeded silently return when no event bus is configured, without logging anything. This means budget enforcement failures and events are completely invisible in the log output.

Code Location

  • File: src/cleveragents/application/services/cost_budget_service.py
  • Lines 16 and 30

Steps to Reproduce

  1. Open src/cleveragents/application/services/cost_budget_service.py
  2. Observe import logging on line 16 and logger = logging.getLogger(__name__) on line 30
  3. Note that logger is never called anywhere in the file
  4. Compare with audit_service.py (same directory) which correctly uses import structlog and _logger = structlog.get_logger(__name__)

Fix Required

Replace:

import logging
...
logger = logging.getLogger(__name__)

With:

import structlog
...
_logger = structlog.get_logger(__name__)

Additionally, add structured log calls for budget events to improve observability:

def _emit_warning(self, session_id: str) -> None:
    _logger.warning("budget_warning", session_id=session_id, level="session")
    ...

def _emit_exceeded(self, session_id: str) -> None:
    _logger.warning("budget_exceeded", session_id=session_id)
    ...

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-uat-tester

## Bug Report ### What Was Tested Code-level analysis of `src/cleveragents/application/services/cost_budget_service.py` against the observability specification in `docs/specification.md` §Observability → Structured Logging. ### Expected Behavior (from spec) The specification (line ~45890) explicitly mandates: > **All logging uses structlog with JSON output format.** This requirement applies to **all** modules in the codebase. The `structlog` library is listed as a required dependency (`>= 24.4.0`). ### Actual Behavior `cost_budget_service.py` uses the standard Python `logging` module instead of `structlog`: ```python # Line 16 — WRONG import logging # Line 30 — WRONG logger = logging.getLogger(__name__) ``` Note: The `logger` variable is defined but **never actually used** in the current implementation — `_emit_warning` and `_emit_exceeded` silently return when no event bus is configured, without logging anything. This means budget enforcement failures and events are completely invisible in the log output. ### Code Location - **File**: `src/cleveragents/application/services/cost_budget_service.py` - **Lines 16 and 30** ### Steps to Reproduce 1. Open `src/cleveragents/application/services/cost_budget_service.py` 2. Observe `import logging` on line 16 and `logger = logging.getLogger(__name__)` on line 30 3. Note that `logger` is never called anywhere in the file 4. Compare with `audit_service.py` (same directory) which correctly uses `import structlog` and `_logger = structlog.get_logger(__name__)` ### Fix Required Replace: ```python import logging ... logger = logging.getLogger(__name__) ``` With: ```python import structlog ... _logger = structlog.get_logger(__name__) ``` Additionally, add structured log calls for budget events to improve observability: ```python def _emit_warning(self, session_id: str) -> None: _logger.warning("budget_warning", session_id=session_id, level="session") ... def _emit_exceeded(self, session_id: str) -> None: _logger.warning("budget_exceeded", session_id=session_id) ... ``` --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#3763
No description provided.