"""observability.tracing — lambdagent Trace → structured spans."""
from __future__ import annotations
from typing import List, Dict


def bridge_trace(trace_entries: list) -> List[Dict]:
    """Convert lambdagent TraceEntry list to structured span dicts."""
    spans = []
    for i, entry in enumerate(trace_entries):
        spans.append({
            "step": i,
            "term_name": getattr(entry, 'term_name', ''),
            "duration_ms": getattr(entry, 'duration_ms', 0),
            "model": getattr(entry, 'model', ''),
            "tokens": getattr(entry, 'tokens_used', 0),
            "input_preview": str(getattr(entry, 'input', ''))[:100],
            "output_preview": str(getattr(entry, 'output', ''))[:100],
        })
    return spans
