
    g                    r   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
Z
ddlmZmZmZ dd	lmZ d
dlmZ  ee
j$                        j&                  Z G d de      Z G d de      Z	  ej0                   ee
j4                        j6                        j8                  Zy# e$ r dZ ede       Y yw xY w)z<Integration with [Loguru](https://github.com/Delgan/loguru).    )annotationsN)	LogRecord)Path)Any   )ATTRIBUTES_LOGGING_ARGS_KEYATTRIBUTES_MESSAGE_KEYATTRIBUTES_MESSAGE_TEMPLATE_KEY)warn_at_user_stacklevel   )LogfireLoggingHandlerc                      e Zd ZdZy)LoguruInspectionFailedzWarning raised when magic introspection of loguru stack frames fails.

    This may happen if the loguru library changes in a way that breaks the introspection.
    N)__name__
__module____qualname____doc__     P/var/www/openai/venv/lib/python3.12/site-packages/logfire/integrations/loguru.pyr   r      s    r   r   c                  (     e Zd ZdZdZd fdZ xZS )LogfireHandlerz0A loguru handler that sends logs to **Logfire**.loguruc                   t         |   |      }|j                  |j                  di              |j                  rJ t
        r(t        j                         }|r|j                  t
        u r|j                  }d|v r|d   |t        <   nt        dt               |j                  d      }t        |t        t         f      r|r||t"        <   nt        dt               |j                  d      }t        |t$              r;t        |j                  d      x}t&              r||j(                  v r||t*        <   	 |S t        dt               	 |S |j,                  }|rt        dt               |S )	zFill attributes from a log record.

        It filters out the 'extra' attribute and adds it's content to the attributes.

        Args:
            record: The log record.

        Returns:
            The attributes for the log record.
        extramessagez>Failed to extract message template (span name) for loguru log.argsz&Failed to extract args for loguru log.
log_recordz2Failed to extract original message for loguru log.z?Failed to find loguru log frame to extract detailed information)superfill_attributesupdatepopr   _LOG_METHOD_CODEinspectcurrentframef_codef_localsr
   r   r   get
isinstancetuplelistr   dictstrmsgr	   f_back)	selfrecord
attributesframeframe_localsr   original_recordr   	__class__s	           r   r    zLogfireHandler.fill_attributes   sg    W,V4
*.."56;;((*E<<#33#(>>L L0FRS\F]
#BC/\^t (++F3D!$6FJJ'BC/0XZpq=I=M=Ml=[O"?D9&/2E2Ei2P'PwRUV#vzz1 >E
#9:   0PRh   C F (UWm r   )r1   r   returnzdict[str, Any])r   r   r   r   custom_scope_suffixr    __classcell__)r6   s   @r   r   r      s    :"8 8r   r   zEFailed to find loguru log method code to extract detailed information)r   
__future__r   r$   loggingr   pathlibr   typingr   r   _internal.constantsr   r	   r
   _internal.stack_infor   r   __file__parentLOGURU_PATHRuntimeWarningr   r   unwraptypelogger_log__code__r#   	Exceptionr   r   r   <module>rJ      s    B "      v v : *6??#**^ =* =@%w~~d6==&9&>&>?HH OQgs   ,6B# #B65B6