o
    S۷i                  
   @   s   d 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	 er0ddlm
Z
mZ ddlmZmZ d	ZG d
d deeZG dd deeZejgZejejejejejejejejejd	ZG dd dZdS )z
The API in this file is only meant to be used in span streaming mode.

You can enable span streaming mode via
sentry_sdk.init(_experiments={"trace_lifecycle": "stream"}).
    N)Enum)TYPE_CHECKING)SPANDATA)format_attribute)OptionalUnion)
AttributesAttributeValue
   c                   @   s"   e Zd ZdZdZdefddZdS )
SpanStatusokerrorreturnc                 C      | j S Nvalueself r   G/home/ubuntu/vllm_env/lib/python3.10/site-packages/sentry_sdk/traces.py__str__      zSpanStatus.__str__N)__name__
__module____qualname__OKERRORstrr   r   r   r   r   r      s    r   c                   @   s2   e Zd ZdZdZdZdZdZdZde	fdd	Z
d
S )SegmentSource	componentcustomroutetaskurlviewr   c                 C   r   r   r   r   r   r   r   r   )   r   zSegmentSource.__str__N)r   r   r   	COMPONENTCUSTOMROUTETASKURLVIEWr   r   r   r   r   r   r   !   s    r   )	endpointfunction_namehandler_namemethod_and_path_patternpath
route_nameroute_patternuri_templater$   c                   @   s  e Zd ZdZdZddddedddd	fd
dZd8ddZdeddddfddZd9ddZ	deddfddZ
d:ddZd;ddZdeddfd d!Zdefd"d#Zdeddfd$d%Zd&ed'eddfd(d)Zd*eddfd+d,Zd-eddfd.d/Zd<d2d3Zedefd4d5Zedefd6d7ZdS )=StreamedSpanz
    A span holds timing information of a block of code.

    Spans can have multiple child spans thus forming a span tree.

    This is the Span First span implementation. The original transaction-based
    span implementation lives in tracing.Span.
    )_name_attributes_span_id	_trace_id_status_flagsN)
attributestrace_idnamer;   zOptional[Attributes]r<   zOptional[str]c                C   s\   || _ i | _|r| D ]
\}}| || qd | _|| _| tj | 	t
j i | _d S r   )r5   r6   itemsset_attributer7   r8   
set_statusr   r   
set_sourcer   r'   r:   )r   r=   r;   r<   	attributer   r   r   r   __init__S   s   
zStreamedSpan.__init__r   r   c                 C   r   r   )r6   r   r   r   r   get_attributesh   r   zStreamedSpan.get_attributeskeyr   r	   c                 C   s   t || j|< d S r   )r   r6   )r   rE   r   r   r   r   r?   k   s   zStreamedSpan.set_attributec                 C   s"   |  D ]
\}}| || qd S r   )r>   r?   )r   r;   rE   r   r   r   r   set_attributesn   s   zStreamedSpan.set_attributesc                 C   s$   z| j |= W d S  ty   Y d S w r   )r6   KeyError)r   rE   r   r   r   remove_attributer   s
   zStreamedSpan.remove_attributeUnion[SpanStatus, str]c                 C   s$   | j dd tD v rt| j S | j S )Nc                 S   s   h | ]}|j qS r   r   ).0sr   r   r   	<setcomp>y   s    z*StreamedSpan.get_status.<locals>.<setcomp>)r9   r   r   r   r   r   
get_statusx   s   
zStreamedSpan.get_statusstatusc                 C   s   t |tr|j}|| _d S r   )
isinstancer   r   r9   )r   rN   r   r   r   r@   ~   s   

zStreamedSpan.set_statushttp_statusc                 C   s6   |  tj| |dkr| tj d S | tj d S )Ni  )r?   r   HTTP_STATUS_CODEr@   r   r   r   )r   rP   r   r   r   set_http_status   s   zStreamedSpan.set_http_statusc                 C   r   r   r5   r   r   r   r   get_name   r   zStreamedSpan.get_namec                 C   s
   || _ d S r   rS   )r   r=   r   r   r   set_name   s   
zStreamedSpan.set_nameflagresultc                 C   s    t | jtk r|| j|< d S d S r   )lenr:   FLAGS_CAPACITY)r   rV   rW   r   r   r   set_flag   s   zStreamedSpan.set_flagopc                 C      |  d| d S )Nz	sentry.opr?   )r   r[   r   r   r   set_op      zStreamedSpan.set_oporiginc                 C   r\   )Nzsentry.originr]   )r   r`   r   r   r   
set_origin   r_   zStreamedSpan.set_originsourceUnion[str, SegmentSource]c                 C   s    t |tr|j}| d| d S )Nzsentry.span.source)rO   r   r   r?   )r   rb   r   r   r   rA      s   
zStreamedSpan.set_sourcec                 C   s    | j st jdd  | _ | j S )N   )r7   uuiduuid4hexr   r   r   r   span_id   s   zStreamedSpan.span_idc                 C   s   | j s	t j| _ | j S r   )r8   re   rf   rg   r   r   r   r   r<      s   zStreamedSpan.trace_id)r   r   )r;   r   r   N)r   rI   )rN   rI   r   N)rb   rc   r   N)r   r   r   __doc__	__slots__r   rC   rD   r?   rF   rH   rM   r@   intrR   rT   rU   boolrZ   r^   ra   rA   propertyrh   r<   r   r   r   r   r4   @   s:    	





r4   )ri   re   enumr   typingr   sentry_sdk.constsr   sentry_sdk.utilsr   r   r   sentry_sdk._typesr   r	   rY   r   r   r   r*   LOW_QUALITY_SEGMENT_SOURCESr&   r(   SOURCE_FOR_STYLEr4   r   r   r   r   <module>   s2    
