Darkhunt telemetry for JS/TS

TypeScript SDK for sending LLM traces, generations, and observations to the Darkhunt platform for persistence and security data enrichment. Built on OpenTelemetry primitives. The SDK sends values as you give them; masking of PII happens server-side in the Darkhunt platform on ingest.
It can also enforce: guard() asks Darkhunt before a tool runs and before its output is used, so dashboard rules can block it — optionally through Microsoft AGT. checkInput / checkOutput do the same for the request before the agent sees it and the answer before the user does.
🤖 Skip the manual wiring — if you use Claude Code, install the Darkhunt plugin once:
/plugin marketplace add darkhunt-security/darkhunt
/plugin install darkhunt-telemetry@darkhunt
Then tell Claude "add Darkhunt telemetry to this service" and the darkhunt-telemetry-integration skill auto-invokes and does steps 1–5 below for you.
The same skill works in Amp and OpenCode:
- Amp: run
amp skill add darkhunt-security/darkhunt-telemetry-ts/plugins/darkhunt-telemetry 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-ts/main/plugins/darkhunt-telemetry/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-integration skill."
Get started
Prerequisite — set up your project in Darkhunt. Open the Get started page in the Darkhunt dashboard to copy your tenantId, workspaceId, and applicationId, then create an API key (dh-...) by following Creating an API key. Set them in the environment as DARKHUNT_TENANT_ID, DARKHUNT_WORKSPACE_ID, DARKHUNT_APPLICATION_ID, and DARKHUNT_API_KEY — the SDK reads them automatically.
1. Install
npm install @darkhunt-security/telemetry
Requires Node ^18.19.0 || >=20.6.0 and an ESM project ("type": "module" in package.json). For CommonJS consumers, use dynamic import() or migrate to ESM.
2. Create a singleton module
The SDK holds a global TracerProvider, so instantiate it exactly once per process. Put it in a dedicated module that the rest of your app imports.
// src/telemetry.ts
import { DarkhuntTelemetry } from '@darkhunt-security/telemetry';
// Reads DARKHUNT_API_KEY, DARKHUNT_TENANT_ID, DARKHUNT_WORKSPACE_ID,
// and DARKHUNT_APPLICATION_ID from the environment.
export const dh = new DarkhuntTelemetry();
Pass options explicitly if you need to override any of these (e.g. multi-tenant routing where tenantId varies per request — see Common patterns).
Import dh wherever you need to open a trace. Don't new DarkhuntTelemetry() again — a second provider will silently shadow the first.
3. Wrap your LLM calls
The SDK has two concepts you'll use:
trace — one user-facing operation (a request, a chat session, a job). Open it at the entry point.
generation — one LLM call inside a trace. Records model, input, output, token usage, cost.
// src/handlers/chat.ts
import { dh } from '../telemetry.js';