o
    i=4                     @   s  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	 d dlm
Z
 d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ ddlmZ ddlmZ ddlmZ ddlmZ eeZ i ddddddddddddddddddddddddddd dd!dd"dd#di d$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1dd2dd3dd4di d5dd6dd7dd8dd9dd:d;d<d;d=dd>dd?dd@ddAd;dBd;dCd;dDddEddFdi dGddHddIddJd;dKddLddMddNddOddPddQddRddSddTddUddVddWdi dXddYddZdd[dd\d;d]dd^dd_dd`ddaddbddcddddded;dfddgddhdd;ej!ddiZ"d\djiZ#e$ Z%i d dkd1dld:dmdUdnd-dod"dpdEdqdXdrdYdsdZdtd[dudBdvd)dwd#dxd$dyd^dzd*d{dhd|iZ&dhZ'G d}d~ d~e(Z)G dd de)Z*G dd de)Z+de,de,de-fddZ.dede,de
e,df fddZ/dede,de,de
e,df fddZ0dede,de,ddfddZ1	dde,de,de-de
e-e2e, f dee	gdf f
ddZ3de-ddfddZ4de-ddfddZ5dde-de
e2e, e-f ddfddZ6de$e, fddZ7dS )    )CallableN)Path)
ModuleType)Any)Union)when_imported)config)TELEMETRY_NAMESPACE)	deprecate)SpecifierSet)Version   )	telemetry)
get_logger)formats)DDTraceDeprecationWarningaiokafkaTaiomysqlaredisasyncioavrobotobotocorebottleceleryconsulddtrace_apidjangodramatiqelasticsearchalgoliasearchfutures
google_adkgoogle_genaigeventgraphqlgrpchttpxkafka	langgraphlitellmmysqlmysqldbpymysqlmariadbmcppsycopgpylibmc
pymemcachepymongoredisredisclusterrequestsrqsanic	snowflakeF
sqlalchemysqlite3aiohttpaiohttp_jinja2aiopgaiobotocorehttpliburllib3vertexaiverticamoltenjinja2makoflaskkombu	starlettefalconpyramidlogbookloggingloguru	structlogpynamodbpyodbcfastapidogpile_cacheyaaredisasyncpg
aws_lambdaazure_eventhubsazure_functionsazure_servicebustornadoopenai	langchain	anthropiccrewaipydantic_aivllm
subprocessunittestcoverageseleniumvalkeyopenai_agents)rayprotobufclaude_agent_sdk)r!   )r   elasticsearch1elasticsearch2elasticsearch5elasticsearch6elasticsearch7elastic_transportopensearchpy)r0   psycopg2)zsnowflake.connector)zdogpile.cache)MySQLdb)zconcurrent.futures.thread)vertica_python)datadog_lambda)zazure.eventhub)zazure.functions)zazure.servicebus)zhttp.client)confluent_kafka)z
google.adk)zgoogle.genai)langchain_core)r)   zlanggraph.graphzlanggraph.prebuilt)agentsc                   @   s   e Zd ZdZdS )PatchExceptionz5Wraps regular `Exception` class when patching modulesN)__name__
__module____qualname____doc__ r}   r}   C/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/_monkey.pyrx      s    rx   c                   @   s   e Zd ZdS )ModuleNotFoundExceptionN)ry   rz   r{   r}   r}   r}   r~   r      s    r   c                       s0   e Zd Zddedeedf f fddZ  ZS )IncompatibleModuleExceptionNmessageinstalled_versionc                    s   t  | || _d S N)super__init__r   )selfr   r   	__class__r}   r~   r      s   
z$IncompatibleModuleException.__init__r   )ry   rz   r{   strr   r   __classcell__r}   r}   r   r~   r      s    (r   versionsupported_versions_specreturnc                 C   s@   |sdS |dkr
dS zt |}t| |v W S  ty   Y dS w )zeReturns whether a given package version is compatible with the integration's supported version range.F*T)r   r   	Exception)r   r   specifier_setr}   r}   r~   is_version_compatible   s   r   imported_modulehooked_module_namec                 C   s.   t | dr|  |S t | dr|  S dS )z*Returns the installed version of a module.get_versionsget_versionN)hasattrr   getr   )r   r   r}   r}   r~   _get_installed_module_version   s
   

