2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-04-06 19:41:16 +00:00

feat(backend): add request id (#11666)

helpful for https://github.com/inventree/InvenTree/issues/9996
This commit is contained in:
Matthias Mair
2026-04-03 05:07:27 +02:00
committed by GitHub
parent 5c55f4f4c0
commit 45de695d4f
2 changed files with 18 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
"""Helpers for logging integrations."""
from django.dispatch import receiver
import structlog
from django_structlog import signals
@receiver(signals.update_failure_response)
@receiver(signals.bind_extra_request_finished_metadata)
def add_request_id_to_response(response, logger, **kwargs):
"""Add the request ID to the response header, so that it can be traced through logs.
source: https://django-structlog.readthedocs.io/en/latest/how_tos.html#bind-request-id-to-response-s-header
"""
context = structlog.contextvars.get_merged_contextvars(logger)
response['X-InvenTree-ReqId'] = context['request_id']

View File

@@ -20,6 +20,7 @@ import build.api
import common.api import common.api
import company.api import company.api
import importer.api import importer.api
import InvenTree.logging # noqa: F401 - ensure logging handlers are registered
import machine.api import machine.api
import order.api import order.api
import part.api import part.api