Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).
## Unreleased

### Fixed

- `get_request_logger()` now raises the documented `RuntimeError` instead of `AttributeError` when called before `init_request_instrument()`.

## 1.6.0 - 2026-10-21

### Added
Expand Down
3 changes: 2 additions & 1 deletion json_logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def get_request_logger():
"request_logger is only available if json_logging is inited with a web app, "
"call init_<framework_name>() to do that")

instance = _current_framework['app_request_instrumentation_configurator']._instance
# _instance only exists once the configurator has been instantiated by init_request_instrument()
instance = getattr(_current_framework['app_request_instrumentation_configurator'], '_instance', None)
if instance is None:
raise RuntimeError("please init request instrument first, call init_request_instrument(app) to do that")

Expand Down
17 changes: 17 additions & 0 deletions tests/test_get_request_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""get_request_logger() error handling before request instrumentation is configured."""
import pytest
from helpers.imports import undo_imports_from_package


@pytest.fixture
def fresh_json_logging():
undo_imports_from_package("json_logging")
import json_logging
yield json_logging
undo_imports_from_package("json_logging")


def test_get_request_logger_after_init_but_before_request_instrumentation_raises_runtime_error(fresh_json_logging):
fresh_json_logging.init_flask()
with pytest.raises(RuntimeError, match="init request instrument first"):
fresh_json_logging.get_request_logger()
Loading