Ë
    KµCj5  ã                   ór   — d 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
mZ  e
d«      Z G d„ d	e«      Zy)
a’  
Request ID middleware.

Generates a unique ID per incoming request and:
1. Sets it in the request_id context var so every log line emitted
   while handling this request is automatically tagged with it.
2. Echoes it back in the X-Request-ID response header, so if the client
   reports "my request failed", they can give you the exact ID to grep
   in logs instead of "it failed around 3pm sometime."
é    N)ÚRequest)ÚBaseHTTPMiddleware)ÚResponse)Ú
get_loggerÚrequest_id_ctxzapp.requestc                   ó   — e Zd Zdedefd„Zy)ÚRequestContextMiddlewareÚrequestÚreturnc           
   ƒ   óN  K  — |j                   j                  d«      xs t        t        j                  «       «      }t        j                  |«      }t        j                  «       }	  ||«      ƒ d {  –—† }t        j                  |«       t        t        j                  «       |z
  dz  «      }||j                   d<   t        j                  |j                  › d|j                  j                  › d|j                   › d|› d�«       |S 7 Œ–# t        j                  |«       w xY w­w)NzX-Request-IDiè  ú z -> z (zms))ÚheadersÚgetÚstrÚuuidÚuuid4r   ÚsetÚtimeÚperf_counterÚresetÚintÚloggerÚinfoÚmethodÚurlÚpathÚstatus_code)Úselfr
   Ú	call_nextÚ
request_idÚtokenÚstartÚresponseÚ
elapsed_mss           úKC:\Crop_Prediction\Backend\crop-ai-system\app\middleware\request_context.pyÚdispatchz!RequestContextMiddleware.dispatch   sð   è ø€ Ø—_‘_×(Ñ(¨Ó8ÒM¼CÄÇ
Á
ÃÓ<Mˆ
Ü×"Ñ" :Ó.ˆÜ×!Ñ!Ó#ˆð	(Ù& wÓ/×/ˆHä× Ñ  Ô'äœ$×+Ñ+Ó-°Ñ5¸Ñ=Ó>ˆ
Ø+5ˆ×Ñ˜Ñ(Ü�‰Ø�~‰~Ð˜a §¡× 0Ñ 0Ð1°°h×6JÑ6JÐ5KÈ2ÈjÈ\ÐY\Ð]ô	
ð ˆð 0ùä× Ñ  Õ'üs1   ‚A$D%Á'D Á2D	Á3D Á7BD%Ä	D ÄD"Ä"D%N)Ú__name__Ú
__module__Ú__qualname__r   r   r&   © ó    r%   r	   r	      s   „ ð gð ¸Xô r+   r	   )Ú__doc__r   r   Úfastapir   Ústarlette.middleware.baser   Ústarlette.responsesr   Úapp.core.logging_configr   r   r   r	   r*   r+   r%   ú<module>r1      s5   ðñ	ó Û å Ý 8Ý (ç >á	�MÓ	"€ôÐ1õ r+   