
    Ng>                     $    d Z  G d d          ZdS )z:Middleware for making it easier to do distributed tracing.c                   $    e Zd ZdZd ZdefdZdS )TracingMiddlewareaZ  Middleware for propagating distributed tracing context using LangSmith.

    This middleware checks for the 'langsmith-trace' header and propagates the
    tracing context if present. It does not start new traces by default.
    It is designed to work with ASGI applications.

    Attributes:
        app: The ASGI application being wrapped.
    c                 .    ddl m} || _        || _        dS )zInitialize the middleware.    )tracing_contextN)langsmith.run_helpersr   _with_headersapp)selfr	   r   s      P/var/www/html/ai-engine/env/lib/python3.11/site-packages/langsmith/middleware.py__init__zTracingMiddleware.__init__   s'    999999,    scopec                 0  K   |d         dk    rjd|v rft          |d                   }d|v rM|                     |          5  |                     |||           d{V  ddd           n# 1 swxY w Y   dS |                     |||           d{V  dS )a  Handle incoming requests and propagate tracing context if applicable.

        Args:
            scope: A dict containing ASGI connection scope.
            receive: An awaitable callable for receiving ASGI events.
            send: An awaitable callable for sending ASGI events.

        If the request is HTTP and contains the 'langsmith-trace' header,
        it propagates the tracing context before calling the wrapped application.
        Otherwise, it calls the application directly without modifying the context.
        typehttpheaderss   langsmith-trace)parentN)dictr   r	   )r
   r   receivesendr   s        r   __call__zTracingMiddleware.__call__   s      =F""yE'9'95+,,G!W,,''w'77 9 9((5'48888888889 9 9 9 9 9 9 9 9 9 9 9 9 9 9hhugt,,,,,,,,,,,s   A,,A03A0N)__name__
__module____qualname____doc__r   r   r    r   r   r   r      sH           -D - - - - - -r   r   N)r   r   r   r   r   <module>r      s=    @ @$- $- $- $- $- $- $- $- $- $-r   