Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.trulayer.ai/llms.txt

Use this file to discover all available pages before exploring further.

Options

OptionTypeDefaultDescription
apiKeystringrequiredTruLayer API key (tl_...)
projectNamestringrequiredHuman-readable project name
projectIdstringDeprecated alias for projectName. Removed in 0.3.x.
environmentstring"production"Filter label
endpointstringhttps://api.trulayer.aiOverride for self-hosted
batchSizenumber50Spans per flush
flushIntervalnumber2000ms between flushes
timeoutnumber5000HTTP timeout (ms)
sampleRatenumber | () => boolean1.0Fraction of traces to send
redact(value: unknown) => unknownundefinedRedact inputs/outputs before ingest
relayUrlstringundefinedServer-side relay URL for browser builds
debugbooleanfalseLog payloads locally

Example — production

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]");
  },
});

Example — offline/test

const tl = new TruLayer({
  apiKey: "tl_local",
  projectName: "test",
  debug: true,
});
Or mock server:
const tl = new TruLayer({
  apiKey: "tl_local",
  projectName: "test",
  endpoint: "http://localhost:4010",
});

Sampling

Static fraction:
new TruLayer({ ..., sampleRate: 0.1 }); // 10%
Dynamic (evaluated per trace):
new TruLayer({
  ...,
  sampleRate: () => Math.random() < 0.1,
});
Sampling is applied at trace creation — a sampled trace always includes every one of its spans.

Flush & shutdown

await tl.flush();     // ship buffered traces, resolve when done
await tl.shutdown();  // flush + stop background work
Call flush() before returning a response in serverless/Edge functions. Call shutdown() on SIGTERM in long-lived servers.