Skip to content

Instantly share code, notes, and snippets.

@zed-eiq
Created September 24, 2025 21:02
Show Gist options
  • Select an option

  • Save zed-eiq/c2e836b67a1be6310f829788b9de5013 to your computer and use it in GitHub Desktop.

Select an option

Save zed-eiq/c2e836b67a1be6310f829788b9de5013 to your computer and use it in GitHub Desktop.
import json
from datetime import datetime
TRACE_ID='45b893611ffd06a3cfb3cbfe93e1f601'
RUN_ID='579c4210-5dc3-4562-b3a6-916e090f6d81'
def get_timestamp(timestamp: str) -> datetime:
return datetime.strptime(timestamp,"%Y-%m-%dT%H:%M:%S.%fZ")
def main():
with open("data/logfile.ndjson") as fp:
_data = fp.readlines()
data = []
for line in _data:
if TRACE_ID in line or RUN_ID in line:
line = json.loads(line)
data.append(line)
out = []
for i,line in enumerate(data):
if line.get("timestamp", None) is None:
continue
if i != 0:
line["time_taken"] = (get_timestamp(line["timestamp"]) - get_timestamp(data[i-1]["timestamp"])).total_seconds()
out.append(json.dumps(line))
print(out[1])
with open("output.ndjson","w") as fp:
for i in out:
fp.write(i + '\n')
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment