MCPcopy
hub / github.com/microsoft/agent-lightning / convert_call_to_span

Method convert_call_to_span

agentlightning/tracer/weave.py:580–677  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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:

Callers 2

complete_call_handlerMethod · 0.95

Calls 9

TraceStatusClass · 0.90
sanitize_attributesFunction · 0.90
flatten_attributesFunction · 0.90
SpanContextClass · 0.90
SpanClass · 0.90
OtelResourceClass · 0.90
op_name_to_func_nameFunction · 0.85
updateMethod · 0.45
getMethod · 0.45

Tested by 1