Client options
All options are optional. With no arguments,Carbon reads CARBON_API_KEY from the environment and sends events to the production ingest API.
API key used to authenticate with the ingest API. Create one in the dashboard
under Settings → API Keys.
Base URL of the ingest API. Override only when pointing at a non-production
environment.
Number of buffered events that triggers an immediate flush.
Maximum serialized batch size in bytes (3.5 MiB). A batch flushes before it
would exceed this size. A single event larger than this limit throws at
capture time.
Maximum time in milliseconds an event waits in the buffer before a scheduled
flush sends it.
Custom transport for delivering event batches. Defaults to
HttpTransport.
See Transports.Buffering and flushing
Captured events go into an in-memory buffer. A flush happens when any of these is reached:- the buffer holds
bufferBatchSizeevents (50 by default) - the next event would push the serialized batch past
bufferMaxBatchBytes - an event has waited
bufferMaxTimeMs(5 seconds by default)
Flushing on shutdown
flushPendingEvents drains the buffer and resolves once every event is delivered. It rejects if delivery ultimately fails, so callers can decide how to handle loss at shutdown:
HTTP delivery and retries
The defaultHttpTransport posts batches to POST /v1/ingest-events with your API key as a bearer token.
- Requests time out after 15 seconds.
- Failed requests are retried up to 2 times, within a 30 second overall window.
- Responses with status 408, 409, 425, 429, or any 5xx are retried; other 4xx responses are not.
CarbonIngestError, which carries status (the HTTP status, when available) and retryable.
The ingest API deduplicates by event ID, so retried batches never create
duplicate events. See Delivery guarantees.
Transports
A transport implementssendBatch({ batch }). Three are built in:
| Transport | Use |
|---|---|
HttpTransport | Production delivery to the ingest API (default) |
MemoryTransport | Tests — batches accumulate on the in-memory batches array |
FileTransport | Local development — each batch is written as a JSON file |
FileTransport accepts a dirPath option and defaults to .tmp in the working directory: