mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-11 03:38:38 +00:00
perf(litellm_pre_call_utils.py): add otel tracing for pre-call utils
adds 200ms on calls with pgdb connected
This commit is contained in:
parent
d71f079b42
commit
1429bcc2de
2 changed files with 19 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import copy
|
||||
import time
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
|
||||
|
||||
from fastapi import Request
|
||||
|
|
@ -6,6 +7,7 @@ from starlette.datastructures import Headers
|
|||
|
||||
import litellm
|
||||
from litellm._logging import verbose_logger, verbose_proxy_logger
|
||||
from litellm._service_logger import ServiceLogging
|
||||
from litellm.proxy._types import (
|
||||
AddTeamCallback,
|
||||
CommonProxyErrors,
|
||||
|
|
@ -16,11 +18,15 @@ from litellm.proxy._types import (
|
|||
UserAPIKeyAuth,
|
||||
)
|
||||
from litellm.proxy.auth.auth_utils import get_request_route
|
||||
from litellm.types.services import ServiceTypes
|
||||
from litellm.types.utils import (
|
||||
StandardLoggingUserAPIKeyMetadata,
|
||||
SupportedCacheControls,
|
||||
)
|
||||
|
||||
service_logger_obj = ServiceLogging() # used for tracking latency on OTEL
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from litellm.proxy.proxy_server import ProxyConfig as _ProxyConfig
|
||||
|
||||
|
|
@ -293,6 +299,8 @@ async def add_litellm_data_to_request( # noqa: PLR0915
|
|||
"""
|
||||
from litellm.proxy.proxy_server import llm_router, premium_user
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
safe_add_api_version_from_query_params(data, request)
|
||||
|
||||
_headers = clean_headers(
|
||||
|
|
@ -539,6 +547,16 @@ async def add_litellm_data_to_request( # noqa: PLR0915
|
|||
verbose_proxy_logger.debug(
|
||||
f"[PROXY]returned data from litellm_pre_call_utils: {data}"
|
||||
)
|
||||
|
||||
end_time = time.time()
|
||||
await service_logger_obj.async_service_success_hook(
|
||||
service=ServiceTypes.PROXY_PRE_CALL,
|
||||
duration=end_time - start_time,
|
||||
call_type="completion",
|
||||
start_time=start_time,
|
||||
end_time=end_time,
|
||||
parent_otel_span=user_api_key_dict.parent_otel_span,
|
||||
)
|
||||
return data
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class ServiceTypes(str, enum.Enum):
|
|||
LITELLM = "self"
|
||||
ROUTER = "router"
|
||||
AUTH = "auth"
|
||||
PROXY_PRE_CALL = "proxy_pre_call"
|
||||
|
||||
|
||||
class ServiceLoggerPayload(BaseModel):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue