6 views
-/https://github.com/berriai/litellm/issues/31864
GitHub · issue

#31864 feat(logging): JSON log records have no request-scoped identifiers when JSON_LOGS=true

  • State: open
  • Author: @deepanshululla

## Problem

LiteLLM emits structured JSON log records via three module-level logger singletons (`verbose_logger`, `verbose_proxy_logger`, `verbose_router_logger`) instantiated in `litellm/_logging.py`. `JsonFormatter.format()` (lines 159-190) serializes `message`, `level`, `timestamp`, extra `{}` kwargs, and embedded Python dicts but has no mechanism to inject request-scoped identifiers such as `session_id` or `trace_id` into the emitted JSON record.

In production environments with concurrent async requests, this means log lines are interleaved with no way to group them per request. The `Logging` object created per-request in `litellm/litellm_core_utils/litellm_logging.py` does hold `self.litellm_trace_id` (line 347), but that object is never accessible from inside `JsonFormatter.format()`. Operators cannot reconstruct a request's lifecycle from logs alone.

## Root cause

`JsonFormatter` in `litellm/_logging.py` has no request-scoped context. The `Logging` object's `litellm_trace_id` and caller-supplied `litellm_session_id` are never stored in a `ContextVar`, so they cannot be read inside `format()` without passing them through every intervening function call.

## Reproduction

`…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (1 events)
#0 of 0 · 31d18h28m38s ago — entered · #import:https:::github.com:berriai:litellm post #2691
Issue 31864 is harder because it requires designing and safely propagating request context across asynchronous execution boundaries, integrating it with shared logging infrastructure, and validating behavior under concurrency without breaking existing log formats. Issue 14667 is comparatively localized to configuration parsing and header-to-user mapping behavior.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search