Options
Example — production
Example — offline/test
Sampling
Static fraction:Flush & shutdown
flush() before returning a response in serverless/Edge functions. Call shutdown() on SIGTERM in long-lived servers.Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Every option you can pass to the TruLayer constructor.
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | TruLayer API key (tl_...) |
projectName | string | required | Human-readable project name |
projectId | string | — | Deprecated alias for projectName. Removed in 0.3.x. |
environment | string | "production" | Filter label |
endpoint | string | https://api.trulayer.ai | Override for self-hosted |
batchSize | number | 50 | Spans per flush |
flushInterval | number | 2000 | ms between flushes |
timeout | number | 5000 | HTTP timeout (ms) |
sampleRate | number | () => boolean | 1.0 | Fraction of traces to send |
redact | (value: unknown) => unknown | undefined | Redact inputs/outputs before ingest |
relayUrl | string | undefined | Server-side relay URL for browser builds |
debug | boolean | false | Log payloads locally |
import { TruLayer } from "@trulayer/sdk";
export const tl = new TruLayer({
apiKey: process.env.TRULAYER_API_KEY!,
projectName: "prod",
environment: "production",
batchSize: 50,
flushInterval: 2000,
redact: (value) => {
if (typeof value !== "string") return value;
return value
.replace(/\b[\w.+-]+@[\w.-]+\.\w{2,}\b/gi, "[email]")
.replace(/\b\d{13,16}\b/g, "[cc]");
},
});
const tl = new TruLayer({
apiKey: "tl_local",
projectName: "test",
debug: true,
});
const tl = new TruLayer({
apiKey: "tl_local",
projectName: "test",
endpoint: "http://localhost:4010",
});
new TruLayer({ ..., sampleRate: 0.1 }); // 10%
new TruLayer({
...,
sampleRate: () => Math.random() < 0.1,
});
await tl.flush(); // ship buffered traces, resolve when done
await tl.shutdown(); // flush + stop background work
flush() before returning a response in serverless/Edge functions. Call shutdown() on SIGTERM in long-lived servers.