For the complete documentation index, see llms.txt. This page is also available as Markdown.

Backfill traces from logs

Recipe — backfill traces from existing application logs.

When to use: you have months of application logs but no Stratix traces — need to bootstrap evaluation history.

Pattern

  1. Parse your application logs into the Stratix trace shape.

  2. Write JSONL files (≤50 MB per file).

  3. Upload each file via client.traces.upload(file_path). The SDK handles presigned-S3 upload and trace-record creation in three steps.

import json
from pathlib import Path
from layerlens import Stratix

client = Stratix()

def chunked_jsonl(records, chunk_path_template, max_bytes=45_000_000):
 """Split records into ≤45 MB JSONL files (50 MB hard limit; 45 MB safe)."""
 chunk_idx, current_size, current_records = 0, 0, []
 for r in records:
 line = json.dumps(r)
 if current_size + len(line) > max_bytes and current_records:
 path = chunk_path_template.format(chunk_idx)
 Path(path).write_text("\n".join(current_records))
 yield path
 chunk_idx += 1
 current_size, current_records = 0, []
 current_records.append(line)
 current_size += len(line) + 1
 if current_records:
 path = chunk_path_template.format(chunk_idx)
 Path(path).write_text("\n".join(current_records))
 yield path

# Yield JSONL chunks from your log parser, upload each
for chunk_path in chunked_jsonl(parse_logs(), "backfill_{}.jsonl"):
 result = client.traces.upload(chunk_path)
 print(f"Uploaded {len(result.trace_ids)} traces from {chunk_path}")

See also

Last updated

Was this helpful?