> 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/6.-build-wire-your-code/instrument-haystack.md).

# Instrument Haystack

{% hint style="warning" %}
**Private preview.** This surface is not yet generally available. Adapters live in the Python SDK today and the rendering / configuration UX is under iteration. Contact <support@layerlens.ai> to request access to the private preview.
{% endhint %}

**When to use:** Haystack pipeline (RAG, search) and you want traces in Stratix.

The Stratix SDK does not currently ship a dedicated Haystack adapter. Use manual trace upload after each pipeline run.

```python
import json, uuid
from pathlib import Path
from layerlens import Stratix
client = Stratix()

# Run your Haystack pipeline
result = pipeline.run({"text_embedder": {"text": query}, "prompt_builder": {"query": query}})

# Build a trace record (data is flexible Dict[str, Any])
trace_record = {
 "id": str(uuid.uuid4()),
 "input": query,
 "output": result["llm"]["replies"][0] if "llm" in result else None,
 "data": {
 "haystack_pipeline_outputs": result,
 },
}

Path("haystack_trace.jsonl").write_text(json.dumps(trace_record))
client.traces.upload("haystack_trace.jsonl")
```

## See also

* [Workflow: Instrument](/6.-build-wire-your-code/workflow.md)
* [Integrations](/6.-build-wire-your-code/migration.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/6.-build-wire-your-code/instrument-haystack.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.
