Testing locally
You can check an integration completely on your own machine, without a Zyonix server and without an API key. Local mode writes everything the SDK would send into a file, so you can see exactly which runs and steps your application produces and what would leave your process.
Local mode
Set two environment variables and run your application as usual:
export ZYONIX_MODE=local
export ZYONIX_LOCAL_PATH=zyonix-check.jsonl
python -m invoice_extractor.cli ./samples
$env:ZYONIX_MODE = "local"
$env:ZYONIX_LOCAL_PATH = "zyonix-check.jsonl"
python -m invoice_extractor.cli .\samples
- No key is needed and nothing leaves the machine.
- Your application's output must be identical to a run without these variables.
ZYONIX_LOCAL_PATHis relative to the folder the application runs in. Without it the file iszyonix-traces.jsonl. The SDK appends to the file: delete it between attempts to keep the results apart.- The file contains exactly what remote mode would send: redacted, size-limited and, in
hash_onlymode, with content replaced by hashes. To see what full capture would send, addcapture: fullto azyonix.yaml(orinit(capture="full")) while you test, and check that everything readable in the file may be shared.
For a quick look without a file, ZYONIX_MODE=console prints one line per span on standard error:
[zyonix] LLM extract 812.40 ms trace=e42072c4278e2e4022f2cd7d80afd757 status=UNSET
[zyonix] RUN zyonix.run 901.12 ms trace=e42072c4278e2e4022f2cd7d80afd757 doc=INV-2026-0042 status=UNSET
Reading the file
Each line of the file is one JSON object:
{"type": "otlp_traces", "data": {...}}: a batch of spans in the standard OpenTelemetry JSON format. The spans are indata.resourceSpans[].scopeSpans[].spans[]; each span has atraceId(the run), anameand a list ofattributes({"key": ..., "value": {"stringValue": ...}}).{"type": "feedback", "data": {...}}: onezyonix.feedbackcall.
What to look for:
| Attribute | On | Check |
|---|---|---|
zyonix.span.kind = RUN, name zyonix.run | one span per document | exactly one per document you processed |
zyonix.run.doc_id | the run span | your document's own id, not a random value |
zyonix.step.name | one span per step | your step names |
zyonix.step.replayable = true | at most one step | the model call |
zyonix.record.ref | the run span | zyonix.output was called (the recorded result) |
zyonix.check.name, zyonix.check.passed | check spans | your zyonix.check / zyonix.flag calls |
zyonix.input.truncated, zyonix.output.truncated, zyonix.record.truncated | any span | should be absent; if present, raise max_payload_bytes |
llm.model_name and other llm.* attributes | model-call spans | your LLM library is recorded |
This script prints one line per span:
# read_zyonix_check.py
import json
import sys
path = sys.argv[1] if len(sys.argv) > 1 else "zyonix-check.jsonl"
def value(v: dict):
for key in ("stringValue", "boolValue", "intValue", "doubleValue"):
if key in v:
return v[key]
return v
with open(path, encoding="utf-8") as fh:
for line in fh:
item = json.loads(line)
if item["type"] == "feedback":
print("feedback", item["data"]["doc_id"], item["data"]["verdict"])
continue
for resource in item["data"]["resourceSpans"]:
for scope in resource["scopeSpans"]:
for span in scope["spans"]:
attrs = {a["key"]: value(a["value"]) for a in span.get("attributes", [])}
kind = attrs.get("zyonix.span.kind") or attrs.get("openinference.span.kind", "-")
print(span["traceId"][:12], f"{kind:<9}", span["name"],
{k: v for k, v in attrs.items()
if k in ("zyonix.run.doc_id", "zyonix.step.replayable",
"zyonix.record.ref", "zyonix.check.passed",
"llm.model_name")})
python read_zyonix_check.py zyonix-check.jsonl
Example output for one document:
e42072c4278e PARSE parse {}
e42072c4278e LLM ChatCompletion {'llm.model_name': 'gpt-4o-mini'}
e42072c4278e LLM extract {'zyonix.step.replayable': True}
e42072c4278e TRANSFORM validate {}
e42072c4278e CHECK check:line_items_add_up {'zyonix.check.passed': True}
e42072c4278e TOOL save_invoice {}
e42072c4278e RUN zyonix.run {'zyonix.run.doc_id': 'INV-2026-0042', 'zyonix.record.ref': 'sha256:4512d83c...'}
Spans are written when they end, so the run span comes last. The first 12 characters are the run's trace id: every span of one document shares it.
Delete the file when you are done. With full capture it contains your redacted documents.
Starting a configuration file: zyonix init
zyonix init --service invoice-extractor --endpoint https://zyonix.example.com
writes a commented zyonix.yaml in the current folder with every setting and its explanation
(see Configuration). It refuses to overwrite
an existing file without --force; --path writes it elsewhere.
Before you use the file, check two lines in it:
capture: full: the template turns full capture on. Change it tocapture: hash_onlyunless you have decided to send content.egress_allow: []: if your Zyonix address is a public name, put its host here (egress_allow: [zyonix.example.com]), or setZYONIX_EGRESS_ALLOW.
(zyonix init --agent is something else: it writes instructions for a coding agent that
investigates problems later. It needs the zyonix-cli package.)
What zyonix doctor checks
zyonix doctor checks a setup from top to bottom, stops at the first failure, and sends one test
document. Run it in the same environment as your application (same shell, container or pod), so it
sees the same variables and the same zyonix.yaml.
A successful run against a server:
Zyonix doctor
[info] config file: zyonix.yaml
[info] service=invoice-extractor mode=remote capture=hash_only redaction=email,phone,iban,card_number
[info] endpoint=https://zyonix.example.com api_key=zx_sdk_xxx...
[info] capture=hash_only: zyonix.yaml does not set capture, so only content hashes leave the process (grounding and replay need content: set `capture: full` in zyonix.yaml or init(capture='full'))
[ ok ] data boundary: local-only on; data goes only to zyonix.example.com (external, explicitly allowed)
[info] otel_provider=private: Zyonix spans never reach your application's own OpenTelemetry exporters
[ ok ] LLM library openai 1.82.0: auto-instrumented
[ ok ] backend reachable (48 ms)
[ ok ] API key accepted (project invoice-extractor)
[ ok ] test trace stored: run 0b302fc1da9a18d4bec94d64af55185c (inspect: zyonix runs show 0b302fc1da9a)
5 ok, 0 warning(s), 0 failed
all checks passed
Line by line:
| Line | What it checks | If it fails |
|---|---|---|
config file: | Which zyonix.yaml was read, or (none, using env/defaults). | [FAIL] config file ... is invalid: ...: the file has a YAML error, an unknown key or a wrong value, and tracing is off until it is fixed. The message says what is wrong. |
service=... mode=... capture=... redaction=... | The settings in effect. mode=off means nothing would be sent. | |
endpoint=... api_key=... | The address, and the first characters of the key ((not set) when there is none). | |
capture=... | The capture mode and where it came from: (set in zyonix.yaml), (set in init()), or why it is hash_only. | Informational. |
data boundary: | That the endpoint is local, or listed in egress_allow. | [FAIL] endpoint host ... is not local and not listed in egress_allow: add the host to ZYONIX_EGRESS_ALLOW. [FAIL] ... plain http://: use the https:// address. [warn] local-only OFF: local_only: false is set. |
otel_provider= | Whether Zyonix spans stay private. | [warn] otel_provider=shared: your own exporters also receive Zyonix data. |
LLM library ... | Each supported LLM library that is installed, and whether its calls are recorded. | [warn] ... not instrumented; install zyonix-sdk[name]. [warn] no supported LLM library found is normal if you use another library. |
tracing is off | Shown instead of the following lines when there is neither a key nor a local mode. | [FAIL]: set ZYONIX_API_KEY, or ZYONIX_MODE=local. |
endpoint is not HTTPS | Remote mode over plain http:// to a local address. | [warn]: the key travels unencrypted. |
backend reachable | That the server answers its health check, and how fast. | cannot reach ...: wrong address, network or firewall. With CERTIFICATE_VERIFY_FAILED: set ZYONIX_CA_FILE. returned HTTP 3xx: the server redirects; use the address it names. |
API key accepted (project ...) | That the server knows the key, and which agent it belongs to. | API key rejected (HTTP 401): wrong, revoked, or from another installation. |
guard ... | Runtime repair settings of your agent, when the server reports any. | A warning that the Guard cannot run here: ask an administrator to turn the strategies off. |
test trace stored | Sends a test document (doc_id zyonix-doctor-..., source zyonix doctor) through the real export path and confirms the server stored it. | test trace not exported: the key cannot send (for example an agent key) or the server is overloaded. not found on the backend: the server's background worker is not running, or the key belongs to another agent. |
N ok, N warning(s), N failed / all checks passed | The summary. | doctor stopped at the first failed check: fix that line and run it again. |
In local mode the network lines are skipped and the last check says
test trace ... written to <your local_path> (the test document is appended to that file). In
console mode it is printed to standard error.
Options:
| Option | Meaning |
|---|---|
--config PATH | Another configuration file. |
--endpoint URL | Check another address. |
--api-key KEY | Check another key (it then appears in your shell history: prefer the variable). |
--ca-file PATH | Another CA file. |
--json | One JSON document on standard output ("schema": "zyonix.doctor/1") with the overall status, the settings and every check. It never contains the key. |
Exit code 0 means every check passed (warnings included), 1 means one failed. That makes it usable as a deployment health check:
zyonix doctor --json > doctor.json || echo "Zyonix is not set up correctly"
The test document appears on the website under Documents with the id zyonix-doctor-....
When ZYONIX_API_KEY is not set and the zyonix-cli package is installed, zyonix doctor uses
the session saved by zyonix login instead. It can then pass while your application, which reads
only ZYONIX_API_KEY, sends nothing. To test what the application will do, run doctor with the
application's own variables set.
Running your application's tests
Your tests need no change:
- Without
ZYONIX_API_KEYand withoutZYONIX_MODE,zyonix.init()turns tracing off, and every decorator simply calls your function. Results, exceptions and return values are exactly as before. - Make sure your test environment does not have a real
ZYONIX_API_KEYset (for example inherited from a developer's shell or a CI secret), or your test documents are sent to Zyonix. In CI, set the key only for jobs that should send. - If a test should check the integration itself, run it in local mode and read the file:
# tests/test_zyonix_integration.py
import json
from pathlib import Path
import zyonix
from invoice_extractor.pipeline import process
SAMPLE = Path(__file__).parent / "data" / "invoice.txt" # a synthetic test document
def test_one_run_per_document(tmp_path, monkeypatch):
path = tmp_path / "zyonix.jsonl"
monkeypatch.chdir(tmp_path) # no zyonix.yaml from the project folder
zyonix.shutdown()
zyonix.init(service="invoice-extractor-test", mode="local", local_path=str(path),
instrument="none")
try:
process("TEST-1", str(SAMPLE)) # with your usual test doubles for the model and database
assert zyonix.flush(5)
finally:
zyonix.shutdown()
doc_ids = []
for line in path.read_text(encoding="utf-8").splitlines():
item = json.loads(line)
if item["type"] != "otlp_traces":
continue
for resource in item["data"]["resourceSpans"]:
for scope in resource["scopeSpans"]:
for span in scope["spans"]:
for attr in span.get("attributes", []):
if attr["key"] == "zyonix.run.doc_id":
doc_ids.append(attr["value"]["stringValue"])
assert doc_ids == ["TEST-1"]
zyonix.shutdown() before and after keeps one test's SDK state from leaking into another, because
init takes effect only once per process.