@@ -213,10 +213,7 @@ async def add_spans_to_dataset(
213
213
if k in nonprivate_span_attributes
214
214
},
215
215
"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 ),
220
217
},
221
218
DatasetExampleRevision .revision_kind .key : "CREATE" ,
222
219
}
@@ -602,6 +599,19 @@ def _to_orm_revision(
602
599
}
603
600
604
601
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
+
605
615
def _serialize_span_annotation (span_annotation : models .SpanAnnotation ) -> dict [str , Any ]:
606
616
return {
607
617
"label" : span_annotation .label ,
0 commit comments