Signature
Returns
- A
BoundaryLogger<T>when eitherapiKey(orBOUNDARY_API_KEYenv var) orwriteis configured. nullotherwise — the dev-safe fallback. PassingnulltodefineContract({ logger })is a no-op.
BoundaryLoggerOptions
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | process.env.BOUNDARY_API_KEY | Boundary ingest credential |
environment | "production" | "staging" | "development" | — | Bucket events on the dashboard |
endpoint | string | "https://api.withboundary.com" | Override the ingest endpoint (self-host, proxy) |
model | string | — | Default LLM label stamped onto every event; overridable per-call |
capture | Partial<CapturePolicy> | see below | Which buckets of data to ship |
redact | RedactionOptions | — | fields / patterns / custom scrubbing |
batch.size | number | 20 | Flush when queue hits this length |
batch.intervalMs | number | 5000 | Periodic flush cadence (0 disables) |
batch.maxQueueSize | number | 1000 | Drop-oldest overflow threshold |
beforeSend | (event) => BoundaryLogEvent | null | — | Last-chance transform or drop |
write | (events) => void | Promise<void> | — | Custom sink; fires alongside apiKey |
flushOnExit | boolean | true | Attach runtime lifecycle drain hooks |
onError | (err) => void | one-time console.warn | Permanent drop callback |
fetch | typeof fetch | globalThis.fetch | Injected fetch (tests, polyfills) |
Default capture policy
BoundaryLogger<T>
The returned object:
- Implements every
ContractLogger<T>hook (assign it directly todefineContract({ logger })). flush(timeoutMs?)— drain the queue; logger stays active.shutdown(timeoutMs?)— drain, stop the timer, disable further sends. Idempotent.
Minimal example
Full example
Related types
BoundaryLogEvent— the wire formatCapturePolicy— the five bucketsRedactionOptions—fields/patterns/custom- Full SDK types: Types reference
See also
SDK Quickstart
Install and wire the logger
Shutdown
flush + shutdown + signal handling