aiohttp middleware: ensures each request has a unique request ID.

    See: ``inject_request_id``.

async def inject_request_id(app, handler):
    """aiohttp middleware: ensures each request has a unique request ID.

    See: ``inject_request_id``.
    """

    async def trace_request(request):
        request['x-request-id'] = \
            request.headers.get('x-request-id') or str(uuid.uuid4())
        return await handler(request)

    return trace_request