Skip to content

Commit 6d92d69

Browse files
committed
fix(telemetryapi): repair unit test
1 parent b3b9c93 commit 6d92d69

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

llama_stack/providers/inline/telemetry/meta_reference/sqlite_span_processor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ def on_end(self, span: Span):
112112
if parent_context:
113113
parent_span_id = format_span_id(parent_context.span_id)
114114

115+
# Determine if this span should be marked as root:
116+
# 1. If it has LOCAL_ROOT_SPAN_MARKER attribute (explicitly marked by start_trace())
117+
# 2. If it has no parent (implicit root span from FastAPI instrumentation)
118+
is_root_span = span.attributes.get(LOCAL_ROOT_SPAN_MARKER) or parent_span_id is None
119+
root_span_id_value = span_id if is_root_span else None
120+
115121
# Insert into traces
116122
cursor.execute(
117123
"""
@@ -126,7 +132,7 @@ def on_end(self, span: Span):
126132
(
127133
trace_id,
128134
service_name,
129-
(span_id if span.attributes.get(LOCAL_ROOT_SPAN_MARKER) else None),
135+
root_span_id_value,
130136
datetime.fromtimestamp(span.start_time / 1e9, UTC).isoformat(),
131137
datetime.fromtimestamp(span.end_time / 1e9, UTC).isoformat(),
132138
),

llama_stack/providers/utils/telemetry/sqlite_trace_store.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
QueryCondition,
2020
QueryMetricsResponse,
2121
Span,
22+
SpanStatus,
2223
SpanWithStatus,
2324
Trace,
2425
)
@@ -343,6 +344,11 @@ async def get_span_tree(
343344
raise ValueError(f"Span {span_id} not found")
344345

345346
for row in rows:
347+
# Map OpenTelemetry status codes to API enum values
348+
# OTEL has: UNSET, OK, ERROR -> Map to SpanStatus enum
349+
otel_status = row["status"].upper()
350+
status = SpanStatus.ERROR if otel_status == "ERROR" else SpanStatus.OK
351+
346352
span = SpanWithStatus(
347353
span_id=row["span_id"],
348354
trace_id=row["trace_id"],
@@ -351,7 +357,7 @@ async def get_span_tree(
351357
start_time=datetime.fromisoformat(row["start_time"]),
352358
end_time=datetime.fromisoformat(row["end_time"]),
353359
attributes=json.loads(row["filtered_attributes"]),
354-
status=row["status"].lower(),
360+
status=status,
355361
)
356362

357363
spans_by_id[span.span_id] = span

0 commit comments

Comments
 (0)