> For the complete documentation index, see [llms.txt](https://docs.layerlens.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.layerlens.ai/7.-observe-see-whats-happening/backfill-from-logs.md).

# 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.

```python
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

* [Workflow: Instrument](/7.-observe-see-whats-happening/workflow.md)
* [Concept: Traces and spans](/6.-build-wire-your-code/traces-and-spans.md)
* [SDK reference: traces](https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/traces.md)
