Parse an OTLP-JSON trace document into a flat list of :class:SpanData.
Accepts both the "batches" key (Tempo's trace-by-id response) and the "resourceSpans" key (raw OTLP export), and both "scopeSpans" and the legacy "instrumentationLibrarySpans".
Source code in autogen/beta/eval/sources/_otlp_json.py
| def otlp_json_to_spans(doc: dict[str, Any]) -> list[SpanData]:
"""Parse an OTLP-JSON trace document into a flat list of :class:`SpanData`.
Accepts both the ``"batches"`` key (Tempo's trace-by-id response) and the
``"resourceSpans"`` key (raw OTLP export), and both ``"scopeSpans"`` and the
legacy ``"instrumentationLibrarySpans"``.
"""
batches = doc.get("batches") or doc.get("resourceSpans") or []
spans: list[SpanData] = []
for batch in batches:
scopes = batch.get("scopeSpans") or batch.get("instrumentationLibrarySpans") or []
for scope in scopes:
for span in scope.get("spans", []):
spans.append(_span_to_data(span))
return spans
|