Skip to content

fix(structlog): log retry args/kwargs as original objects, not repr strings - #152

Open
okxint wants to merge 1 commit into
hynek:mainfrom
okxint:fix/structlog-args-not-repr
Open

okxint wants to merge 1 commit into
hynek:mainfrom
okxint:fix/structlog-args-not-repr

Conversation

@okxint

@okxint okxint commented Sep 15, 2026

Copy link
Copy Markdown

Fixes #151.

Problem

init_structlog() was wrapping every positional argument with repr() before passing it to structlog:

args=tuple(repr(a) for a in details.args),

This converted the original Python objects into opaque strings before any structlog processor ever saw them. Processors that need the real values — censoring/redacting sensitive fields, JSON serialization, filtering by type — received "'secret'" (a string) instead of the actual object.

kwargs was already passed through as-is, so this aligns args with the same treatment.

Fix

# Before
args=tuple(repr(a) for a in details.args),
kwargs=dict(details.kwargs.items()),

# After
args=details.args,
kwargs=dict(details.kwargs),

Test

Added test_args_logged_as_original_objects which passes a sentinel object as both a positional and keyword argument, then asserts that the log entry contains the exact same object (by identity), not a repr string.

…trings

init_structlog() was wrapping every positional argument with repr():

    args=tuple(repr(a) for a in details.args)

This turned the original Python objects into opaque strings before
structlog processors ever saw them, breaking use-cases like:

  - Censoring/redacting sensitive values (a processor receives
    "'secret'" instead of the object it knows how to detect)
  - JSON serialization (repr strings aren't valid JSON primitives)
  - Log filtering based on argument type or value

kwargs already passed through as-is (dict(details.kwargs.items())),
so args gets the same treatment now.

Fixes hynek#151
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.

structlog hook repr()s and flattens args so structlog log processors can't censor/inspect them properly

1 participant