o
    i
                     @  s   d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	Z	d dl
mZmZ d dlmZ e ZdZeejv s8J e	jd	d
Zd!ddZd"ddZ		d#d$dd ZdS )%    )annotations)Any)Spanset_span_in_context)TraceContextTextMapPropagatorN)ATTRIBUTES_MESSAGE_KEYATTRIBUTES_SPAN_TYPE_KEY)attach_contexttraceparentfeedback)custom_scope_suffixspanSpan | logfire.LogfireSpanreturnstrc                 C  sB   t | tr| }n| j}|sJ t|}i }t|| |tdS )zGGet a string representing the span context to use for annotating spans. )
isinstancer   _spanr   TRACEPARENT_PROPAGATORinjectgetTRACEPARENT_NAME)r   	real_spancontextcarrier r   f/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/logfire/experimental/annotations.pyget_traceparent   s   
r   	span_namemessage
attributesdict[str, Any]Nonec                 C  sT   t t| itd tj|fi |t|tdi W d   dS 1 s#w   Y  dS )zUCreate a span of kind 'annotation' as a child of the span with the given traceparent.)
propagator
annotationN)r	   r   r   feedback_logfireinfor   r   )r
   r   r   r    r   r   r   raw_annotate_span!   s   "r'   namevalueint | float | bool | strcomment
str | Noneextradict[str, Any] | Nonec                 C  sV   d|||i}|r||vsJ | | |r||d< t| d| d| d|| dS )a  Attach feedback to a span.

    This is a more structured version of `raw_annotate_span`
    with special attributes recognized by the Logfire UI.

    Args:
        traceparent: The traceparent string.
        name: The name of the evaluation.
        value: The value of the evaluation.
            Numbers are interpreted as scores, strings as labels, and booleans as assertions.
        comment: An optional reason for the evaluation.
        extra: Optional additional attributes to include in the span.
    zlogfire.feedback.namezlogfire.feedback.commentz
feedback: z = N)updater'   )r
   r(   r)   r+   r-   r    r   r   r   record_feedback.   s   
r0   )r   r   r   r   )
r
   r   r   r   r   r   r    r!   r   r"   )NN)r
   r   r(   r   r)   r*   r+   r,   r-   r.   r   r"   )
__future__r   typingr   opentelemetry.tracer   r   ,opentelemetry.trace.propagation.tracecontextr   logfirelogfire._internal.constantsr   r   logfire.propagater	   r   r   fieldswith_settingsr%   r   r'   r0   r   r   r   r   <module>   s     

