The official Go SDK for LogFlux. Send logs, metrics, traces, events, and audit entries directly to the LogFlux cloud with end-to-end encryption. 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, HTTP context propagation
- Scopes – Per-request context isolation
- Failsafe – SDK errors never crash your application
Framework Middleware
Separate modules for automatic request tracing:
- Gin –
go get github.com/logflux-io/logflux-go-sdk/v3/gin - Echo –
go get github.com/logflux-io/logflux-go-sdk/v3/echo - Fiber –
go get github.com/logflux-io/logflux-go-sdk/v3/fiber - Chi –
go get github.com/logflux-io/logflux-go-sdk/v3/chi - net/http – Built-in
TracingMiddleware(no extra module)
Logger Adapters
Drop-in hooks for popular Go logging libraries:
- logrus – Structured logger adapter
- zap – High-performance logger integration
- zerolog – Zero allocation JSON logger
- standard log – Built-in Go logger replacement
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 Go errors with automatic stack traces and breadcrumb trail.
| |
Error chain unwrapping: wrapped errors (fmt.Errorf("...: %w", err)) are captured up to 10 levels deep.
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.
| |
Framework Middleware
Auto-creates spans for every HTTP request with panic recovery.
| |
Configuration
Init Options
| Option | Type | Default | Description |
|---|---|---|---|
APIKey | string | required | API key (<region>-lf_<key>) |
Source | string | Node | Service name |
Environment | string | Attached to meta.environment | |
Release | string | Attached to meta.release | |
QueueSize | int | 1000 | In-memory buffer capacity |
BatchSize | int | 100 | Entries per HTTP request |
WorkerCount | int | 2 | Background goroutines |
MaxRetries | int | 3 | Max retry attempts |
SampleRate | float64 | 1.0 | 0.0-1.0, send probability |
MaxBreadcrumbs | int | 100 | Ring buffer size |
Failsafe | bool | true | Never crash host app |
EnableCompression | bool | true | Gzip before encryption |
Environment Variables
All options can be set via LOGFLUX_* environment variables:
| |
| Variable | Description |
|---|---|
LOGFLUX_API_KEY | API key (required) |
LOGFLUX_ENVIRONMENT | Deployment environment |
LOGFLUX_NODE | Host identifier |
LOGFLUX_QUEUE_SIZE | Queue capacity |
LOGFLUX_BATCH_SIZE | Entries per request |
LOGFLUX_WORKER_COUNT | Background workers |
LOGFLUX_ENABLE_COMPRESSION | Gzip compression |
LOGFLUX_DEBUG | SDK diagnostic logging |
LOGFLUX_KEY_PERSISTENCE | Enable/disable key persistence |
LOGFLUX_KEY_PERSISTENCE_PATH | Custom directory for session files |
LOGFLUX_KEY_ROTATION_DAYS | Rotate key after N days |
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 | *bool | true (nil = true) | Enable/disable key persistence |
KeyPersistencePath | string | ~/.logflux/sessions/ | Custom directory for session files |
KeyRotationInterval | time.Duration | 0 (never) | Rotate key after this duration |
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 nil to drop.
| |
Per-type hooks: BeforeSendLog, BeforeSendError, BeforeSendMetric, BeforeSendEvent, BeforeSendAudit, BeforeSendTrace, BeforeSendTelemetry.
Sampling
| |
Audit entries (type 5) are never sampled.
Serverless (Lambda)
| |
Security
- Zero-knowledge: All payloads encrypted client-side with AES-256-GCM
- RSA key exchange: AES keys negotiated via RSA-2048 OAEP handshake
- Key safety: AES keys zeroed from memory on
Close() - Bounded reads: All HTTP responses size-limited
- Failsafe: SDK errors never crash the host application
Requirements
- Go 1.23 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 Go logo and trademarks are the property of Google LLC. LogFlux is not affiliated with, endorsed by, or sponsored by Google LLC. The Go logo is used solely for identification purposes to indicate compatibility and integration capabilities.