o
    i                     @  s$  U d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZ d dlmZ d dlmZ e	rfd dlmZ d d	lmZ d d
lmZmZ d dlmZ d dlmZ edee
 ee
 eZeeB ZdZ de!d< d/ddZ"	d0d1ddZ#d2d%d&Z$ed3d)d*Z%ed4d-d*Z%d5d.d*Z%dS )6    )annotationsN)	find_spec)
ModuleType)TYPE_CHECKINGAnyLiteralcastoverload)Requirement)Logfire)PsycopgInstrumentor)Psycopg2Instrumentor)AsyncConnection
Connection)
connection)TypeVarPsycopgConnectionpsycopgpsycopg2z.tuple[Literal['psycopg'], Literal['psycopg2']]PACKAGE_NAMESlogfire_instancer   conn_or_module[ModuleType | Literal['psycopg', 'psycopg2'] | None | PsycopgConnection | Psycopg2Connectionkwargsr   returnNonec                 K  s   |du rt D ]}t|rt| |fi | qdS |t v r/t|ts#J t| fd|i| dS t|trGttd |j	}t| |fi | dS |j
jD ]%}|jdd }|t v rp|rctd| dt| ||fi |  dS qKtd|)	zInstrument a `psycopg` connection or module so that spans are automatically created for each query.

    See the `Logfire.instrument_psycopg` method for details.
    Nnamer   .r   zBExtra keyword arguments are only supported when instrumenting the z module, not a connection.zDon't know how to instrument )r   r   instrument_psycopg
isinstancestr_instrument_psycopgr   r   r   __name__	__class____mro__
__module__split	TypeError
ValueError)r   r   r   packagemodule_namecls r-   l/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/logfire/_internal/integrations/psycopg.pyr      s2   	

r   r   Literal['psycopg', 'psycopg2']connc                 K  s   t |}|d u r>t|}t||j|}|dr'|dkr'dd l}|j |_	|j
dd|i| j | j d| d S |j|| j d d S )Nenable_commenterr   r   skip_dep_check)tracer_providermeter_provider)r3   r-   )_get_instrumentor	importlibimport_modulecheck_version__version__get
psycopg.pqpqversion__libpq_version__
instrumentconfigget_tracer_providerget_meter_providerinstrument_connection)r   r   r0   r   instrumentormodr2   r   r-   r-   r.   r"   C   s"   


r"   r!   r=   rD   Instrumentorboolc                 C  sv   t t, | D ]}t|}|j| kr(|j| d r( W d    dS q
W d    dS 1 s4w   Y  dS )Nr   TF)	
contextlibsuppress	Exceptioninstrumentation_dependenciesr
   r   	specifiercontainsr'   )r   r=   rD   depreqr-   r-   r.   r8   f   s   
r8   Literal['psycopg']r   c                 C     d S Nr-   r   r-   r-   r.   r5   p      r5   Literal['psycopg2']r   c                 C  rQ   rR   r-   rS   r-   r-   r.   r5   t   rT   c              	   C  sP   z
t d|  }W n ty   td|  d|  dw t||   d S )Nzopentelemetry.instrumentation.zRun `pip install 'logfire[z]'` to install z instrumentation.rF   )r6   r7   ImportErrorgetattr
capitalize)r   instrumentor_moduler-   r-   r.   r5   x   s   )r   r   r   r   r   r   r   r   rR   )
r   r   r   r/   r0   r   r   r   r   r   )r   r!   r=   r!   rD   rF   r   rG   )r   rP   r   r   )r   rU   r   r   )r   r!   r   rF   )&
__future__r   rH   r6   importlib.utilr   typesr   typingr   r   r   r   r	   packaging.requirementsr
   logfirer   %opentelemetry.instrumentation.psycopgr   &opentelemetry.instrumentation.psycopg2r   r   r   r   psycopg2._psycopgr   Psycopg2Connectiontyping_extensionsr   r   rF   r   __annotations__r   r"   r8   r5   r-   r-   r-   r.   <module>   s4    
*
#