r   integration_patch_moduleintegration_namec                 C   s:   t | dsdS |  }||v r|| S ||v r|| S dS )z7Returns the supported version range for an integration._supported_versionsN)r   r   )r   r   r   supported_versionsr}   r}   r~   #_get_integration_supported_versions   s   
r   c                 C   sX   t | |}|s	dS t| ||}|sdS t||s*d| d| d| d}t||ddS )zrDetermines if a module should be patched based on installed version and the integration's supported version range.NzSkipped patching 'z"' integration, installed version: z2 is not compatible with integration support spec: .)r   )r   r   r   r   )r   r   r   r   supported_version_specr   r}   r}   r~   check_module_compatibility   s   

r   modulepath_fraise_errorspatch_indicatorc                    s    fdd}|S )z=Factory to create an import hook for the provided module namec                    s  z"t  f }tjrt| | j |  t|dr!| W nr t	yQ } z#t
d t| tjj dt du t||jd W Y d }~d S d }~w ty } z8r[ t
jd t|dd tj dt du t| tjtjddd	 fd
t|jff W Y d }~d S d }~ww t|dr| }| D ]\}}tjj|dt du d|d qd S t|dr| }tjj dt du d|d d S d S )Npatch_submodulesz+failed to enable ddtrace support for %s: %sFT)r   )exc_infointegration_errorsr   r   
error_typer    r   )	importlibimport_moduler   #_trace_safe_instrumentation_enabledr   ry   patchr   r   r   logerrorr   r   telemetry_writeradd_integrationPATCH_MODULESr   r   r   add_count_metricr	   TRACERStyper   itemsr   )hookr   eversionsnamevr   r   r   r   r   r}   r~   	on_import  sb   

 


z%_on_import_factory.<locals>.on_importr}   )r   r   r   r   r   r}   r   r~   _on_import_factory  s   5r   patch_modulesc                  K   s    t ddtd tdi |  dS )a  Enables ddtrace library instrumentation.

    In addition to ``patch_modules``, an override can be specified via an
    environment variable, ``DD_TRACE_<module>_ENABLED`` for each module.

    ``patch_modules`` have the highest precedence for overriding.

    :param dict patch_modules: Override whether particular modules are patched or not.

        >>> _patch_all(redis=False)
    zNpatch_all is deprecated and will be removed in a future version of the tracer.z|patch_all is deprecated in favor of ``import ddtrace.auto`` and ``DD_PATCH_MODULES``
        environment variable if needed.)r   categoryNr}   )r
   r   
_patch_all)r   r}   r}   r~   	patch_all?  s   r   c                  K   s   t  }| D ].\}}d|  }|tvr%|tjv r%ttj| ||< || r6t	
|dD ]}d||< q/q||  tdddi| d S )NzDD_TRACE_%s_ENABLEDr}   Tr   F)r   copyr   upper_NOT_PATCHABLE_VIA_ENVVARosenvironr   asboolCONTRIB_DEPENDENCIESr   updater   )r   modulesr   _enabledenv_vardepr}   r}   r~   r   T  s   

r   c              	   K   s   dd |  D }|  D ]9\}}ttjd d | d  s)| r)t| dt||f}|D ]}t|t	|d| |d q2t
| qtd	t|d
| dS )zPatch only a set of given modules.

    :param bool raise_errors: Raise error if one patch fail.
    :param dict patch_modules: List of modules to patch.

        >>> patch(psycopg=True, elasticsearch=True)
    c                 S   s   i | ]	\}}|r||qS r}   r}   ).0cr   r}   r}   r~   
<dictcomp>p  s    zpatch.<locals>.<dictcomp>contribinternalzpatch.pyz( does not have automatic instrumentationz!ddtrace.contrib.internal.%s.patch)r   r   zeConfigured ddtrace instrumentation for %s integration(s). The following modules have been patched: %s,N)r   r   __file__parentexistsr   _MODULES_FOR_CONTRIBr   r   r   _PATCHED_MODULESaddr   infolenjoin)r   r   contribsr   r   modules_to_patchr   r}   r}   r~   r   h  s*   
r   c                   C   s   t S )zGet the list of patched modules)r   r}   r}   r}   r~   _get_patched_modules  s   r   )TT)T)8collections.abcr   r   r   pathlibr   typesr   typingr   r   wrapt.importerr   !ddtrace.internal.settings._configr   $ddtrace.internal.telemetry.constantsr	   ddtrace.vendor.debtcollectorr
   #ddtrace.vendor.packaging.specifiersr    ddtrace.vendor.packaging.versionr   r   r   internal.loggerr   internal.utilsr   internal.utils.deprecationsr   ry   r   _data_streams_enabledr   r   setr   r   r   r   rx   r   r   r   boolr   r   r   r   listr   r   r   r   r   r}   r}   r}   r~   <module>   s"   	
 !"#$%&'()*+,-./012345678:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWa$'




=$$