
    ^h!                     h   S SK r S SKrS SKrS SKJr  S SKJr  S SKJr  \" 5       r	\R                  R                  SS5      R                  5       S:X  a   S SKr\" S5        \R                  " 5         \" S	5        \R                   " 5         \R"                  " 5       r\" S
5        \R                   " \S9  \R(                  " S5        \	R                  SSS9S 5       r\	R                  SSS9S 5       r\	R                  SSS9S 5       r\	R                  SSS9S 5       rS rg! \ a	    \" S5      ef = f)    N)	APIRouter)get_secret_str)verbose_proxy_loggerLITELLM_PROFILEfalsetruezgrowth of objectsz

Most common typesz

Leaking objects)objectsz@objgraph not found. Please install objgraph to use this feature.
   z/memory-usageF)include_in_schemac                  "  #    [         R                  " 5       n U R                  S5      n[        R                  " SU5        US S n/ nU H>  nUR                  UR                  R                  SS9 SUR                  S-   S35        M@     S	U0$ 7f)
NlinenozTOP STATS: %s2   r
   )limitz: i   z KiBtop_50_memory_usage)	tracemalloctake_snapshot
statisticsr   debugappend	tracebackformatsize)snapshot	top_statstop_50resultstats        `/home/james-whalen/.local/lib/python3.13/site-packages/litellm/proxy/common_utils/debug_utils.pymemory_usager      s      ,,.''1	""?I> 3BDMMT^^222<=R		D@P?QQUVW  &v..s   BBz/memory-usage-in-mem-cachec                  (  #    SSK Jn JnJn  U c  SnOS[	        U R
                  R                  R                  5      [	        U R
                  R                  R                  5      -   n[	        UR                  R                  5      [	        UR                  R                  5      -   n[	        UR                  R                  R                  R                  5      [	        UR                  R                  R                  R                  5      -   nUUUS.$ 7f)V
1. user_api_key_cache
2. router_cache
3. proxy_logging_cache
4. internal_usage_cache
r   
llm_routerproxy_logging_objuser_api_key_cache)num_items_in_user_api_key_cachenum_items_in_llm_router_cache$num_items_in_proxy_logging_obj_cache)litellm.proxy.proxy_serverr#   r$   r%   lencachein_memory_cache
cache_dictttl_dictinternal_usage_cache
dual_cache)r#   r$   r%   r'   r&   r(   s         r   memory_usage_in_mem_cacher1   /   s       ()%(+,,77)

  0099:);% '***55'..778'9# ,/..99IITT,22==MMVVW,X(
 ,K)F0T s   DDz /memory-usage-in-mem-cache-itemsc                    #    SSK Jn JnJn  U c  0 n0 nO@U R                  R
                  R                  nU R                  R
                  R                  nUR
                  R                  UR
                  R                  UUUR                  R                  R
                  R                  UR                  R                  R
                  R                  S.$ 7f)r!   r   r"   )r%   user_api_key_ttlllm_router_cachellm_router_ttlproxy_logging_obj_cacheproxy_logging_obj_ttl)
r)   r#   r$   r%   r+   r,   r-   r.   r/   r0   )r#   r$   r%   llm_router_in_memory_cache_dictllm_router_in_memory_ttl_dicts        r   memory_usage_in_mem_cache_itemsr:   T   s       *,'(*%*4*:*:*J*J*U*U'(2(8(8(H(H(Q(Q% 1@@KK.>>GG;7#4#I#I#T#T#d#d#o#o!2!G!G!R!R!b!b!k!k s   CCz/otel-spansc                    #    SSK Jn   U c  / 0 S S.$ U R                  n[        US5      (       a  UR	                  5       nO/ n[        SU5        S nSn0 nU Hn  nUR                  c  M  UR                  R                  nXu;  a  / XW'   XW   R                  UR                  5        UR                  U:  d  M`  UnUR                  nMp     U Vs/ s H  ofR                  PM     nnUUUS.$ s  snf 7f)Nr   )open_telemetry_logger)
otel_spansspans_grouped_by_parentmost_recent_parentget_finished_spanszSpans: i@B )r)   r<   OTEL_EXPORTERhasattrr@   printparenttrace_idr   name
start_time)	r<   otel_exporterrecorded_spansr?   most_recent_start_timer>   spanparent_trace_id
span_namess	            r   get_otel_spansrN   t   s    @$')"&
 	
 *77M}233&99;	)^$$ ;;""kk22O=;='8#4;;DIIF !77%4")-&  )77))J7 #:0  8s   A"C.(A
C.6C.C)!C.c                      [        S5      n U c  g [        R                  R                  U 5      (       a  g [        R
                  " U 5      n[        U[        5      (       d  g UR                  SS 5      nUR                  SS 5      nUSL aZ  SS K	nSSK
JnJnJn  UR                  UR                  S9  UR                  UR                  S9  UR                  " UR                  S9  USL a[  SS K	nSSK
JnJnJn  UR                  UR                   S9  UR                  UR                   S9  UR                  " UR                   S9  g USL a  USL a  [        R"                  R                  S	S
5      nUb  UR%                  5       S:X  a@  SS K	nSSK
JnJn  UR                  UR                  S9  UR                  " UR                  S9  g UR%                  5       S:X  a@  SS K	nSSK
JnJn  UR                  UR                   S9  UR                  " UR                   S9  g g g g g ! [&         a+  n	SS K	nUR)                  S[+        U	5       35         S n	A	g S n	A	ff = f)NWORKER_CONFIGr   detailed_debugTr   )verbose_loggerr   verbose_router_logger)levelFLITELLM_LOG INFO)r   rS   DEBUGz Failed to init verbose loggers: )r   ospathisfilejsonloads
isinstancedictgetlogginglitellm._loggingrR   r   rS   setLevelrW   rX   environupper	Exceptionwarningstr)
worker_config	_settingsr   rQ   ra   rR   r   rS   litellm_log_settinges
             r   init_verbose_loggersrm      s0   QE&7 77>>-((JJ}-	)T**gt,"'7>D=  ##',,#7!**ll +  !))=T!  ##'--#8!**mm +  !))mm e^% 7"$**.."C".&,,.&8" *22%ll 3  )11%ll )..0G;"
 *22%mm 3  )11%mm <# / !8^D  E:3q6(CDDEs6   H $H +H "C"H B H AH 
I(!II)r\   rY   r   fastapir   litellmr   rb   r   routerrd   r`   lowerobjgraphrC   show_growthshow_most_common_typesget_leaking_objectsrootsImportErrorstartr   r1   r:   rN   rm        r   <module>r{      sW    	   " 1	::>>#W-335?
!"%&''),,.#$''6 bZZ5Z9/ :/ (EB! C!H .%H I> MU3' 4'VREQ  
N
 	

s   AD" "D1