
    g                        d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZmZ  ee      Z G d d	e      Zd	gZy
)z!
OpenTelemetry Base Instrumentor
    )annotations)ABCabstractmethod)	getLogger)Any
Collection))_OpenTelemetrySemanticConventionStability)DependencyConflictget_dependency_conflictsc                  r    e Zd ZdZdZdZd Zed        Ze	dd       Z
ddZe	dd       Zdd	Zdd
ZddZy)BaseInstrumentora  An ABC for instrumentors.

    Child classes of this ABC should instrument specific third
    party libraries or frameworks either by using the
    ``opentelemetry-instrument`` command or by calling their methods
    directly.

    Since every third party library or framework is different and has different
    instrumentation needs, more methods can be added to the child classes as
    needed to provide practical instrumentation to the end user.
    NFc                f    | j                   t        j                  |       | _         | j                   S N)	_instanceobject__new__)clsargskwargss      _/var/www/openai/venv/lib/python3.12/site-packages/opentelemetry/instrumentation/instrumentor.pyr   zBaseInstrumentor.__new__5   s&    == "NN3/CM}}    c                    | j                   S r   )!_is_instrumented_by_opentelemetryselfs    r    is_instrumented_by_opentelemetryz1BaseInstrumentor.is_instrumented_by_opentelemetry;   s    555r   c                     y)a  Return a list of python packages with versions that the will be instrumented.

        The format should be the same as used in requirements.txt or pyproject.toml.

        For example, if an instrumentation instruments requests 1.x, this method should look
        like:

            def instrumentation_dependencies(self) -> Collection[str]:
                return ['requests ~= 1.0']

        This will ensure that the instrumentation will only be used when the specified library
        is present in the environment.
        N r   s    r   instrumentation_dependenciesz-BaseInstrumentor.instrumentation_dependencies?       r   c                     y)zInstrument the libraryNr   r   r   s     r   _instrumentzBaseInstrumentor._instrumentO   r    r   c                     y)zUninstrument the libraryNr   r"   s     r   _uninstrumentzBaseInstrumentor._uninstrumentR   r    r   c                8    | j                         }t        |      S r   )r   r   )r   dependenciess     r   _check_dependency_conflictsz,BaseInstrumentor._check_dependency_conflictsV   s    88:'55r   c                   | j                   rt        j                  d       y|j                  dd      }|s(| j	                         }|rt        j                  |       yt        j                           | j                  di |}d| _         |S )aS  Instrument the library

        This method will be called without any optional arguments by the
        ``opentelemetry-instrument`` command.

        This means that calling this method directly without passing any
        optional values should do the very same thing that the
        ``opentelemetry-instrument`` command does.
        z3Attempting to instrument while already instrumentedNskip_dep_checkFTr   )	r   _LOGwarningpopr(   errorr	   _initializer#   )r   r   r*   conflictresults        r   
instrumentzBaseInstrumentor.instrumentZ   s     11LLNO  $4e<779H

8$ 	2==?!!! 

 26.r   c                |    | j                   r | j                  di |}d| _         |S t        j                  d       y)zUninstrument the library

        See ``BaseInstrumentor.instrument`` for more information regarding the
        usage of ``kwargs``.
        Fz7Attempting to uninstrument while already uninstrumentedNr   )r   r%   r+   r,   )r   r   r1   s      r   uninstrumentzBaseInstrumentor.uninstrumentz   s?     11'T''1&1F5:D2MNOr   )returnzCollection[str])r   r   )r5   zDependencyConflict | None)__name__
__module____qualname____doc__r   r   r   propertyr   r   r   r#   r%   r(   r2   r4   r   r   r   r   r   %   sj    
 I(-% 6 6  % ' '6@r   r   N)r9   
__future__r   abcr   r   loggingr   typingr   r   &opentelemetry.instrumentation._semconvr	   *opentelemetry.instrumentation.dependenciesr
   r   r6   r+   r   __all__r   r   r   <module>rB      sG     # #  "
 cs cL 
r   