"""Verify exported parent relationships and the completed retry, not just trace existence.""" import base64 import json from collections import Counter from pathlib import Path ROOT=Path(__file__).resolve().parents[1] data=json.loads((ROOT/'evidence/review-retry-trace.json').read_text()) spans=[s for batch in data['trace']['batches'] for scope in batch.get('scopeSpans',[]) for s in scope.get('spans',[])] by_id={s['spanId']:s for s in spans} counts=Counter(s['name'] for s in spans) producers=[s for s in spans if s['kind']=='SPAN_KIND_PRODUCER'] consumers=[s for s in spans if s['kind']=='SPAN_KIND_CONSUMER'] assert len(producers)>=2 and consumers,counts for producer in producers: ancestor = producer for _ in range(len(spans)): ancestor = by_id[ancestor['parentSpanId']] if ancestor['kind']=='SPAN_KIND_SERVER': break else: raise AssertionError('producer has no API ancestor') for consumer in consumers: assert by_id[consumer['parentSpanId']]['kind']=='SPAN_KIND_PRODUCER' assert counts['postgres.complete_attachment_job']>=1,counts assert any(s['name'].startswith('s3.') for s in spans),counts assert all(base64.b64decode(s['traceId']).hex()==data['trace_id'] for s in spans) services={stream['stream']['service_name'] for stream in data['logs']['data']['result']} assert {'messenger-api','messenger-worker'}<=services,services result={'trace_id':data['trace_id'],'span_count':len(spans),'span_names':dict(counts), 'producer_count':len(producers),'consumer_count':len(consumers),'log_services':sorted(services), 'parent_relationships':'PASS','note':'Abrupt os._exit may lose unfinished spans of the crashed attempt; redelivery and committed retry remain visible.'} (ROOT/'evidence/review-retry-summary.json').write_text(json.dumps(result,indent=2)+'\n') print('PASS:',json.dumps(result))