uplink icon indicating copy to clipboard operation
uplink copied to clipboard

Add logging for retrying

Open nikita-sheremet-java-developer opened this issue 8 months ago • 1 comments

Is your feature request related to a problem? Please describe. When uplink retries a request there is no log message. I have to enable all loging for requests.packages.urllib3. but this enables all http requests to log and I have to investigate when request are made and what http code they have. A situation become terrible when there other code that make requests not uplink one.

Describe the solution you'd like Add logging mechanism that will output (may be some condition for on/off) that request is goging to retry

I use something like this in my codebase, it works for requests and aiohttp clients, not sure about twisted

from uplink.retry.retry import _RetryTemplate, retry

class _RetryTemplateWithLog(_RetryTemplate):
    def after_response(self, request, response):
        # part of original method
        if not self._condition.should_retry_after_response(response):
            return self._process_timeout(None)

        print(f"response ({response.status_code}) retrying...")

        # part of original method
        return self._process_timeout(
            self._backoff.get_timeout_after_response(request, response)
        )


class retry(retry):
    def modify_request(self, request_builder):
        request_builder.add_request_template(
            _RetryTemplateWithLog(
                condition=self._when(request_builder),
                backoff=self._backoff,
                stop=self._stop,
            )
        )

mateochr avatar May 14 '25 11:05 mateochr