From 0c6c350c23477a241b9621fc375512afca8ed975 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 13 Aug 2024 15:22:54 -0700 Subject: [PATCH] feat log use_x_forwarded_for --- litellm/proxy/litellm_pre_call_utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.py index 13f9475c5..990cb5233 100644 --- a/litellm/proxy/litellm_pre_call_utils.py +++ b/litellm/proxy/litellm_pre_call_utils.py @@ -177,7 +177,17 @@ async def add_litellm_data_to_request( requester_ip_address = "" if premium_user is True: # Only set the IP Address for Enterprise Users + + # logic for tracking IP Address if ( + general_settings is not None + and general_settings.get("use_x_forwarded_for") is True + and request is not None + and hasattr(request, "headers") + and "x-forwarded-for" in request.headers + ): + requester_ip_address = request.headers["x-forwarded-for"] + elif ( request is not None and hasattr(request, "client") and hasattr(request.client, "host")