Source code for swarmauri.standard.tracing.concrete.SimpleTraceContext

from datetime import datetime
from typing import Dict, Any, Optional

from swarmauri.core.tracing.ITraceContext import ITraceContext

[docs] class SimpleTraceContext(ITraceContext): def __init__(self, trace_id: str, name: str, initial_attributes: Optional[Dict[str, Any]] = None): self.trace_id = trace_id self.name = name self.attributes = initial_attributes if initial_attributes else {} self.start_time = datetime.now() self.end_time = None
[docs] def get_trace_id(self) -> str: return self.trace_id
[docs] def add_attribute(self, key: str, value: Any): self.attributes[key] = value
[docs] def close(self): self.end_time = datetime.now()