def METHOD_NAME(request):
    role_id = None
    if hasattr(request, "authz"):
        role_id = request.authz.id
    # Set up context varibales for structured logging. The context is included
    # with every log entry produced by this particular request
    clear_contextvars()
    bind_contextvars(
        v=__version__,
        method=request.method,
        endpoint=request.endpoint,
        referrer=request.referrer,
        ip=_get_remote_ip(),
        ua=str(request.user_agent),
        begin_time=datetime.utcfromtimestamp(request._begin_time).isoformat(),
        role_id=role_id,
        session_id=getattr(request, "_session_id", None),
        locale=getattr(request, "_app_locale", None),
        url=request.url,
        path=request.full_path,
        trace_id=request._trace_id,
    )