
    uYf%                        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 g dZerd dlmZ  ee      Z G d de      Z G d de j,                  e      Z G d de      Ze	e	e
dZy)    N)TYPE_CHECKING)Any)Dict)List)Optional   )ListStringTable)MsgpackEncoderV03)MsgpackEncoderV05ensure_text)
get_logger)r
   r   r	   MSGPACK_ENCODERS)Spanc                   ,    e Zd ZdZd Zd Zed        Zy)_EncoderBasezQ
    Encoder interface that provides the logic to encode traces and service.
    c                     t               )aT  
        Encodes a list of traces, expecting a list of items where each items
        is a list of spans. Before dumping the string in a serialized format all
        traces are normalized according to the encoding format. The trace
        nesting is not changed.

        :param traces: A list of traces that should be serialized
        NotImplementedError)selftracess     Y/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/ddtrace/internal/encoding.pyencode_tracesz_EncoderBase.encode_traces   s     "##    c                     t               )z
        Defines the underlying format used during traces or services encoding.
        This method must be implemented and should only be used by the internal
        functions.
        r   )r   objs     r   encodez_EncoderBase.encode*   s     "##r   c                    | j                   | j                  | j                  | j                  | j                  | j
                  | j                  d}|j                  d      }|rt        |      t        k(  rd|d<   | j                  r| j                  |d<   | j                  r| j                  |d<   | j                  r| j                  |d<   | j                  r| j                  |d<   | j                  r| j                  |d<   |S )	N)trace_id	parent_idspan_idserviceresourcenameerrorr%   r   startdurationmetametricstype)_trace_id_64bitsr    r!   r"   r#   r$   r%   getr*   boolstart_nsduration_ns_meta_metrics	span_type)spanderrs      r   _span_to_dictz_EncoderBase._span_to_dict3   s     --||||IIZZ
 eeGn49$AgJ==AgJ ,,AjM::

AfI====AiL>>AfIr   N)__name__
__module____qualname____doc__r   r   staticmethodr6    r   r   r   r      s%    
$$ " "r   r   c                   6    e Zd ZdZd Zed        Zed        Zy)JSONEncoderapplication/jsonc                     |D cg c]8  }|D cg c]*  }t         j                  t         j                  |            , c}: }}}| j                  |      S c c}w c c}}w )N)r>   _normalize_spanr6   r   r   r   tracer3   normalized_tracess        r   r   zJSONEncoder.encode_traces\   s\    jp
afV[\d[(()B)B4)HI\
 
 {{,-- ]
s   	A/AAAc                     t         j                  | d         | d<   t         j                  | d         | d<   t         j                  | d         | d<   | S )Nr#   r$   r"   )r>   _normalize_str)r3   s    r   rA   zJSONEncoder._normalize_spanb   sS    
 '55d:6FGZ"11$v,?V%44T)_EYr   c                 $    | | S t        | d      S )Nbackslashreplace)errorsr   )r   s    r   rF   zJSONEncoder._normalize_strl   s    ;J3'9::r   N)r7   r8   r9   content_typer   r;   rA   rF   r<   r   r   r>   r>   Y   s4    %L.   ; ;r   r>   c                   :    e Zd ZdZdZd Zed        Zed        Zy)JSONEncoderV2zD
    JSONEncoderV2 encodes traces to the new intake API format.
    r?   c           
          |D cg c]%  }|D cg c]  }t         j                  |       c}' }}}| j                  d|i      S c c}w c c}}w )Nr   )rL   _convert_spanr   rB   s        r   r   zJSONEncoderV2.encode_traces{   sK    `fgW\ERDm99$?Rgg{{H&7899 Sgs   	AAAAc                 D   t         j                  |       }t         j                  |      }t         j                  |j	                  d            |d<   t         j                  |j	                  d            |d<   t         j                  |j	                  d            |d<   |S )Nr   r    r!   )rL   r6   rA   _encode_id_to_hexr,   )r3   sps     r   rN   zJSONEncoderV2._convert_span   s     ((.**2.&88
9KL:'99"&&:MN;%77y8IJ9	r   c                 $    | sydt        |       z  S )N0000000000000000z%0.16X)int)dd_ids    r   rP   zJSONEncoderV2._encode_id_to_hex   s     %#e*$$r   N)	r7   r8   r9   r:   rJ   r   r;   rN   rP   r<   r   r   rL   rL   t   s;     &L:
   % %r   rL   )zv0.3zv0.4zv0.5)jsontypingr   r   r   r   r   	_encodingr	   r
   r   compatr   loggerr   __all__ddtrace._trace.spanr   r7   logobjectr   r>   rL   r   r<   r   r   <module>r_      s           & ( (   \ ( =6 =@;$""L ;6%K %>  r   