
    ^h                     p    S r SSKJrJrJrJr  SSKJr  SSKJ	r	J
r
  \(       a  SSKJr  O\r " S S5      rg	)
z
This file contains the LangFuseHandler class

Used to get the LangFuseLogger for a given request

Handles Key/Team Based Langfuse Logging
    )TYPE_CHECKINGAnyDictOptional)StandardCallbackDynamicParams   )LangFuseLoggerLangfuseLoggingConfig)DynamicLoggingCachec            
           \ rS rSr\ SS\S\S\\   S\4S jj5       r	\S\\   S\S\4S j5       r
\S	\S\S\4S
 j5       r\ SS\S\\   S\4S jj5       r\S\S\4S j5       rSrg)LangFuseHandler   N standard_callback_dynamic_paramsin_memory_dynamic_logger_cacheglobalLangfuseLoggerreturnc                     Un[         R                  U 5      SL a  [         R                  UUS9$ [         R                  UU S9n[	        U5      nUR                  USS9nUc  [         R                  UUS9nU$ )aR  
This function is used to get the LangFuseLogger for a given request

1. If dynamic credentials are passed
    - check if a LangFuseLogger is cached for the dynamic credentials
    - if cached LangFuseLogger is not found, create a new LangFuseLogger and cache it

2. If dynamic credentials are not passed return the globalLangfuseLogger

F)r   r   )r   r   langfusecredentialsservice_namer   r   )r   (_dynamic_langfuse_credentials_are_passed_return_global_langfuse_logger#get_dynamic_langfuse_logging_configdict	get_cache(_create_langfuse_logger_from_credentials)r   r   r   temp_langfuse_logger_credentialscredentials_dicts         h/home/james-whalen/.local/lib/python3.13/site-packages/litellm/integrations/langfuse/langfuse_handler.pyget_langfuse_logger_for_request/LangFuseHandler.get_langfuse_logger_for_request   s      :NDD0 
 #AA%9/M B   'JJ!5-M K 
  -  >GG(z  H  

  'HH 03Q I  ! $#    c                 b    U b  U $ 0 nUR                  USS9n U c  [        R                  UUS9n U $ )a  
Returns the Global LangfuseLogger set on litellm

(this is the default langfuse logger - used when no dynamic credentials are passed)

If no Global LangfuseLogger is set, it will check in_memory_dynamic_logger_cache for a cached LangFuseLogger
This function is used to return the globalLangfuseLogger if it exists, otherwise it will check in_memory_dynamic_logger_cache for a cached LangFuseLogger
r   r   r   )r   r   r   )r   r   r!   s      r"   r   .LangFuseHandler._return_global_langfuse_loggerJ   sh      +''  	  >GG(#  H  
  'HH 03Q I  ! $#r%   r   c                     [        U R                  S5      U R                  S5      U R                  S5      S9nUR                  U SUS9  U$ )z
This function is used to
1. create a LangFuseLogger from the credentials
2. cache the LangFuseLogger to prevent re-creating it for the same credentials
langfuse_public_keylangfuse_secretlangfuse_host)r)   r*   r+   r   )r   r   logging_obj)r	   get	set_cache)r   r   langfuse_loggers      r"   r   8LangFuseHandler._create_langfuse_logger_from_credentialsj   sZ     ) +0E F'OO,=>%///:

 	'00##' 	1 	

 r%   c                     [        U R                  S5      =(       d    U R                  S5      U R                  S5      U R                  S5      S9$ )a4  
This function is used to get the Langfuse logging config to use for a given request.

It checks if the dynamic parameters are provided in the standard_callback_dynamic_params and uses them to get the Langfuse logging config.

If no dynamic parameters are provided, it uses the `globalLangfuseLogger` values
r*   langfuse_secret_keyr)   r+   )r*   r)   r+   )r
   r-   )r   r   s     r"   r   3LangFuseHandler.get_dynamic_langfuse_logging_config   sV     %<@@ARS K/334IJ @ D D%! ;>>O
 	
r%   c                     U R                  S5      c6  U R                  S5      c$  U R                  S5      c  U R                  S5      b  gg)z
This function is used to check if the dynamic langfuse credentials are passed in standard_callback_dynamic_params

Returns:
    bool: True if the dynamic langfuse credentials are passed, False otherwise
r+   r)   r*   r2   TF)r-   )r   s    r"   r   8LangFuseHandler._dynamic_langfuse_credentials_are_passed   sQ     -00AM/334IJV/334EFR/334IJVr%    )N)__name__
__module____qualname____firstlineno__staticmethodr   r   r   r	   r#   r   r   r   r
   r   boolr   __static_attributes__r6   r%   r"   r   r      s     :>0$*G0$(;0$ '~60$ 
	0$ 0$d $&~6$(;$ 
$ $> (; 
 ,  :>
*G
&~6
 

 
* *G	 r%   r   N)__doc__typingr   r   r   r   *litellm.litellm_core_utils.litellm_loggingr   r   r	   r
   r   r   r6   r%   r"   <module>rA      s0    6 5 T ;NS Sr%   