{"repo":"snok/asgi-correlation-id","free":true,"listed":false,"github":"https://github.com/snok/asgi-correlation-id","clone":"git clone https://github.com/snok/asgi-correlation-id.git","description":"Request ID propagation for ASGI apps","language":"Python","stars":639,"topics":["logging","python","request-id","correlation-id","tracing","sentry","celery"],"license":"MIT","category":"analytics","readme_excerpt":"ASGI Correlation ID middleware Middleware for reading or generating correlation IDs for each incoming request. Correlation IDs can then be added to your logs, making it simple to retrieve all logs generated from a single HTTP request. When the middleware detects a correlation ID HTTP header in an incoming request, the ID is stored. If no header is found, a correlation ID is generated for the request instead. The middleware checks for the X-Request-ID header by default, but can be set to any key. X-Correlation-ID is also pretty commonly used. Example Once logging is configured, your output will go from this: to this: Now we're actually able to see which logs are related. Installation Setup To set up the package, you need to add the middleware and configure logging. Adding the middleware The middleware can be added like this: or any other way your framework allows. For Starlette apps, just substitute FastAPI with Starlette in all examples. Configure logging This section assumes you have already started configuring logging in your project. If this is not the case, check out the section on setting up logging from scratch instead. To set up logging of the correlation ID, you simply have to add the log-filter the package provides. If your current log-config looked like this: You simply have to add the filter, like this: If you're using a json log-formatter, just add correlation-id: %(correlation id)s to your list of properties. Middleware configuration The middleware can be configu","default_branch":null,"files":null,"tree":[],"storefront":"/r/snok","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/snok/asgi-correlation-id/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}