
    ^h                         S r SSKJr  SSKJr  SSKJrJrJr  SSKJ	r	  SSK
JrJr  S rS\S	\4S
 jrS\S\S\S\S\S\S	S4S jrg)z|
Handles logging DB success/failure to ServiceLogger()

ServiceLogger() then sends DB logs to Prometheus, OTEL, Datadog etc
    )datetimewraps)CallableDictTuple)ServiceTypes)!_get_parent_otel_span_from_kwargs get_litellm_metadata_from_kwargsc                 0   ^  [        T 5      U 4S j5       nU$ )a  
Decorator to log the duration of a DB related function to ServiceLogger()

Handles logging DB success/failure to ServiceLogger(), which logs to Prometheus, OTEL, Datadog

When logging Failure it checks if the Exception is a PrismaError, httpx.ConnectError or httpx.TimeoutException and then logs that as a DB Service Failure

Args:
    func: The function to be decorated

Returns:
    Result from the decorated function

Raises:
    Exception: If the decorated function raises an exception
c                  $  >#    [         R                  " 5       n T
" U 0 UD6I S h  vN n[         R                  " 5       nSSKJn  ST
R                  ;  ao  UR
                  R                  [        R                  T
R                  UR                  SS 5      XB-
  R                  5       UUT
R                  UU S.S9I S h  vN   U$ U b  [        U 5      S:  aq  [        U S   [        5      (       aY  U S   n[        US9nUbH  [        US9nUR
                  R                  [        R                   T
R                  USUUUS9I S h  vN   U$  GN$ N N! ["         a3  n	[         R                  " 5       n[%        U	T
UU UUS	9I S h  vN    U	eS n	A	ff = f7f)
Nr   proxy_logging_objPROXYparent_otel_spanfunction_namefunction_kwargsfunction_args)service	call_typer   duration
start_timeend_timeevent_metadata)kwargsg        )efuncr   argsr   r   )r   nowlitellm.proxy.proxy_serverr   __name__service_logging_objasync_service_success_hookr	   DBgettotal_secondslen
isinstancedictr
   r   BATCH_WRITE_TO_DB	Exception_handle_logging_db_exception)r   r   r   resultr   r   passed_kwargsr   metadatar   r   s             Y/home/james-whalen/.local/lib/python3.13/site-packages/litellm/proxy/db/log_db_metrics.pywrapperlog_db_metrics.<locals>.wrapper$   s      (||~
5	000F!)HDdmm+';;VV(OO"mm%+ZZ0BD%I&3BBD)%)-+1)-$ W   H M)  IMtAw-- $Q#D($  $/?}UH+??ZZ , > >"&--)9!$#-!)'/ [    MS 1
4  
	!)H.%!   G
	sv   FE E	BE =E>E FA>E EE F	E E E 
F&F FFFFr   )r   r2   s   ` r1   log_db_metricsr4      s#    $ 4[9 9v N    r   returnc                 Z    SSK nSSKJn  [        XUR                  UR
                  45      $ )z4
Returns True if the exception is related to the DB
r   N)PrismaError)httpxprisma.errorsr8   r)   ConnectErrorTimeoutException)r   r9   r8   s      r1   _is_exception_related_to_dbr=   c   s(    
 )au'9'95;Q;QRSSr5   r   r   r   r   r   Nc                   #    SSK Jn  [        U 5      SLa  g UR                  R	                  U [
        R                  UR                  UR                  S5      XT-
  R                  5       UUUR                  UUS.S9I S h  vN   g  N7f)Nr   r   Tr   r   )errorr   r   r   r   r   r   r   )
r!   r   r=   r#   async_service_failure_hookr	   r%   r"   r&   r'   )r   r   r   r   r   r   r   s          r1   r-   r-   n   s      = #1%T1

/
/
J
J--$67'668!]]%!
 K   s   A>B BB)__doc__r   	functoolsr   typingr   r   r   litellm._service_loggerr	   'litellm.litellm_core_utils.core_helpersr
   r   r4   r,   boolr=   r-    r5   r1   <module>rH      s      ( ( 0NbT9 T T
  	
   
r5   