Skip to content

Conversation

@michaelkedar
Copy link
Member

was getting errors like this:

>>> logging.info('hello', extra={'json_fields': {'hi': 'there'}})
Traceback (most recent call last):
  File "<python-input-17>", line 1, in <module>
    logging.info('hello', extra={'json_fields': {'hi': 'there'}})
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/logging/__init__.py", line 2196, in info
    root.info(msg, *args, **kwargs)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/logging/__init__.py", line 1520, in info
    self._log(INFO, msg, args, **kwargs)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/logging/__init__.py", line 1663, in _log
    record = self.makeRecord(self.name, level, fn, lno, msg, args,
                             exc_info, func, extra, sinfo)
  File "/usr/lib/python3.13/logging/__init__.py", line 1637, in makeRecord
    raise KeyError("Attempt to overwrite %r in LogRecord" % key)
KeyError: "Attempt to overwrite 'json_fields' in LogRecord"

Changing the extra information injector from a factory to a filter seems to fix this

@michaelkedar michaelkedar requested a review from cuixq November 7, 2025 01:08
@michaelkedar michaelkedar enabled auto-merge (squash) November 7, 2025 01:24
@michaelkedar michaelkedar merged commit e406c19 into google:master Nov 7, 2025
18 checks passed
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.

2 participants