Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced DEBUG_API_REQUESTS #287

Open
pgcd opened this issue Nov 4, 2022 · 2 comments
Open

Reduced DEBUG_API_REQUESTS #287

pgcd opened this issue Nov 4, 2022 · 2 comments
Labels
future design Ideas/improvements that need some design work

Comments

@pgcd
Copy link

pgcd commented Nov 4, 2022

Just a suggestion: would it be possible to add a "reduced" DEBUG_API_REQUESTS implementation to log only basic information about the requests and responses (eg. status code, possibly errors in the response; a subset of fields in the request) to allow use outside dev environments?
I'm asking because we had an impossible to track intermittent problem with some notifications (ESP is Postmark) - all our logs confirmed that the email was sent, but nothing was apparently received by Postmark, and Anymail showed no error.

@medmunds
Copy link
Contributor

medmunds commented Nov 5, 2022

Long-term I'm thinking Anymail should really embrace the Python logging facility, replacing DEBUG_API_REQUESTS. So log.info every send, with the sort of minimal info you describe. And log.debug the full request/response (what DEBUG_API_REQUESTS does now). Probably log webhooks the same way. Maybe even log.warning any errors ignored by Django's fail_silently send option.

And then the standard Django LOGGING settings would control it all, allowing users to change the log level for the anymail module (or even individual ESP backends, I guess).

Short-term, for requests-based backends (all but Amazon SES), you could use the new requests session customization hook that will be in Anymail 9.0 to add your own logging of anything you want:

def log_response(response):
    # do any logging you want here...
    # response is a requests.Response
    request = response.request  # request is a requests.PreparedRequest
    print(request.url, response.status_code)

class MyDebugPostmarkBackend(anymail.backends.postmark.EmailBackend):
    def create_session(self):
        session = super().create_session()
        session.hooks['response'].append(log_response)
        return session

(And then in settings.py, set EMAIL_BACKEND = 'path.to.your.MyDebugPostmarkBackend'.

@pgcd
Copy link
Author

pgcd commented Nov 5, 2022

Excellent, thanks - both are perfectly viable solutions, looking forward to them.

@medmunds medmunds added the future design Ideas/improvements that need some design work label Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future design Ideas/improvements that need some design work
Projects
None yet
Development

No branches or pull requests

2 participants