Skip to content

ports

Ports layer - Abstract interfaces for hexagonal architecture

This module defines the ports (interfaces) that the core domain uses to interact with the external world. Adapters implement these ports.

Port for transporting log entries to external systems

This is the interface that different adapters implement:

  • WasmStdoutAdapter (writes to WASM stdout)
  • HttpTransportAdapter (sends via HTTP)
  • BatchingTransportAdapter (batches entries)

Required / Provided Methods

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

Transport a single log entry

fn transport_batch(&self, entries: &[LogEntry]) -> ObservabilityResult<()>

Transport multiple log entries (for batching)

Port for formatting log entries

Different formatters can be plugged in:

  • JsonFormatter (structured JSON output)
  • PlainTextFormatter (human-readable text)
  • CompactFormatter (single-line JSON)

Required / Provided Methods

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

Format a log entry into a string

Port for standard logging integration

This port allows us to hook into standard Rust logging infrastructure:

  • log::Log implementation
  • tracing::Subscriber implementation

Required / Provided Methods

fn initialize(&self) -> ObservabilityResult<()>

Initialize the logging system (called once during agent startup)

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

Process a log entry from standard logging macros

fn enabled(&self, level: &LogLevel) -> bool

Check if logging is enabled for this level

Port for accessing context information

This allows the logging system to enrich entries with context:

  • Agent ID, request ID, trace ID
  • User-defined context fields
  • Thread/task local context

Required / Provided Methods

fn get_context(&self) -> HashMap<String, serde_json::Value>

Get current context fields

fn add_context(&self, key: String, value: serde_json::Value)

Add a context field

fn remove_context(&self, key: &str)

Remove a context field

fn clear_context(&self)

Clear all context

Port for batching log entries

This allows different batching strategies:

  • TimeBasedBatcher (flush every N seconds)
  • SizeBasedBatcher (flush when buffer reaches N entries)
  • HybridBatcher (combination of time and size)

Required / Provided Methods

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

Add an entry to the batch

fn flush_batch(&self) -> ObservabilityResult<()>

Force flush the current batch

fn batch_size(&self) -> usize

Get current batch size

Port for metrics collection (basic interface for correlation).

Required / Provided Methods

fn emit_counter_simple(&self, name: &str, value: f64) -> ObservabilityResult<()>

Emit a simple counter metric

fn emit_histogram_simple(&self, name: &str, value: f64) -> ObservabilityResult<()>

Emit a simple histogram/timing metric

fn emit_gauge_simple(&self, name: &str, value: f64) -> ObservabilityResult<()>

Emit a simple gauge metric

fn is_enabled(&self) -> bool

Check if metrics collection is enabled

fn emit_metrics_batch(&self, entries: &[MetricsEntry]) -> ObservabilityResult<()>

Batch emit multiple metrics (optional, has default implementation)