Trace Utils

class ibm_watsonx_gov.traces.trace_utils.TraceUtils

Bases: object

static build_span_trees(spans: list[dict], agentic_app: AgenticApp | None = None) List[SpanNode]
static calculate_cost(usage_data: List[dict]) float

Calculate cost for given list of usage.

static compute_metrics_from_trace(span_tree: SpanNode, api_client: APIClient = None) tuple[list[AgentMetricResult], list[Node], list]
async static compute_metrics_from_trace_async(span_tree: SpanNode, api_client: APIClient = None, **kwargs) tuple[list[AgentMetricResult], list[Node], list]
async static compute_metrics_from_trace_async_v2(span_tree: SpanNode, metrics_configuration: MetricsConfiguration, api_client: APIClient = None, **kwargs) Tuple[List[AgentMetricResult], MessageData, List[NodeData], MetricsMappingData, List[Node]]

Process span tree data to compute comprehensive metrics and extract execution artifacts.

This method orchestrates the end-to-end metrics computation pipeline by: 1. Extracting and processing raw data from span traces 2. Computing metrics from the extracted trace data 3. Calculating additional metrics based on mapping configurations

static convert_array_value(array_obj: Dict) List

Convert OTEL array value to Python list

static stream_trace_data(file_path: Path) Generator

Generator that yields spans one at a time.