Convert a Weave Call (with nested children) into a Agent-lightning Span. `rollout_id` and `attempt_id` are required to attach the spans to the store. Args: call: The Weave Call object. rollout_id: Optional rollout ID to attach to spans. attempt_i
(
self,
call: tsi.CallSchema,
rollout_id: Optional[str] = None,
attempt_id: Optional[str] = None,
sequence_id: Optional[int] = None,
)
| 578 | logger.exception(f"Error adding span to store: {exc}") |
| 579 | |
| 580 | async def convert_call_to_span( |
| 581 | self, |
| 582 | call: tsi.CallSchema, |
| 583 | rollout_id: Optional[str] = None, |
| 584 | attempt_id: Optional[str] = None, |
| 585 | sequence_id: Optional[int] = None, |
| 586 | ) -> Span: |
| 587 | """Convert a Weave Call (with nested children) into a Agent-lightning Span. |
| 588 | |
| 589 | `rollout_id` and `attempt_id` are required to attach the spans to the store. |
| 590 | |
| 591 | Args: |
| 592 | call: The Weave Call object. |
| 593 | rollout_id: Optional rollout ID to attach to spans. |
| 594 | attempt_id: Optional attempt ID to attach to spans. |
| 595 | sequence_id: Optional sequence ID to attach to spans. |
| 596 | |
| 597 | Returns: |
| 598 | List of converted spans. |
| 599 | """ |
| 600 | rollout_id = rollout_id or "rollout-dummy" |
| 601 | attempt_id = attempt_id or "attempt-dummy" |
| 602 | sequence_id = sequence_id or 0 |
| 603 | |
| 604 | start_ts: float = call.started_at.timestamp() |
| 605 | end_ts: Optional[float] = call.ended_at.timestamp() if call.ended_at else None |
| 606 | |
| 607 | if call.exception: |
| 608 | status = TraceStatus(status_code="ERROR", description=call.exception) |
| 609 | else: |
| 610 | status = TraceStatus(status_code="OK") |
| 611 | |
| 612 | attributes: Dict[str, Any] = { |
| 613 | LightningSpanAttributes.OPERATION_NAME.value: call.op_name, |
| 614 | # op_name can be possibly overridden by the attributes. |
| 615 | **call.attributes, |
| 616 | } |
| 617 | if call.inputs: |
| 618 | attributes[LightningSpanAttributes.OPERATION_INPUT.value] = call.inputs |
| 619 | if call.output: |
| 620 | attributes[LightningSpanAttributes.OPERATION_OUTPUT.value] = call.output |
| 621 | if call.summary: |
| 622 | # attributes can be possibly overridden by the summary. |
| 623 | attributes.update(call.summary) |
| 624 | if call.exception: |
| 625 | attributes[exception_attributes.EXCEPTION_MESSAGE] = call.exception |
| 626 | |
| 627 | sanitized_attributes = sanitize_attributes(flatten_attributes(attributes, expand_leaf_lists=False)) |
| 628 | |
| 629 | context = SpanContext( |
| 630 | trace_id=call.trace_id, |
| 631 | span_id=call.id, |
| 632 | is_remote=False, |
| 633 | trace_state={}, |
| 634 | ) |
| 635 | |
| 636 | # Get context for parent |
| 637 | if call.parent_id: |