The official JavaScript/TypeScript SDK for LogFlux. Send logs, metrics, traces, events, and audit entries directly to the LogFlux cloud with end-to-end encryption from Node.js applications. The server never sees your plaintext data.
GitHub Repository ยท Release Notes
Key Features
- End-to-end encryption – AES-256-GCM with RSA key exchange
- 7 entry types – Log, Metric, Trace, Event, Audit, Telemetry, TelemetryManaged
- Multipart binary transport – 33% less overhead than JSON + base64
- Async by default – Non-blocking queue with background workers
- Breadcrumbs – Automatic trail of recent events attached to error captures
- Distributed tracing – Spans, child spans, trace header propagation
- Scopes – Per-request context isolation
- Full TypeScript – Complete type definitions included
- Failsafe – SDK errors never crash your application
- Zero runtime dependencies – Node.js 18+ built-ins only
Installation
| |
Quick Start
| |
Entry Types
Log (Type 1)
Standard application logs with 8 severity levels.
| |
Metric (Type 2)
Counters, gauges, and distributions.
| |
Event (Type 4)
Discrete application events.
| |
Audit (Type 5)
Immutable audit trail with Object Lock storage (365-day retention).
| |
Trace (Type 3)
Distributed tracing with span helpers.
| |
Telemetry (Types 6 and 7)
Device and sensor data. Type 6 is end-to-end encrypted, type 7 is server-side encrypted.
Error Capture
Capture JavaScript errors with automatic stack traces and breadcrumb trail.
| |
Breadcrumbs
Breadcrumbs record a trail of events leading up to an error. They are automatically added for log and event calls, and attached to captureError.
| |
Scopes
Per-request context isolation. Attributes set on a scope are merged into every entry.
| |
Trace Context Propagation
Propagate trace context across services via HTTP headers.
| |
Express Middleware
| |
Configuration
Options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | API key (<region>-lf_<key>) |
source | string | Service name | |
environment | string | Attached to meta.environment | |
release | string | Attached to meta.release | |
queueSize | number | 1000 | In-memory buffer capacity |
batchSize | number | 100 | Entries per HTTP request |
flushInterval | number | 5000 | Auto-flush interval (ms) |
workerCount | number | 2 | Background workers |
maxRetries | number | 3 | Max retry attempts |
sampleRate | number | 1.0 | 0.0-1.0, send probability |
maxBreadcrumbs | number | 100 | Ring buffer size |
failsafe | boolean | true | Never crash host app |
enableCompression | boolean | true | Gzip before encryption |
Environment Variables
| |
Reads LOGFLUX_API_KEY, LOGFLUX_ENVIRONMENT, LOGFLUX_NODE, LOGFLUX_QUEUE_SIZE, LOGFLUX_BATCH_SIZE, LOGFLUX_KEY_PERSISTENCE, LOGFLUX_KEY_PERSISTENCE_PATH, LOGFLUX_KEY_ROTATION_DAYS, etc.
Key Persistence
The SDK persists AES encryption keys to disk by default, reusing them across restarts instead of performing a new handshake each time. This reduces key proliferation in the database and speeds up initialization.
| Option | Type | Default | Description |
|---|---|---|---|
keyPersistence | boolean | true | Enable/disable key persistence |
keyPersistencePath | string | ~/.logflux/sessions/ | Custom directory for session files |
keyRotationIntervalMs | number | 0 (never) | Rotate key after this many milliseconds |
Session files are stored at ~/.logflux/sessions/<hash>.json with 0600 permissions. If the cached key is rejected by the server (401/403), the SDK automatically re-handshakes and saves the new key.
| |
BeforeSend Hooks
Filter or modify entries before they are sent. Return null to drop.
| |
Per-type hooks: beforeSendLog, beforeSendError, beforeSendMetric, beforeSendEvent, beforeSendAudit, beforeSendTrace, beforeSendTelemetry.
Sampling
| |
Audit entries (type 5) are never sampled.
Security
- Zero-knowledge: All payloads encrypted client-side with AES-256-GCM
- RSA key exchange: AES keys negotiated via RSA-2048 OAEP handshake
- Key zeroing: AES keys cleared from memory on
close() - Bounded reads: All HTTP responses size-limited
- Failsafe: SDK errors never crash the host application
Requirements
- Node.js 18 or later
- LogFlux account with API key
License
Elastic License 2.0 (ELv2) – free for all use except offering as a hosted or managed service to third parties.
Support
- Documentation: GitHub Repository
- Issues: GitHub Issues
Disclaimer
The JavaScript and Node.js logos and trademarks are the property of Oracle Corporation and the OpenJS Foundation respectively. LogFlux is not affiliated with, endorsed by, or sponsored by Oracle Corporation or the OpenJS Foundation. The logos are used solely for identification purposes to indicate compatibility and integration capabilities.