diff --git a/src/service/main.py b/src/service/main.py index 4ed4474..8d8d2c3 100644 --- a/src/service/main.py +++ b/src/service/main.py @@ -9,7 +9,7 @@ from fastapi import FastAPI, Request from src.initialize import initialize_app, initialize_logging -from src.utils import get_ip_client, inject_additional_attributes, timeit +from src.utils import inject_additional_attributes, timeit from langtrace_python_sdk import SendUserFeedback, langtrace from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span @@ -131,7 +131,7 @@ async def qa( # logger.info(messages) response, span_id, trace_id = await inject_additional_attributes( lambda: call_llm_api(model_name=model_name, messages=messages), - {"db.collection.name": collection_name, "service.ip": get_ip_client(request)} + {"db.collection.name": collection_name, "service.ip": request.client.host} ) answer = response.choices[0].message.content logger.info(answer) @@ -211,9 +211,3 @@ async def sleep(): async def asleep(): await asyncio.sleep(5) return {"status": "OK"} - - -@APP.get("/get-ip") -async def get_ip(request: Request): - client_host = request.client.host - return {"ip": client_host} diff --git a/src/utils.py b/src/utils.py index 69b2b8e..d4bb878 100644 --- a/src/utils.py +++ b/src/utils.py @@ -50,12 +50,3 @@ async def inject_additional_attributes(fn, attributes=None): context.attach(new_ctx) return await fn() - - -def get_ip_client(request: Request): - x_forwarded_for = request.headers.get('x-forwarded-for') - if x_forwarded_for: - ip_client = x_forwarded_for.split(',')[0] - else: - ip_client = request.client.host - return ip_client