refactor(logging): hoist a safely-hoistable function-body import to module top

CorrelationContextFilter.filter()'s `import litellm` was a function-body
import; verified it can move to module top without a circular-import failure
(litellm/__init__.py already imports from litellm._logging before setting
request_correlation_in_logs, but a bare `import litellm` only binds the
already-in-sys.modules module object - the attribute itself isn't read until
filter() actually runs, by which point litellm is fully initialized).
This commit is contained in:
Deepanshu 2026-07-28 22:14:40 -04:00
parent 0f129ad31b
commit 5fe7041c8d

View file

@ -3,6 +3,8 @@ import contextvars
import logging
import os
import sys
import litellm
from datetime import datetime
from logging import Formatter
from typing import Any, Final
@ -113,8 +115,6 @@ class CorrelationContextFilter(logging.Filter):
"""
def filter(self, record: logging.LogRecord) -> bool:
import litellm
if not litellm.request_correlation_in_logs:
return True
trace_id = trace_id_var.get()