ZokLens Python SDK — LLM & Agent Observability via OpenTelemetry
Project description
ZokLens Python SDK
LLM & Agent Observability via OpenTelemetry. Track every LLM call, agent step, and chain interaction with 3 lines of code.
Quick Start
pip install zoklens
import zoklens
# 1. Initialize
zoklens.init(
api_key="zok_xxx", # from ZokLens Console → API Keys
endpoint="https://api.zoklens.com", # or your self-hosted URL
project="my-agent",
)
# 2. Auto-instrument LLM SDKs (one line)
zoklens.instrument(providers=["openai", "anthropic"])
# 3. Your existing code — zero changes needed
import openai
client = openai.OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}],
)
# ✅ Trace automatically captured: model, tokens, cost, latency
Features
Auto-Instrumentation
Automatically patches LLM SDKs to capture traces — zero code changes to your LLM calls.
zoklens.instrument(providers=["openai"]) # OpenAI SDK
zoklens.instrument(providers=["anthropic"]) # Anthropic SDK
zoklens.instrument(providers=["deepseek"]) # DeepSeek (OpenAI-compatible)
Captured attributes: llm.model, llm.provider, llm.tokens.input, llm.tokens.output, llm.cost.usd, llm.duration_ms
Custom Spans
Track any operation in your agent pipeline:
with zoklens.span("retrieval", metadata={"query": "cost trends", "top_k": 5}):
docs = retriever.search(query)
with zoklens.span("generation", metadata={"model": "gpt-4o"}):
response = llm.generate(prompt)
Session Tracking
Group related spans under a session with user context:
with zoklens.session(user_id="u123", session_id="s456"):
# All spans inside automatically get user_id and session_id
with zoklens.span("step-1"):
...
with zoklens.span("step-2"):
...
Shutdown
Flush pending spans before exit:
zoklens.shutdown()
How It Works
Your App ZokLens
┌─────────────────────┐ ┌──────────────┐
│ import zoklens │ │ │
│ zoklens.init(...) │ OTLP │ Trace Store │
│ zoklens.instrument()│────────→│ Cost Calc │
│ │ HTTP │ AI Copilot │
│ llm.chat(...) │ │ │
└─────────────────────┘ └──────────────┘
The SDK uses OpenTelemetry under the hood:
- Configures a
TracerProviderwith a customZokLensSpanExporter - Exports traces via OTLP/HTTP to
POST /api/v1/otel/v1/traces - Authenticates with
X-API-Keyheader for tenant isolation
SDK vs Proxy
| Proxy (Sprint 10) | SDK (Sprint 12) | |
|---|---|---|
| Setup | Change BASE_URL |
import zoklens |
| Code changes | Zero | 3 lines |
| Trace depth | HTTP layer | Span/chain level |
| Custom attributes | ❌ | ✅ user_id, session, metadata |
| Agent internals | ❌ | ✅ step/tool/chain tracking |
| Best for | Quick start | Agent developers |
Both can be used simultaneously.
Requirements
- Python ≥ 3.9
- OpenTelemetry SDK (installed automatically)
License
Apache-2.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zoklens-2026.3.0.tar.gz.
File metadata
- Download URL: zoklens-2026.3.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22d03d65f1ec513ebe68eb01fe68f134240481fde107c5e7290b14ab48409f8c
|
|
| MD5 |
cd895e0c00e1d9e8745074350af06216
|
|
| BLAKE2b-256 |
7a1dbac9fa6ef7b4d86bbfc88d9ea727ff54d0e48caaa8d271dbf5376076e62a
|
File details
Details for the file zoklens-2026.3.0-py3-none-any.whl.
File metadata
- Download URL: zoklens-2026.3.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecfb46dbbc9f75ff94d5e14ec80bf490c1a7e7bf7952dd8ff5ca9f838ee9b0a2
|
|
| MD5 |
1f149603ca9b71a4289928eee23a4819
|
|
| BLAKE2b-256 |
fc29c873a83e45f844dae17ec285f68c3ea994aba350a0ac56a6c5ad574ed0e6
|