Skip to main content

SpectraBuilder

Struct SpectraBuilder 

Source
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.

ModeCalls
Direct persistbackends + .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

Source

pub fn new() -> Self

New builder with async storage persist enabled and no backends configured yet.

Source

pub fn metrics_backend(self, backend: SharedMetricsBackend) -> Self

Register the metrics storage backend (required before Self::build).

Source

pub fn events_backend(self, backend: SharedEventBackend) -> Self

Register the events storage backend (required before Self::build).

Source

pub fn config(self, config: SpectraConfig) -> Self

Override emit policy and feature flags (defaults to SpectraConfig::from_env).

Source

pub fn persist(self, config: PersistConfig) -> Self

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.

Source

pub fn sink(self, sink: Arc<dyn SpectraSink>) -> Self

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.

Source

pub fn embedded(self) -> Self

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.

Source

pub fn persist_disabled(self) -> Self

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.

Source

pub fn build(self) -> Result<Spectra>

Install global config, router, and sink; returns a handle to the running runtime.

Trait Implementations§

Source§

impl Default for SpectraBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.