o
    iO	                     @   s   d dl mZ d dlZd dlZd dl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 d dlmZ daed	d
dd Zddedeeeef dB fddZddddZdddefddZdS )    )	lru_cacheN)config)tracer)Span)	SpanEvent)HandledExceptionCollector)NNNi    )maxsizec                 C   s8   t \}}}t }ttj}tj|||||d | S )zMost of the overhead of automatic reporting is added by traceback formatting
    Cache was added to try to be faster is the same error is reported several times
    )filelimit)	_error_tuple_infoioStringIOintr   _span_traceback_max_size	tracebackprint_exceptiongetvalue)tb_hashexc_typeexc_valexc_tbbuffr
    r   g/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/errortracking/_handled_exceptions/callbacks.py_get_formatted_traceback   s
   

r   spanreturnc                 C   s   |st  \}}}|sdS t|||jfattd }ddd |D }t	|
  }t|}|| tdt|d|jj|jjf |dfS )	z!Generate the exception span eventN    c                 s   s*    | ]}|j  d |j d |j V  qdS ):N)filenamelinenoname).0framer   r   r   	<genexpr>-   s   ( z'_generate_span_event.<locals>.<genexpr>	exceptionz%s.%s)zexception.messagezexception.typezexception.stacktrace)sysexc_infotype__traceback__r   r   
extract_tbjoinhashlibsha256encode	hexdigestr   r   str	__class__
__module____name__)r   exc_tb_listtb_strr   tbr   r   r   _generate_span_event   s&   r:   )r5   c                 G   s    t  }|rt|| d d S d S )N)r   r5   )r   current_span#_default_errortracking_exc_callback)r5   argsr   r   r   r   _default_bytecode_exc_callback?   s   r>   c                 G   s2   t | |}|d ur|\}} }t| || d S d S N)r:   r   capture_exception_event)r   r5   r=   	generated
span_eventr   r   r   r<   E   s
   

r<   r?   )	functoolsr   cachedr-   r   r'   r   ddtracer   r   ddtrace._trace.spanr   r   3ddtrace.errortracking._handled_exceptions.collectorr   r   r   tuple	Exceptionr:   r>   r<   r   r   r   r   <module>   s     
"!