Skip to content

fix: ensure metric aliases are always exported#164

Open
adepat06 wants to merge 1 commit into
Devnil434:mainfrom
adepat06:fix-ingest-counter-import
Open

fix: ensure metric aliases are always exported#164
adepat06 wants to merge 1 commit into
Devnil434:mainfrom
adepat06:fix-ingest-counter-import

Conversation

@adepat06

@adepat06 adepat06 commented Jun 20, 2026

Copy link
Copy Markdown

Description

This PR fixes a backend startup issue caused by INGEST_COUNTER and REASONING_TRIGGER_COUNTER not being consistently exported from libs/observability/metrics.py.

The aliases were defined inside a nested conditional block, which meant they were not created on all execution paths. As a result, importing these metrics in apps/backend/routes/ingest.py could raise:

ImportError: cannot import name 'INGEST_COUNTER' from 'libs.observability.metrics'

This prevented the FastAPI backend from starting successfully.

Changes Made

  • Moved the backwards-compatible metric aliases out of the nested conditional block.
  • Ensured INGEST_COUNTER and REASONING_TRIGGER_COUNTER are always available for import.
  • Preserved existing metric registration behavior.

Testing

Before

ImportError: cannot import name 'INGEST_COUNTER'

After

INFO: Started server process
INFO: Waiting for application startup.
INFO: Application startup complete.

Verification

  • Started the backend using:
uvicorn main:app --reload --port 8000
  • Confirmed successful startup without import errors.
  • Verified Swagger/OpenAPI documentation is accessible at:
http://127.0.0.1:8000/docs

Related Issue

Fixes #156

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of metric counter accessibility across all initialization scenarios.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d02e347c-61f6-4e11-b451-6d7a920beb13

📥 Commits

Reviewing files that changed from the base of the PR and between 3429ec9 and 91445f3.

📒 Files selected for processing (1)
  • libs/observability/metrics.py

📝 Walkthrough

Walkthrough

INGEST_COUNTER and REASONING_TRIGGER_COUNTER in libs/observability/metrics.py are moved from inside a conditional block to module scope, ensuring both aliases are defined at import time regardless of which branch the metrics registration logic takes.

Changes

Metric Alias Scope Fix

Layer / File(s) Summary
Promote metric aliases to module scope
libs/observability/metrics.py
INGEST_COUNTER and REASONING_TRIGGER_COUNTER are relocated from inside a conditional branch to module scope so they are always defined when the module is imported, resolving the ImportError raised by apps/backend/routes/ingest.py.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 A counter once hidden in branching code's maze,
Now hops to the top where imports can gaze.
No more ImportError at startup's bright dawn,
The backend awakens, the error is gone!
Three little lines shifted — the bug hops away~ 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: ensuring metric aliases are always exported by moving them outside conditional blocks.
Linked Issues check ✅ Passed The PR fully addresses the primary objective in issue #156 by relocating metric alias definitions outside the conditional block, ensuring INGEST_COUNTER and REASONING_TRIGGER_COUNTER are always exported and importable.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the import failure by moving metric aliases to module scope; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

[Bug]: Backend startup fails with ImportError for INGEST_COUNTER

1 participant