o
    i~                     @   s  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 dZedZdZedZedZ edZ!edZ"zd dl#Z#d dl$m%Z% ee%Z&e'de(edd W n e)y   e Z&Z%Y nw de*fddZ+de(e*e*f fddZ,dd Z-d d! Z.d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0Z/d1d2 Z0dS )3    )wrap_function_wrapper)config)Pin)_SPAN_MEASURED_KEY)	SPAN_KIND)trace_utils)SpanKind)	SpanTypes)	COMPONENT)schematize_cloud_api_operation)schematize_service_name)unwrap)tracer)parse_datadog_patchalgoliasearchz0.0z1.0z2.0z3.0NVERSIONF)_default_servicecollect_query_textreturnc                   C   s   t S )Nr    r   r   `/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/contrib/internal/algoliasearch/patch.pyget_version'   s   r   c                   C   s   ddiS )Nr   z>=2.6.3r   r   r   r   r   _supported_versions+   s   r   c                  C   s   t tkrd S tttdrd S dt_t } t tk r,t tkr,t	tj
dt | tj
j d S t tkrHt tk rHddlm} t	tdt | |j d S d S )NFTzIndex.searchr   search_indexzsearch_index.SearchIndex.search)algoliasearch_versionV0getattrr   DD_PATCH_ATTRr   r   V2V1_windex_patched_searchontoIndexV3r   SearchIndex)pinr   r   r   r   patch/   s   r+   c                  C   sz   t tkrd S tttdr;tttd t tk r#t tkr#ttj	j
d d S t tkr9t tk r9ddlm}  t| jd d S d S d S )NFsearchr   r   )r   r   r   r   r    setattrr!   r"   _ur$   r'   r(   r   r)   r   r   r   r   unpatchF   s   r/   pagehits_per_pageattributes_to_retrieveattributes_to_highlightattributes_to_snippetmin_word_size_for_1_typomin_word_size_for_2_typosget_ranking_infoaround_lat_lngnumeric_filterstag_filters
query_typeoptional_wordsdistinct)r0   hitsPerPageattributesToRetrieveattributesToHighlightattributesToSnippetminWordSizefor1TypominWordSizefor2TyposgetRankingInfoaroundLatLngnumericFilters
tagFilters	queryTypeoptionalWordsr=   c              	   C   s  t tk rt tkrd}nt tkrt tk rd}n| |i |S t|}|r(| s/| |i |S tjt	ddddt
|tjtjd}|ttjj |ttj |td |jjd	urr|jjd
krr| |i |W  d	   S tjjr|d|d|d
  ||t|dkr|d nd	}|rt|trt  D ]\}}	||}
|
d	ur|!d"|	|
 q| |i |}t|tr|dd	d	ur|dt#|d  |dd	d	ur|dt#|d  |W  d	   S 1 sw   Y  d	S )z
    wrapt_args is called the way it is to distinguish it from the 'args'
    argument to the algoliasearch.index.Index.search() method.
    argsrequest_optionszalgoliasearch.searchr   r,   )cloud_providercloud_service)service	span_type   Nr   z
query.textqueryzquery.args.{}processingTimeMSprocessing_time_msnbHitsnumber_of_hits)$r   r!   r"   r(   r   get_fromenabledr   tracer   r   ext_servicer   r   r	   HTTP_set_tag_strr
   integration_namer   r   CLIENT
set_metricr   contextsampling_priorityr   getlen
isinstancedictQUERY_ARGS_DD_TAG_MAPitemsset_tagformatint)funcinstance
wrapt_argswrapt_kwargsfunction_query_arg_namer*   span
query_args	query_argtag_namevalueresultr   r   r   r%   l   sJ   
 

$r%   )1wraptr   r#   ddtracer   ddtrace._trace.pinr   ddtrace.constantsr   r   ddtrace.contribr   ddtrace.extr   r	   ddtrace.internal.constantsr
   ddtrace.internal.schemar   r   ddtrace.internal.utils.wrappersr   r.   ddtrace.tracer    ddtrace.vendor.packaging.versionr   parse_versionr    SERVICE_NAMEAPP_NAMEr   r"   r!   r(   r   algoliasearch.versionr   r   _addrd   ImportErrorstrr   r   r+   r/   re   r%   r   r   r   r   <module>   sb    