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

Pre-process incoming requests? #3378

Closed
thanatos opened this issue Nov 2, 2018 · 3 comments
Closed

Pre-process incoming requests? #3378

thanatos opened this issue Nov 2, 2018 · 3 comments
Labels
documentation Improvements or additions to documentation enhancement outdated

Comments

@thanatos
Copy link
Contributor

thanatos commented Nov 2, 2018

Long story short

Is it possible to hook/log requests at the start of the request? (aiohttp's AccessLogger is invoked after the request, as it receives the response as one of its arguments.)

As part of our logging, we'd like to assign each request a unique ID. Ideally the request comes in w/ this in a header, but if it doesn't, we assign it one. Currently, we do this in an AccessLogger, when we log there, however, this means this ID isn't associated w/ the request until the very end. I was wondering if it's possible to hook the very start of the request, s.t. this can happen as early as possible. This allows other logging calls that occur during the processing of the request to access this context. Essentially, I want to be able to know that "this log line indicating a DB call belongs to this request", which is made difficult when aiohttp handles multiple requests simultaneously, as the logs get intertwined. Hence, attaching an ID allows the log reader to understand which lines apply to which requests.

I can wrap every request handler in a decorator to accomplish this, but I was wondering if there was something more convenient.

@aio-libs-bot
Copy link

GitMate.io thinks the contributor most likely able to help you is @asvetlov.

Possibly related issues are #619 (Not possible to do requests with pre-compressed data), #669 (Log request process time in seconds), #875 (Improve Request.repr), #575 (how to log the incoming requests and the response), and #242 (Request's storage).

@aio-libs-bot aio-libs-bot added documentation Improvements or additions to documentation enhancement labels Nov 2, 2018
@asvetlov
Copy link
Member

asvetlov commented Nov 2, 2018

Try a middleware

@asvetlov asvetlov closed this as completed Nov 8, 2018
@lock
Copy link

lock bot commented Nov 8, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Nov 8, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Nov 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation enhancement outdated
Projects
None yet
Development

No branches or pull requests

3 participants