3
Z_ð]ç  ã               @   sz   d dl Z d dlZd dlmZ d dlmZ dZdZdZdZ	ej
r^ejjZejjZdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ ZdS )é    N)Úhttplib)ÚapizX-B3-TraceIdzX-B3-SpanIdzX-B3-ParentSpanIdzX-B3-Sampledc             C   st   t jƒ rht jƒ }t jƒ }| jtt|jƒƒ | jtt|ƒƒ | jt	t|j
ƒƒ | jtt|jƒƒ t jdƒ t| ƒ d S )NzClient Send)r   Ú
is_tracingZget_trace_dataZgenerate_span_idÚ	putheaderÚHDR_TRACE_IDÚhex_strZtrace_idÚHDR_SPAN_IDÚHDR_PARENT_SPAN_IDZspan_idÚHDR_SAMPLEDÚintZsampledÚput_annotationÚ__org_endheaders__)ÚselfZ
trace_dataZnew_span_id© r   ú8/tmp/pip-build-yz_zf6az/eventlet/eventlet/zipkin/http.pyÚ_patched_endheaders   s    
r   c             C   s$   t | ƒ tjƒ r tjd| j ƒ d S )NzClient Recv (%s))Ú__org_begin__r   r   r   Ústatus)r   r   r   r   Ú_patched_begin   s    r   c               C   s*   t jrttj_ttj_t j	r&t
jdƒ d S )NzŽSince current Python thrift release         doesn't support Python 3, eventlet.zipkin.http         doesn't also support Python 3 (http.client))ÚsixÚPY2r   r   ÚHTTPConnectionÚ
endheadersr   ÚHTTPResponseÚbeginÚPY3ÚwarningsÚwarnr   r   r   r   Úpatch&   s    r   c               C   s    t jrttj_ttj_t j	rd S )N)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   Úunpatch0   s
    r   c             C   s
   d| f S )z�
    Thrift uses a binary representation of trace and span ids
    HTTP headers use a hexadecimal representation of the same
    z%0.16xr   )Únr   r   r   r   8   s    r   )r   r   Zeventlet.greenr   Zeventlet.zipkinr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   
