Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Traces

Trace

A trace is the root level object that tracing creates. It represents a logical "workflow".

Source code insrc/agents/tracing/traces.py
classTrace:"""    A trace is the root level object that tracing creates. It represents a logical "workflow".    """@abc.abstractmethoddef__enter__(self)->Trace:pass@abc.abstractmethoddef__exit__(self,exc_type,exc_val,exc_tb):pass@abc.abstractmethoddefstart(self,mark_as_current:bool=False):"""        Start the trace.        Args:            mark_as_current: If true, the trace will be marked as the current trace.        """pass@abc.abstractmethoddeffinish(self,reset_current:bool=False):"""        Finish the trace.        Args:            reset_current: If true, the trace will be reset as the current trace.        """pass@property@abc.abstractmethoddeftrace_id(self)->str:"""        The trace ID.        """pass@property@abc.abstractmethoddefname(self)->str:"""        The name of the workflow being traced.        """pass@abc.abstractmethoddefexport(self)->dict[str,Any]|None:"""        Export the trace as a dictionary.        """pass

trace_idabstractmethodproperty

trace_id:str

The trace ID.

nameabstractmethodproperty

name:str

The name of the workflow being traced.

startabstractmethod

start(mark_as_current:bool=False)

Start the trace.

Parameters:

NameTypeDescriptionDefault
mark_as_currentbool

If true, the trace will be marked as the current trace.

False
Source code insrc/agents/tracing/traces.py
@abc.abstractmethoddefstart(self,mark_as_current:bool=False):"""    Start the trace.    Args:        mark_as_current: If true, the trace will be marked as the current trace.    """pass

finishabstractmethod

finish(reset_current:bool=False)

Finish the trace.

Parameters:

NameTypeDescriptionDefault
reset_currentbool

If true, the trace will be reset as the current trace.

False
Source code insrc/agents/tracing/traces.py
@abc.abstractmethoddeffinish(self,reset_current:bool=False):"""    Finish the trace.    Args:        reset_current: If true, the trace will be reset as the current trace.    """pass

exportabstractmethod

export()->dict[str,Any]|None

Export the trace as a dictionary.

Source code insrc/agents/tracing/traces.py
@abc.abstractmethoddefexport(self)->dict[str,Any]|None:"""    Export the trace as a dictionary.    """pass

NoOpTrace

Bases:Trace

A no-op trace that will not be recorded.

Source code insrc/agents/tracing/traces.py
classNoOpTrace(Trace):"""    A no-op trace that will not be recorded.    """def__init__(self):self._started=Falseself._prev_context_token:contextvars.Token[Trace|None]|None=Nonedef__enter__(self)->Trace:ifself._started:ifnotself._prev_context_token:logger.error("Trace already started but no context token set")returnselfself._started=Trueself.start(mark_as_current=True)returnselfdef__exit__(self,exc_type,exc_val,exc_tb):self.finish(reset_current=True)defstart(self,mark_as_current:bool=False):ifmark_as_current:self._prev_context_token=Scope.set_current_trace(self)deffinish(self,reset_current:bool=False):ifreset_currentandself._prev_context_tokenisnotNone:Scope.reset_current_trace(self._prev_context_token)self._prev_context_token=None@propertydeftrace_id(self)->str:return"no-op"@propertydefname(self)->str:return"no-op"defexport(self)->dict[str,Any]|None:returnNone

TraceImpl

Bases:Trace

A trace that will be recorded by the tracing library.

Source code insrc/agents/tracing/traces.py
classTraceImpl(Trace):"""    A trace that will be recorded by the tracing library.    """__slots__=("_name","_trace_id","group_id","metadata","_prev_context_token","_processor","_started",)def__init__(self,name:str,trace_id:str|None,group_id:str|None,metadata:dict[str,Any]|None,processor:TracingProcessor,):self._name=nameself._trace_id=trace_idorutil.gen_trace_id()self.group_id=group_idself.metadata=metadataself._prev_context_token:contextvars.Token[Trace|None]|None=Noneself._processor=processorself._started=False@propertydeftrace_id(self)->str:returnself._trace_id@propertydefname(self)->str:returnself._namedefstart(self,mark_as_current:bool=False):ifself._started:returnself._started=Trueself._processor.on_trace_start(self)ifmark_as_current:self._prev_context_token=Scope.set_current_trace(self)deffinish(self,reset_current:bool=False):ifnotself._started:returnself._processor.on_trace_end(self)ifreset_currentandself._prev_context_tokenisnotNone:Scope.reset_current_trace(self._prev_context_token)self._prev_context_token=Nonedef__enter__(self)->Trace:ifself._started:ifnotself._prev_context_token:logger.error("Trace already started but no context token set")returnselfself.start(mark_as_current=True)returnselfdef__exit__(self,exc_type,exc_val,exc_tb):self.finish(reset_current=exc_typeisnotGeneratorExit)defexport(self)->dict[str,Any]|None:return{"object":"trace","id":self.trace_id,"workflow_name":self.name,"group_id":self.group_id,"metadata":self.metadata,}

[8]ページ先頭

©2009-2025 Movatter.jp