Darkhunt telemetry for Python

Python SDK for sending LLM traces, generations, and observations to
the Darkhunt platform for persistence and security data enrichment. Built on
OpenTelemetry primitives (TracerProvider, BatchSpanProcessor, OTLP/protobuf).
This is the Python analog of
@darkhunt-security/telemetry
(the TypeScript SDK) — same wire contract and routing semantics, adapted to
Python idioms (keyword arguments, with context managers).
DarkhuntTelemetry — the client. One per process.
Trace — a single user-facing interaction. Carries routing fields.
Generation — one LLM round-trip under a trace (model, messages, usage, cost).
Span — anything else (tool calls, retrievals, guardrails, sub-agents).
@guard — asks Darkhunt before a tool runs and before its output is used,
so dashboard rules can block it (Guard tool calls;
optionally through Microsoft AGT).
check_input / check_output — the same check for the request before the
agent sees it and the answer before the user does
(Guard the request and the answer).
Requires Python 3.9+.
Let your coding agent wire it up for you. In Claude Code, install the plugin:
/plugin marketplace add darkhunt-security/darkhunt
/plugin install darkhunt-telemetry-py@darkhunt
Then tell Claude "add Darkhunt telemetry to this service" and the darkhunt-telemetry-python-integration skill auto-invokes and does the steps below for you.
The same skill works in Amp and OpenCode:
- Amp: run
amp skill add darkhunt-security/darkhunt-telemetry-python/plugins/darkhunt-telemetry-py in your repo root. Add --global to use it in every project; run it again with --overwrite to update.
- OpenCode (1.17.12 or later): add
"skills": { "urls": ["https://raw.githubusercontent.com/darkhunt-security/darkhunt-telemetry-python/main/plugins/darkhunt-telemetry-py/skills/"] } to opencode.json, then restart OpenCode. New versions of the skill arrive on their own.
In either, start your prompt with "Use the darkhunt-telemetry-python-integration skill."
Get started
1. Install
pip install darkhunt-telemetry
# optional Temporal handoff interceptors:
pip install "darkhunt-telemetry[temporal]"
2. Create a singleton client
Construct one client for the lifetime of the process — it spins up a
TracerProvider + batch processor, so a per-request client leaks resources.
from darkhunt_telemetry import DarkhuntTelemetry
# api_key is read from DARKHUNT_API_KEY if omitted.
dh = DarkhuntTelemetry(
tenant_id="t1",
workspace_id="ws-1",
application_id="app-1",
service_name="my-service", # OTel service.name — one per process/agent
)
Several logical agents in one process? service_name is per client, so they would
share a node — name them per trace with
agent instead.
In-cluster service-to-service callers post to the permitAll /internal/... path
and need no key: