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

Idea: Add alternate request id factory that uses request counter #5

Open
messa opened this issue May 31, 2024 · 1 comment
Open

Idea: Add alternate request id factory that uses request counter #5

messa opened this issue May 31, 2024 · 1 comment
Assignees

Comments

@messa
Copy link
Owner

messa commented May 31, 2024

The default request id factory returns a random string:

2020-01-15 15:58:47,238  INFO: [req:O5bvIlU] Processing GET / (__main__:hello)
2020-01-15 15:58:47,950  INFO: [req:xtMacpA] Processing GET / (__main__:hello)

Sometimes I feel like adding request counter would be better:

2020-01-15 15:58:47,238  INFO: [req:xtMac0001] Processing GET / (__main__:hello)
2020-01-15 15:58:47,950  INFO: [req:xtMac0002] Processing GET / (__main__:hello)

I want to keep some random string in the request id so it can be better searched in logs.
Also it can help when logging from multiple processes (each having their own counter) to one log file.

Maybe let's provide an alternative request id factory for this and let users configure this one instead of the default request id factory.

@messa messa self-assigned this May 31, 2024
@messa
Copy link
Owner Author

messa commented Jun 2, 2024

Added in version 0.0.6. Commit: 11d286d

Sample log output:

2024-06-02 11:08:06,753 [MainThread] aiohttp_request_id_logging  INFO: [req:qphq0000] Processing GET / (__main__:hello)
2024-06-02 11:08:07,755 [MainThread] __main__                    INFO: [req:qphq0000] Doing something
2024-06-02 11:08:08,755 [MainThread] aiohttp.access              INFO: [req:qphq0000] 127.0.0.1 "GET / HTTP/1.1" 200 165 "-" "curl/7.88.1" 2.002257
2024-06-02 11:08:09,827 [MainThread] aiohttp_request_id_logging  INFO: [req:qphq0001] Processing GET / (__main__:hello)
2024-06-02 11:08:10,829 [MainThread] __main__                    INFO: [req:qphq0001] Doing something
2024-06-02 11:08:11,830 [MainThread] aiohttp.access              INFO: [req:qphq0001] 127.0.0.1 "GET / HTTP/1.1" 200 165 "-" "curl/7.88.1" 2.003048

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

No branches or pull requests

1 participant