o
    Á¿i¾  ã                   @   sP   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dd„ ƒZ
dd	„ ZdS )
é    N)Úwrap_function_wrapper)Ú	iswrapped)Úwith_traced_module)Útracerc                 C   s&   t  ¡ }|dur| ¡  ||i |¤ŽS )zˆSets the error message, error type and exception stack trace to the current span
    before calling the original exception handler.
    N)r   Úcurrent_spanÚset_traceback)ÚdjangoÚpinÚwrappedÚinstanceÚargsÚkwargsÚspan© r   úa/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/contrib/internal/django/restframework.pyÚ_traced_handle_exception	   s   r   c                 C   s&   t tjjdƒstddt| ƒƒ dS dS )a]  Patches rest_framework app.

    To trace exceptions occurring during view processing we currently use a TraceExceptionMiddleware.
    However the rest_framework handles exceptions before they come to our middleware.
    So we need to manually patch the rest_framework exception handler
    to set the exception stack trace in the current span.
    Úhandle_exceptionzrest_framework.viewszAPIView.handle_exceptionN)r   Úrest_frameworkÚviewsÚAPIViewÚwrapr   )r   r   r   r   Úpatch_restframework   s   
ÿr   )Úrest_framework.viewsr   Úwraptr   r   Ú$ddtrace.contrib.internal.trace_utilsr   r   Úddtrace.tracer   r   r   r   r   r   r   Ú<module>   s    
