跳至内容

Processor interface

TracingProcessor

基类: ABC

处理跨度的接口。

Source code in src/agents/tracing/processor_interface.py
class TracingProcessor(abc.ABC):
    """Interface for processing spans."""

    @abc.abstractmethod
    def on_trace_start(self, trace: "Trace") -> None:
        """Called when a trace is started.

        Args:
            trace: The trace that started.
        """
        pass

    @abc.abstractmethod
    def on_trace_end(self, trace: "Trace") -> None:
        """Called when a trace is finished.

        Args:
            trace: The trace that started.
        """
        pass

    @abc.abstractmethod
    def on_span_start(self, span: "Span[Any]") -> None:
        """Called when a span is started.

        Args:
            span: The span that started.
        """
        pass

    @abc.abstractmethod
    def on_span_end(self, span: "Span[Any]") -> None:
        """Called when a span is finished. Should not block or raise exceptions.

        Args:
            span: The span that finished.
        """
        pass

    @abc.abstractmethod
    def shutdown(self) -> None:
        """Called when the application stops."""
        pass

    @abc.abstractmethod
    def force_flush(self) -> None:
        """Forces an immediate flush of all queued spans/traces."""
        pass

跟踪开始 abstractmethod

on_trace_start(trace: Trace) -> None

在跟踪开始时调用。

参数:

名称 类型 描述 默认值
trace Trace

开始的追踪。

required
Source code in src/agents/tracing/processor_interface.py
@abc.abstractmethod
def on_trace_start(self, trace: "Trace") -> None:
    """Called when a trace is started.

    Args:
        trace: The trace that started.
    """
    pass

on_trace_end abstractmethod

on_trace_end(trace: Trace) -> None

当跟踪完成时调用。

参数:

名称 类型 描述 默认值
trace Trace

开始的追踪。

required
Source code in src/agents/tracing/processor_interface.py
@abc.abstractmethod
def on_trace_end(self, trace: "Trace") -> None:
    """Called when a trace is finished.

    Args:
        trace: The trace that started.
    """
    pass

on_span_start abstractmethod

on_span_start(span: Span[Any]) -> None

当开始一个span时调用。

参数:

名称 类型 描述 默认值
span Span[Any]

开始的跨度。

required
Source code in src/agents/tracing/processor_interface.py
@abc.abstractmethod
def on_span_start(self, span: "Span[Any]") -> None:
    """Called when a span is started.

    Args:
        span: The span that started.
    """
    pass

on_span_end abstractmethod

on_span_end(span: Span[Any]) -> None

当某个span完成时调用。不应阻塞或引发异常。

参数:

名称 类型 描述 默认值
span Span[Any]

已完成的跨度。

required
Source code in src/agents/tracing/processor_interface.py
@abc.abstractmethod
def on_span_end(self, span: "Span[Any]") -> None:
    """Called when a span is finished. Should not block or raise exceptions.

    Args:
        span: The span that finished.
    """
    pass

关机 abstractmethod

shutdown() -> None

当应用程序停止时调用。

Source code in src/agents/tracing/processor_interface.py
@abc.abstractmethod
def shutdown(self) -> None:
    """Called when the application stops."""
    pass

force_flush abstractmethod

force_flush() -> None

强制立即刷新所有排队的跨度/追踪数据。

Source code in src/agents/tracing/processor_interface.py
@abc.abstractmethod
def force_flush(self) -> None:
    """Forces an immediate flush of all queued spans/traces."""
    pass

TracingExporter

基类: ABC

导出跟踪和跨度数据。例如,可以将其记录或发送到后端。

Source code in src/agents/tracing/processor_interface.py
class TracingExporter(abc.ABC):
    """Exports traces and spans. For example, could log them or send them to a backend."""

    @abc.abstractmethod
    def export(self, items: list["Trace | Span[Any]"]) -> None:
        """Exports a list of traces and spans.

        Args:
            items: The items to export.
        """
        pass

导出 abstractmethod

export(items: list[Trace | Span[Any]]) -> None

导出一组追踪记录和跨度数据。

参数:

名称 类型 描述 默认值
items list[Trace | Span[Any]]

要导出的项目。

required
Source code in src/agents/tracing/processor_interface.py
@abc.abstractmethod
def export(self, items: list["Trace | Span[Any]"]) -> None:
    """Exports a list of traces and spans.

    Args:
        items: The items to export.
    """
    pass