o
    õæh!  ã                   @   s\   d dl Z d dlmZmZ erddlmZ ddlmZ G dd„ de jƒZ	G dd	„ d	e jƒZ
dS )
é    N)ÚTYPE_CHECKINGÚAnyé   )ÚSpan)ÚTracec                   @   sp   e Zd ZdZejddd„ƒZejddd	„ƒZejddd„ƒZejddd„ƒZ	ejddd„ƒZ
ejddd„ƒZdS )ÚTracingProcessora«  Interface for processing and monitoring traces and spans in the OpenAI Agents system.

    This abstract class defines the interface that all tracing processors must implement.
    Processors receive notifications when traces and spans start and end, allowing them
    to collect, process, and export tracing data.

    Example:
        ```python
        class CustomProcessor(TracingProcessor):
            def __init__(self):
                self.active_traces = {}
                self.active_spans = {}

            def on_trace_start(self, trace):
                self.active_traces[trace.trace_id] = trace

            def on_trace_end(self, trace):
                # Process completed trace
                del self.active_traces[trace.trace_id]

            def on_span_start(self, span):
                self.active_spans[span.span_id] = span

            def on_span_end(self, span):
                # Process completed span
                del self.active_spans[span.span_id]

            def shutdown(self):
                # Clean up resources
                self.active_traces.clear()
                self.active_spans.clear()

            def force_flush(self):
                # Force processing of any queued items
                pass
        ```

    Notes:
        - All methods should be thread-safe
        - Methods should not block for long periods
        - Handle errors gracefully to prevent disrupting agent execution
    Útracer   ÚreturnNc                 C   ó   dS )aT  Called when a new trace begins execution.

        Args:
            trace: The trace that started. Contains workflow name and metadata.

        Notes:
            - Called synchronously on trace start
            - Should return quickly to avoid blocking execution
            - Any errors should be caught and handled internally
        N© ©Úselfr   r   r   úc/var/www/html/openai_agents/venv/lib/python3.10/site-packages/agents/tracing/processor_interface.pyÚon_trace_start5   ó   zTracingProcessor.on_trace_startc                 C   r
   )aQ  Called when a trace completes execution.

        Args:
            trace: The completed trace containing all spans and results.

        Notes:
            - Called synchronously when trace finishes
            - Good time to export/process the complete trace
            - Should handle cleanup of any trace-specific resources
        Nr   r   r   r   r   Úon_trace_endC   r   zTracingProcessor.on_trace_endÚspanú	Span[Any]c                 C   r
   )aX  Called when a new span begins execution.

        Args:
            span: The span that started. Contains operation details and context.

        Notes:
            - Called synchronously on span start
            - Should return quickly to avoid blocking execution
            - Spans are automatically nested under current trace/span
        Nr   ©r   r   r   r   r   Úon_span_startQ   r   zTracingProcessor.on_span_startc                 C   r
   )a9  Called when a span completes execution.

        Args:
            span: The completed span containing execution results.

        Notes:
            - Called synchronously when span finishes
            - Should not block or raise exceptions
            - Good time to export/process the individual span
        Nr   r   r   r   r   Úon_span_end_   r   zTracingProcessor.on_span_endc                 C   r
   )zØCalled when the application stops to clean up resources.

        Should perform any necessary cleanup like:
        - Flushing queued traces/spans
        - Closing connections
        - Releasing resources
        Nr   ©r   r   r   r   Úshutdownm   ó   	zTracingProcessor.shutdownc                 C   r
   )a  Forces immediate processing of any queued traces/spans.

        Notes:
            - Should process all queued items before returning
            - Useful before shutdown or when immediate processing is needed
            - May block while processing completes
        Nr   r   r   r   r   Úforce_flushx   r   zTracingProcessor.force_flush)r   r   r	   N)r   r   r	   N)r	   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚabcÚabstractmethodr   r   r   r   r   r   r   r   r   r   r   	   s    +
r   c                   @   s,   e Zd ZdZejded ddfdd„ƒZdS )ÚTracingExporterzPExports traces and spans. For example, could log them or send them to a backend.ÚitemszTrace | Span[Any]r	   Nc                 C   r
   )zcExports a list of traces and spans.

        Args:
            items: The items to export.
        Nr   )r   r"   r   r   r   Úexport‡   s   zTracingExporter.export)r   r   r   r   r   r    Úlistr#   r   r   r   r   r!   „   s    r!   )r   Útypingr   r   Úspansr   Útracesr   ÚABCr   r!   r   r   r   r   Ú<module>   s    {