Skip to content

domain

Domain layer for observability core - Pure business logic

This module contains ONLY pure business logic with no external dependencies. No WASM, HTTP, or framework-specific code should be here.

type TraceContext = TraceCorrelation;

Backwards-compatible alias.

Core processor interface - transforms log entries

Required / Provided Methods

fn process(&self, entry: LogEntry) -> ObservabilityResult<LogEntry>

Process and transform a log entry

fn name(&self) -> &''static str

Get processor name for debugging

Core log entry - pure data structure

Fields

FieldTypeDescription
timestampchrono::DateTime&lt;chrono::Utc&gt;
levelLogLevel
messageString
fieldsserde_json::Value
trace_contextOption&lt;TraceContext&gt;
sourceLogSource

Source of the log entry

Fields

FieldTypeDescription
moduleOption&lt;String&gt;
fileOption&lt;String&gt;
lineOption&lt;u32&gt;
targetOption&lt;String&gt;

Serializable trace identifiers for log/metric correlation.

Distinct from [crate::context::TraceContext] which is the runtime tracing context with sampling decisions and W3C conversion methods.

Fields

FieldTypeDescription
trace_idString
span_idString
parent_span_idOption&lt;String&gt;

Processor chain pattern (inspired by structlog)

Methods

fn new() -> Self

Create a new empty processor chain

fn add_processor(self, processor: Box<dyn LogProcessor>) -> Self

Add a processor to the chain

fn process(&self, entry: LogEntry) -> ObservabilityResult<LogEntry>

Process an entry through the entire chain

fn len(&self) -> usize

Get number of processors in the chain

fn is_empty(&self) -> bool

Check if chain is empty

Processor that adds timestamps

Processor that enriches with context

Methods

fn new() -> Self
fn with_field<impl Into<String>, impl Into<serde_json::Value>>(self, key: impl Into, value: impl Into) -> Self

Processor that structures fields

Filter processor that filters out logs below certain level

Methods

fn new(min_level: LogLevel) -> Self

Processor that extracts structured fields from log::kv

This processor supports the log::info!(“msg”; “key” => value) syntax by extracting key-value pairs from log::Record and adding them to LogEntry fields

Methods

fn new() -> Self
fn extract_kv_from_record(record: &log::Record<'_>) -> serde_json::Value

Extract key-value pairs from log::Record

This function would be called by StandardLogAdapter when processing log::Record but we’ll implement the interface here for the processor chain

Enhanced processor that combines context enrichment with kv extraction

Methods

fn new() -> Self
fn with_field<impl Into<String>, impl Into<serde_json::Value>>(self, key: impl Into, value: impl Into) -> Self
fn with_kv_extraction(self, extract_kv: bool) -> Self

Basic metric entry for correlation with logs

Fields

FieldTypeDescription
nameString
valuef64
metric_typeBasicMetricType
timestampchrono::DateTime&lt;chrono::Utc&gt;
trace_contextOption&lt;TraceContext&gt;
sourceMetricsSource

Methods

fn new<impl Into<String>>(name: impl Into, value: f64, metric_type: BasicMetricType) -> Self

Create a new metrics entry

fn with_trace_context(self, trace_context: TraceContext) -> Self

Add trace context for correlation

fn with_source(self, module: Option<String>, component: Option<String>, operation: Option<String>) -> Self

Add source information

fn to_json(&self) -> serde_json::Value

Convert to JSON for transport

Source of the metric

Fields

FieldTypeDescription
moduleOption&lt;String&gt;
componentOption&lt;String&gt;
operationOption&lt;String&gt;

Simple metric types supported by core

Variants

VariantDescription
CounterCounter metric (monotonically increasing)
HistogramHistogram/timing metric (distribution of values)
GaugeGauge metric (current value)
fn build_default_processor_chain() -> ProcessorChain

Build a default processor chain with common processors

fn build_enhanced_processor_chain() -> ProcessorChain

Build an enhanced processor chain with additional features

fn create_log_entry<impl Into<String>>(level: LogLevel, message: impl Into, fields: serde_json::Value) -> LogEntry

Create a log entry from basic components

fn create_counter_metric<impl Into<String>>(name: impl Into, value: f64) -> MetricsEntry

Convenience function to create a counter metric

fn create_histogram_metric<impl Into<String>>(name: impl Into, value: f64) -> MetricsEntry

Convenience function to create a histogram metric

fn create_gauge_metric<impl Into<String>>(name: impl Into, value: f64) -> MetricsEntry

Convenience function to create a gauge metric