> 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

**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)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.layerlens.ai/7.-observe-see-whats-happening/backfill-from-logs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
