Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
messa authored May 31, 2024
1 parent 3eccb03 commit 259e89b
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
aiohttp-request-id-logging
==========================

When you log from your web application, usually log messages from different requests are intertwined and you cannot surely tell which line was generated by what request. For example:
Motivation
----------

When logging from an async application (e.g. aiohttp web application),
log messages from different async tasks, http requests etc. are intertwined and you cannot surely tell which line was generated by what request.
For example:

```
2020-01-15 15:35:37,501 INFO: Processing money transfer id 1234
2020-01-15 15:35:37,976 INFO: Processing money transfer id 5678
2020-01-15 15:35:37,501 INFO: Processing transfer id 1234
2020-01-15 15:35:37,976 INFO: Processing transfer id 5678
2020-01-15 15:35:38,201 ERROR: Oh no, something bad has happened! Cannot finish the transfer.
2020-01-15 15:35:38,504 INFO: 127.0.0.1 [15/Jan/2020:14:35:36 +0000] "GET / HTTP/1.1" 200 165 "-" "curl/7.68.0"
2020-01-15 15:35:38,982 INFO: 127.0.0.1 [15/Jan/2020:14:35:36 +0000] "GET / HTTP/1.1" 500 165 "-" "curl/7.68.0"
```

So, which transfer has failed? The one with id 1234, or the one with id 5678?

When you start to use this library, this is how your log messages will look like:
Of course, ideally the error message should contain also the transfer id.
But it is not always this case, or you may want to inspect also other log messages that were logged by that specific task/request.

When you start to use this library in your aiohttp web application, this is how your log messages will look like:

```
2020-01-15 15:58:47,238 INFO: [req:O5bvIlU] Processing GET / (__main__:hello)
Expand Down Expand Up @@ -89,4 +97,19 @@ This library helps you to add request (correlation) id to the log messages in a

Sentry integration will be active only if you have `sentry_sdk` installed.

Motivation: https://stackoverflow.com/a/58801740/196206

Alternatives
------------

- TODO: find other solutions to this problem, perhaps also from different frameworks or platforms


Links
-----

In general, you should be familiar with Aiohttp documentation related to production deployment:

- https://docs.aiohttp.org/en/stable/web_advanced.html#deploying-behind-a-proxy
- https://docs.aiohttp.org/en/stable/deployment.html

This is where this started: https://stackoverflow.com/a/58801740/196206

0 comments on commit 259e89b

Please sign in to comment.