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

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

The question should be specific, self-contained, and written in natural language.
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.
