from swarmauri.core.tracing.ITraceContext import ITraceContext
from abc import ABC, abstractmethod
from typing import Optional, Dict, Any
[docs]
class ITracer(ABC):
"""
Interface for implementing distributed tracing across different components of the system.
"""
[docs]
@abstractmethod
def start_trace(self, name: str, initial_attributes: Optional[Dict[str, Any]] = None) -> ITraceContext:
"""
Starts a new trace with a given name and optional initial attributes.
Args:
name (str): Name of the trace, usually represents the operation being traced.
initial_attributes (Optional[Dict[str, Any]]): Key-value pairs to be attached to the trace initially.
Returns:
ITraceContext: A context object representing this particular trace instance.
"""
pass
[docs]
@abstractmethod
def end_trace(self, trace_context: ITraceContext):
"""
Marks the end of a trace, completing its lifecycle and recording its details.
Args:
trace_context (ITraceContext): The trace context to be ended.
"""
pass
[docs]
@abstractmethod
def annotate_trace(self, trace_context: ITraceContext, key: str, value: Any):
"""
Adds an annotation to an existing trace, enriching it with more detailed information.
Args:
trace_context (ITraceContext): The trace context to annotate.
key (str): The key or name of the annotation.
value (Any): The value of the annotation.
"""
pass