agents icon indicating copy to clipboard operation
agents copied to clipboard

JSON logs no longer include levelname, Datadog status mapping breaks

Open MonkeyLeeT opened this issue 1 month ago • 3 comments

Bug Description

  • PR #3199 switched the CLI logging to a custom JsonFormatter (livekit-agents/livekit/agents/cli/log.py).
  • That formatter only copies fields referenced in logging.PercentStyle.default_format, plus two hard- coded keys (level and name). It never emits the standard levelname.
  • The formatter also drops levelname from extras via _RESERVED_ATTRS, so applications can’t re-add it in handlers.
  • Result: production JSON logs now only contain level, not levelname. Datadog (and any tooling that expects the canonical Python field) can’t determine log status anymore.
    • As a workaround, we added ad hoc remapper logic to look at level field, but not in canonical way.

Expected Behavior

levelname is still in output json record

Reproduction Steps

Upgrade to 1.3.0+, then run agent with prod environment and json logger, and configure logging override as below

logging.PercentStyle.default_format = (
    "%(levelname)s %(message)s %(processName) %(threadName)s"
)

observe that levelname is not present in the json output


Operating System

Linux

Models Used

No response

Package Versions

livekit-agents=1.3.2

Session/Room/Call IDs

No response

Proposed Solution

Always include the levelname attribute in JSON output (the previous dependency did this by default), or provide a supported hook to restore it across processes. Otherwise every consumer has to monkeypatch json formatter before app runs, which is brittle.

Additional Context

No response

Screenshots and Recordings

No response

MonkeyLeeT avatar Nov 18 '25 07:11 MonkeyLeeT

does levelname exist in the json logs before agents 1.3? I tested with 1.2.18 and it's "level": "INFO".

longcw avatar Nov 18 '25 09:11 longcw

does levelname exist in the json logs before agents 1.3? I tested with 1.2.18 and it's "level": "INFO".

It does, you need to override the default formatting as below to expose it in final json.

    logging.PercentStyle.default_format = (
        "%(levelname)s %(message)s %(processName) %(threadName)s"
    )

But this is not working now after 1.2.18.

MonkeyLeeT avatar Nov 18 '25 17:11 MonkeyLeeT

@longcw Any update here?

MonkeyLeeT avatar Nov 25 '25 21:11 MonkeyLeeT

@longcw A friendly ping here.

MonkeyLeeT avatar Dec 03 '25 00:12 MonkeyLeeT

the issue is that the setting of logging.PercentStyle.default_format is not used, fixed in https://github.com/livekit/agents/pull/4169

longcw avatar Dec 04 '25 03:12 longcw