@@ -0,0 +1,1029 @@
+import time%0Afrom structlog import get_logger%0Afrom profiles.verifier import get_key_from_request%0A%0Alogger = get_logger(%22openstates%22)%0A%0A%0Adef structlog_middleware(get_response):%0A    def middleware(request):%0A        msg = None%0A%0A        if request.path.startswith(%22/api/v1/%22):%0A            msg = %22v1%22%0A        if request.path.startswith(%22/graphql%22):%0A            msg = %22graphql%22%0A%0A        if msg:%0A            log = logger.bind(%0A                user_agent=request.META.get(%22HTTP_USER_AGENT%22, %22UNKNOWN%22),%0A                remote_addr=request.META.get(%22REMOTE_ADDR%22),%0A                api_key=get_key_from_request(request),%0A                url=request.path_info,%0A                params=request.GET if request.method == %22GET%22 else request.body,%0A            )%0A            start = time.time()%0A%0A        response = get_response(request)%0A%0A        if msg:%0A            log = log.bind(%0A                status_code=response.status_code, duration=time.time() - start,%0A            )%0A            log.info(msg)%0A%0A        return response%0A%0A    return middleware%0A

add middleware