pub struct SpectraBuilder { /* private fields */ }Expand description
Configures and installs Spectra with explicit storage adapter injection.
Both metrics and events backends are required. Storage persistence is enabled by default;
an optional SpectraSink can receive the same emits before they are queued for persistence.
| Mode | Calls |
|---|---|
| Direct persist | backends + .build() |
| Dual-path | .sink(transport).build() |
| Publisher (distributed) | .sink(transport).persist_disabled().build() |
Publisher processes publish through the sink; consumers subscribe on the host bus and write
storage. See the spectra crate Getting started → Mode 2.
§Examples
use std::sync::Arc;
use spectra_backend_mem::{MemEventsBackend, MemMetricsBackend};
use spectra_core::{RecordingSink, SpectraSink};
use spectra_runtime::Spectra;
let transport = Arc::new(RecordingSink::new());
let spectra = Spectra::builder()
.metrics_backend(Arc::new(MemMetricsBackend::new()))
.events_backend(Arc::new(MemEventsBackend::new()))
.sink(Arc::clone(&transport) as Arc<dyn SpectraSink>)
.embedded()
.build()?;Implementations§
Source§impl SpectraBuilder
impl SpectraBuilder
Sourcepub fn new() -> SpectraBuilder
pub fn new() -> SpectraBuilder
New builder with async storage persist enabled and no backends configured yet.
Sourcepub fn metrics_backend(
self,
backend: Arc<dyn MetricsStorageBackend>,
) -> SpectraBuilder
pub fn metrics_backend( self, backend: Arc<dyn MetricsStorageBackend>, ) -> SpectraBuilder
Register the metrics storage backend (required before Self::build).
Sourcepub fn events_backend(
self,
backend: Arc<dyn EventStorageBackend>,
) -> SpectraBuilder
pub fn events_backend( self, backend: Arc<dyn EventStorageBackend>, ) -> SpectraBuilder
Register the events storage backend (required before Self::build).
Sourcepub fn config(self, config: SpectraConfig) -> SpectraBuilder
pub fn config(self, config: SpectraConfig) -> SpectraBuilder
Override emit policy and feature flags (defaults to SpectraConfig::from_env).
Sourcepub fn persist(self, config: PersistConfig) -> SpectraBuilder
pub fn persist(self, config: PersistConfig) -> SpectraBuilder
Configure the L2 persist queue and batch settings (ignored when persist is disabled).
Defaults: queue_max=8192, batch_max=32, batch_wait=5ms, batch_enabled=true.
Raise batch_max for high-throughput DW ingest.
Sourcepub fn sink(self, sink: Arc<dyn SpectraSink>) -> SpectraBuilder
pub fn sink(self, sink: Arc<dyn SpectraSink>) -> SpectraBuilder
Optional transport or telemetry sink (invoked before async storage persist when enabled).
Use this for the publisher side of distributed ingest: your SpectraSink
publishes emits onto a bus (for example Photon). Combine with
Self::persist_disabled when the publisher must not write storage.
Without persist_disabled, the runtime installs a persist wrapper that calls your
sink first, then queues async storage writes (dual-path).
Implement SpectraSink in your application or use
RecordingSink in tests. See the spectra crate
Getting started → Mode 2.
Sourcepub fn embedded(self) -> SpectraBuilder
pub fn embedded(self) -> SpectraBuilder
Mark in-process embedded topology (in-host storage backends).
This sets a topology flag retained on the returned Spectra handle
(Spectra::is_embedded). It does not select or validate backends — you still
inject storage via Self::metrics_backend / Self::events_backend.
Sourcepub fn persist_disabled(self) -> SpectraBuilder
pub fn persist_disabled(self) -> SpectraBuilder
Disable async storage persist (only the transport sink receives emits).
Publisher / distributed mode. Pair with Self::sink: writers publish through the
sink; separate consumer processes subscribe and persist. Requires a sink — building
with persist disabled and no sink returns an error.
Sourcepub fn telemetry_ndjson(
self,
dir: impl AsRef<Path>,
) -> Result<SpectraBuilder, Error>
pub fn telemetry_ndjson( self, dir: impl AsRef<Path>, ) -> Result<SpectraBuilder, Error>
Attach off-thread NDJSON + optional console mirror telemetry (telemetry-console feature).
Writes {dir}/metrics.ndjson and {dir}/events.ndjson.