Badger Storage#
Jaeger's Badger backend is an embedded key-value store (backed by dgraph-io/badger v4) used as a self-contained, single-node storage option for spans, sampling data, and dependency information. Because it runs in-process, no separate storage server is required, making it suitable for all-in-one deployments and development environments.
The implementation lives under internal/storage/v1/badger/ and is split into three sub-packages:
| Sub-package | Purpose |
|---|---|
spanstore/ | Writes and reads trace spans |
samplingstore/ | Stores adaptive sampling throughput & probabilities |
dependencystore/ | Computes service dependencies from span data |
The Factory in factory.go is the entry point. It opens the Badger database, starts background maintenance goroutines, and implements the storage.SamplingStoreFactory interface .
Configuration#
Configuration is defined in config.go. Key defaults:
| Option | Default | Notes |
|---|---|---|
Ephemeral | true | Data stored in a temp directory; lost on restart |
SyncWrites | false | Performance over durability |
TTL.Spans | 72 hours | How long span data is retained |
MaintenanceInterval | 5 min | Frequency of ValueLogGC runs |
MetricsUpdateInterval | 10 sec | Frequency of metrics collection |
In ephemeral mode SyncWrites is forced to false . In persistent mode, SyncWrites follows the configured value and ReadOnly is also available .
A background maintenance() goroutine periodically calls store.RunValueLogGC(0.5) to reclaim disk space from the value log .
Sampling Store Write Paths โ Silently Discarded Errors#
The SamplingStore in samplingstore/storage.go implements two write methods, both of which contain a latent bug: the error returned by s.store.Update(...) is captured into err but then the function unconditionally returns nil, silently swallowing any write failure.
InsertThroughput :
err = s.store.Update(func(txn *badger.Txn) error { ... })
return nil // โ err is never checked or returned
InsertProbabilitiesAndQPS :
err = s.store.Update(func(txn *badger.Txn) error { ... })
return nil // โ err is never checked or returned
In both cases, serialization errors from createThroughputEntry / createProbabilitiesEntry are correctly returned . Only failures from the Badger transaction commit itself are lost.
The practical impact: adaptive sampling data writes to Badger can fail silently (e.g., due to disk-full conditions or a corrupt database), with no error logged and no metric incremented. Callers such as the adaptive sampling manager will assume the write succeeded.
Fix: Both methods should return the error from s.store.Update(...) instead of nil:
// InsertThroughput โ line 58
return err // instead of: return nil
// InsertProbabilitiesAndQPS โ line 124
return err // instead of: return nil
Key Encoding#
Sampling records use single-byte key prefixes to separate namespaces :
| Prefix | Data |
|---|---|
0x08 | Throughput records |
0x09 | Probabilities + QPS records |
Keys are 16 bytes: 1-byte prefix + 8-byte big-endian epoch-microseconds timestamp + 7 padding bytes. Values are JSON-marshalled structs .
Read paths (GetThroughput, GetLatestProbabilities) use Badger prefix-seek iterators and correctly propagate errors .
Key Source Files#
| File | Description |
|---|---|
internal/storage/v1/badger/factory.go | Factory, DB open/close, background maintenance |
internal/storage/v1/badger/config.go | Configuration struct and defaults |
internal/storage/v1/badger/samplingstore/storage.go | Sampling store โ throughput & probabilities read/write |