Skip to content

fix: raise RuntimeError from get_request_logger before request instrumentation - #139

Merged
cvas22 merged 1 commit into
masterfrom
fix/get-request-logger-before-instrumentation
Oct 24, 2026
Merged

cvas22 merged 1 commit into
masterfrom
fix/get-request-logger-before-instrumentation

Conversation

@cvas22

@cvas22 cvas22 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem: after init_flask() (or any framework init) but before init_request_instrument(), get_request_logger() raises AttributeError: type object ... has no attribute '_instance' instead of the intended RuntimeError("please init request instrument first ...").

Root cause: _instance is only set on the configurator class the first time it is instantiated, and the function read it directly.

Fix: read it with getattr(..., '_instance', None), so the existing None check produces the intended error.

Tests: new tests/test_get_request_logger.py fails before the change and passes after. Full unit suite (excluding smoke tests and gunicorn): 96 passed on Python 3.14.6, Windows.

Found while working on #137.

Summary by CodeRabbit

  • Bug Fixes
    • Calling get_request_logger() before request instrumentation is initialized now raises the documented RuntimeError instead of an AttributeError.
  • Tests
    • Added coverage for calling the logger before initialization.

…mentation

get_request_logger() read the configurator's _instance attribute, which
only exists after the configurator has been instantiated, so calling it
after init_<framework>() but before init_request_instrument() raised
AttributeError instead of the intended RuntimeError.

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1db7e421-118e-4b59-b8e1-bb5cf575f912
Commits

Reviewing files that changed from the base of the PR and between c775fe3 and a551ee5.

Files selected for processing: 3
  • CHANGELOG.md
  • json_logging/__init__.py
  • tests/test_get_request_logger.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Walkthrough

get_request_logger() now raises the documented RuntimeError when request instrumentation has not been initialized, instead of raising AttributeError. A test covers this case, and the changelog records the fix.

Changes: Request logger initialization error

Layer / File(s) Summary
Handle and test uninitialized request logger
json_logging/__init__.py, tests/test_get_request_logger.py, CHANGELOG.md
The function handles a missing configurator instance by raising the existing initialization error. A test verifies the error, and the changelog documents the fix.

Priority: Low

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Possibly related issues

  • Issue 137 identifies missing test coverage for get_request_logger() before request instrumentation. This change adds that coverage and fixes the expected RuntimeError behavior.

Suggested reviewers: bobbui

Merge Risk: Minimal · up to a551e

The narrowly scoped logger initialization fix is mergeable.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: get_request_logger now raises RuntimeError before request instrumentation.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@cvas22
cvas22 merged commit 10c4f58 into master Oct 24, 2026
16 checks passed

@llamapreview llamapreview Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LlamaPReview — Review stopped

This pull request was merged before the review finished, so LlamaPReview stopped the remaining model work. No code-review verdict was produced.

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.

1 participant