Skip to content

RFC: better logging #76

@vgavro

Description

@vgavro

I'm reviewing logging in httpx-retries, and have some suggestions.

Current logging
L1. transport.py: debug: handle_request_started, handle_request_finished - those logs are totally replaced by providing logging to Client.event_hooks["request"/"response"] and doesn't make much sense IMHO - as they are not retry transport specific at all.
L2. transport.py: debug: retry_operation (sync/async) request, response|exception - this is most useful log, lack sleep information
L3. retry.py: warning: Retry-After has no timezone, Retry-After invalid date
L4. retry.py: debug: sleep/asleep time (this is not much useful without _retry_operation request/response|exception info). (considering you have requests in parallel, you don't even understand which sleep actually applies to which retry)

What I propose to have
T1. (high severity) One log record for L2 and L4 - this is main issue here.
T2. (middle severity) Possibility to override T1 logging to use structlog, for example, based on application logic, not to extract request/response parameters from formatted string.
T3. (low severity) maybe (what do you think) drop L1 log entirely.

How to implement
To achieve T1, we need to either calculate sleep with public method after increment, log in transport, then call sleep(calculated_sleep) from transport.
Or better - pass (request, response) to Retry.sleep(), and call Retry._log_sleep(request, response, time_to_sleep) there, which can default to current implementation, but can be easily overriden on inheriting Retry class.
What do you think?.... problem is - passing request to Retry.sleep is breaking public api, BUT i don't think it's a big issue here... IMHO other options worse.

Thank you for your time on this! i'll be glad to create PR on this after your feedback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions