"""Summarize one Tempo trace by id. Prints span names and parent links only.""" import json import sys import urllib.request trace_id = sys.argv[1] payload = json.load(urllib.request.urlopen(f"http://127.0.0.1:3200/api/traces/{trace_id}", timeout=10)) batches = payload.get("batches") or payload.get("resourceSpans") or [] # Tempo may return OTLP JSON under batches or the classic trace format. if "trace" in payload: spans = payload["trace"].get("spans") or [] for span in spans: print(span.get("name") or span.get("operationName"), span.get("spanID"), span.get("parentSpanID")) raise SystemExit def walk(node): if isinstance(node, dict): if "name" in node and ("spanId" in node or "span_id" in node): print( node.get("name"), "id=" + str(node.get("spanId") or node.get("span_id")), "parent=" + str(node.get("parentSpanId") or node.get("parent_span_id") or "-"), ) for value in node.values(): walk(value) elif isinstance(node, list): for item in node: walk(item) walk(payload)