Chronicle

Configuration

Options and defaults for chronicle.New and the Forge extension.

chronicle.New options

chronicle.New accepts a variadic list of chronicle.Option functions:

c, err := chronicle.New(
    chronicle.WithStore(adapter),               // required
    chronicle.WithLogger(logger),               // optional
    chronicle.WithBatchSize(200),               // optional
    chronicle.WithFlushInterval(2*time.Second), // optional
    chronicle.WithCryptoErasure(true),          // optional
)
OptionTypeDefaultDescription
WithStore(s)chronicle.StorerRequired. Pass store.NewAdapter(yourBackend).
WithLogger(l)*slog.Loggerslog.Default()Structured logger for internal events.
WithBatchSize(n)int100Max events to accumulate before flushing to the store.
WithFlushInterval(d)time.Duration1sMax time between store flushes.
WithCryptoErasure(b)boolfalseEnable AES-256-GCM per-subject encryption for GDPR.

Config defaults

Config{
    BatchSize:              100,
    FlushInterval:          1 * time.Second,
    ShutdownTimeout:        30 * time.Second,
    EnableCryptoErasure:    false,
    RetentionCheckInterval: 24 * time.Hour,
}

ShutdownTimeout and RetentionCheckInterval are set via DefaultConfig() and are not currently exposed as WithXxx options on the root package — use the extension options below to control the retention interval.

Store adapter

chronicle.New accepts chronicle.Storer, not store.Store directly. You must always wrap your backend with store.NewAdapter:

mem := memory.New()
adapter := store.NewAdapter(mem)
c, err := chronicle.New(chronicle.WithStore(adapter))

See Architecture for the import-cycle reason behind this.

Forge extension options

The extension.New function accepts its own set of options:

ext := extension.New(
    extension.WithStore(pgStore),
    extension.WithBatchSize(200),
    extension.WithFlushInterval(2*time.Second),
    extension.WithCryptoErasure(true),
    extension.WithRetentionInterval(12*time.Hour),
    extension.WithArchiveSink(s3Sink),
    extension.WithLogger(logger),
    extension.WithDisableRoutes(false),
    extension.WithDisableMigrate(false),
)
OptionTypeDefaultDescription
WithStore(s)store.StoreRequired. Composite store backend.
WithBatchSize(n)int100Passed to chronicle.WithBatchSize.
WithFlushInterval(d)time.Duration1sPassed to chronicle.WithFlushInterval.
WithCryptoErasure(b)boolfalseEnable GDPR crypto-erasure.
WithRetentionInterval(d)time.Duration24hHow often retention policies are enforced. Set to 0 to disable.
WithArchiveSink(s)sink.SinknilSink used to write events before they are purged.
WithLogger(l)*slog.Loggerslog.Default()Logger for all Chronicle components.
WithDisableRoutes(b)boolfalseSkip HTTP route registration in the Forge router.
WithDisableMigrate(b)boolfalseSkip store.Migrate on Start.

The extension calls store.NewAdapter internally — pass the raw store.Store, not an already-adapted chronicle.Storer.

On this page