MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / Span

Class Span

app/api/agentops/exporter/models.py:42–179  ·  view source on GitHub ↗

Span is a representation of a single operation within a trace. It can be a root span or a child span.

Source from the content-addressed store, hash-verified

40
41
42class Span(pydantic.BaseModel):
43 """
44 Span is a representation of a single operation within a trace.
45 It can be a root span or a child span.
46 """
47
48 name: Optional[str] = None
49 trace_id: Optional[str] = None
50 span_id: str
51 parent_span_id: Optional[str] = None
52 kind: Union[SpanKind, str] = SpanKind.INTERNAL
53 start_time: int = 0
54 end_time: Optional[int] = None
55 project_id: Optional[str] = None
56 service_name: str = DEFAULT_SERVICE_NAME
57 scope_name: str = DEFAULT_SCOPE_NAME
58 scope_version: str = DEFAULT_VERSION
59 resource_attributes: dict[str, str] = pydantic.Field(default_factory=dict)
60 span_attributes: dict[str, str] = pydantic.Field(default_factory=dict)
61 status_code: str = "OK"
62 status_message: str = ""
63 events: list[dict[str, Any]] = pydantic.Field(default_factory=list)
64 links: list[dict[str, Any]] = pydantic.Field(default_factory=list)
65
66 model_config = {
67 'arbitrary_types_allowed': True,
68 }
69
70 def __repr__(self) -> str:
71 return f"Span(span_id={self.span_id}, parent_span_id={self.parent_span_id})"
72
73 def model_post_init(self, __context) -> None:
74 if self.end_time is None:
75 self.end_time = self.start_time
76
77 @property
78 def duration(self) -> int:
79 """Calculate duration in nanoseconds"""
80 if self.end_time and self.start_time:
81 return self.end_time - self.start_time
82 return 0
83
84 def to_clickhouse_dict(self) -> dict[str, Any]:
85 """Convert to a dictionary ready for ClickHouse insertion"""
86
87 if self.start_time:
88 timestamp = ns_to_datetime(self.start_time)
89 else:
90 timestamp = datetime.now(timezone.utc)
91
92 # otel_context = SpanContext(
93 # trace_id=trace_id,
94 # span_id=span_id,
95 # is_remote=False,
96 # trace_flags=TraceFlags(0x1), # SAMPLED
97 # trace_state=TraceState()
98 # )
99

Callers 6

to_traceMethod · 0.70
to_spanMethod · 0.70
to_spanMethod · 0.70
to_spanMethod · 0.70
to_spanMethod · 0.70
to_spanMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…