Skip to content

Commit 1371f70

Browse files
committed
gather span annotations by name
1 parent d72af30 commit 1371f70

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/phoenix/server/api/mutations/dataset_mutations.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,7 @@ async def add_spans_to_dataset(
213213
if k in nonprivate_span_attributes
214214
},
215215
"span_kind": span.span_kind,
216-
"annotations": [
217-
_serialize_span_annotation(span_annotation)
218-
for span_annotation in span.span_annotations
219-
],
216+
"annotations": _gather_span_annotations_by_name(span.span_annotations),
220217
},
221218
DatasetExampleRevision.revision_kind.key: "CREATE",
222219
}
@@ -602,6 +599,19 @@ def _to_orm_revision(
602599
}
603600

604601

602+
def _gather_span_annotations_by_name(
603+
span_annotations: list[models.SpanAnnotation],
604+
) -> dict[str, list[dict[str, Any]]]:
605+
span_annotations_by_name: dict[str, list[dict[str, Any]]] = {}
606+
for span_annotation in span_annotations:
607+
if span_annotation.name not in span_annotations_by_name:
608+
span_annotations_by_name[span_annotation.name] = []
609+
span_annotations_by_name[span_annotation.name].append(
610+
_serialize_span_annotation(span_annotation)
611+
)
612+
return span_annotations_by_name
613+
614+
605615
def _serialize_span_annotation(span_annotation: models.SpanAnnotation) -> dict[str, Any]:
606616
return {
607617
"label": span_annotation.label,

0 commit comments

Comments
 (0)