# usage: python3 otelgrep.py import json,sys,re svcpat=re.compile(sys.argv[2]); pat=re.compile(sys.argv[3],re.I) for line in open(sys.argv[1]): try: d=json.loads(line) except: continue for rl in d.get('resourceLogs',[]): svc=next((a['value'].get('stringValue') for a in rl['resource'].get('attributes',[]) if a['key']=='service.name'),'?') if not svcpat.search(svc): continue for sl in rl.get('scopeLogs',[]): for r in sl.get('logRecords',[]): body=r.get('body',{}).get('stringValue','') if pat.search(body): print(svc,r.get('timeUnixNano','')[:10],r.get('severityText'),'|',body[:260])