zhanla
Trace an LLM agent for Zhanla: OpenTelemetry spans for each request, its model calls and its tool calls, sent to the Zhanla eval run that started the process or, in production, to your organization.
pip install zhanla
import zhanla
zhanla.init(agent="<your agent's id in Zhanla>")
@zhanla.observe # the function that handles one request: its call is the root of the trajectory
def answer(question):
... # your agent: OpenAI, Anthropic, LangChain, LlamaIndex, LiteLLM, CrewAI and the OpenAI Agents SDK are traced on their own
Zhanla offers to write this for you when it sets your agent up, as a diff you accept.
Versions before 0.2.0 of this name on PyPI were an earlier Zhanla command-line tool, unrelated to this SDK.
Where spans go
- An eval run. Zhanla starts your agent with
ZHANLA_TRACE_ENDPOINTandZHANLA_TRACE_ITEMset; nothing to configure. - Production. Set
ZHANLA_API_KEYto an SDK key made on your organization's settings page (ZHANLA_INGEST_URLoverrides where they go). - Neither. Tracing is off, with one line on stderr. The SDK never writes to stdout and never stops your agent: a failed export is said once on stderr.
Spans waiting to be sent go as the process exits (atexit); a server that stops on a signal calls zhanla.flush() first. A process that calls os._exit loses them.
What is traced
init instruments the libraries your environment has and returns their names. When a framework (LangChain, LlamaIndex, CrewAI) calls a client it covers, the call is recorded once, by the framework; calls you make on the client yourself are kept.
By hand:
@zhanla.observe / @zhanla.observe(name=...) |
a span per call (sync or async) with its arguments and result |
with zhanla.span(name, kind=None): |
a span of its own; kind="subagent" or "skill" says what it is |
zhanla.generation(model, input).end(output, input_tokens, output_tokens, thinking, thinking_tokens) |
a model call |
zhanla.tool(name, arguments, mcp=None, kind=None).end(result) |
a tool call |
set_session_id, set_user_id, set_tags, set_metadata |
stamped on every span started after, for this request |
zhanla.init(agent, mask=...): mask runs on every input and output before anything leaves the process; what it returns is what is sent.
Serverless functions and named libraries
zhanla.init(agent="<id>", instrument={"openai": openai}) # instrument these, and raise if one cannot be
On AWS Lambda, Vercel, Netlify, Google Cloud Functions and Run, and Azure Functions, the outermost observe sends its request's spans as it ends, before it returns, so a frozen function loses nothing; serverless=True turns this on elsewhere, False turns it off.
Servers
A request Zhanla sends to a server you run carries baggage: zhanla.item=<id>, so one server serves every eval item:
app.add_middleware(zhanla.ASGIMiddleware) # FastAPI, Starlette
app.wsgi_app = zhanla.WSGIMiddleware(app.wsgi_app) # Flask
Requires Python 3.10 or later.
Metadata
Release files for zhanla 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zhanla-0.2.0.tar.gz | 21.4 kB | Without provenance | Details for zhanla-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zhanla-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for zhanla-0.2.0-py3-none-any.whl |
Total release size: 33.6 kB
Release files / zhanla-0.2.0.tar.gz
| Download URL | zhanla-0.2.0.tar.gz |
|---|---|
| Size | 21.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d35a8cd4a74698d93eb67a9741a8d3cbb4ac0afb5d9db024a21be509a63db85
|
|
BLAKE2b-256 checksum How to use checksums |
f07234847d6a0640bf51ea2ebb2d071e4bf1c2c45575ad2e3f4f36fb47f13c42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / zhanla-0.2.0-py3-none-any.whl
| Download URL | zhanla-0.2.0-py3-none-any.whl |
|---|---|
| Size | 12.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ea3443b6228b4699f8738b038de39a40858231985aba28428663774f7152d7d
|
|
BLAKE2b-256 checksum How to use checksums |
26e485b5e36f45e2086552abd5514f202bd3f81441df8eb77dd9684ab8571e33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for zhanla 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.