| name | swarm-observability |
| description | Tracing, metrics, derive macros, and error context. Use when adding observability or improving developer experience. |
Swarm: Observability
Workflow
- Add tracing/metrics dependencies to
Cargo.toml
- Instrument async functions with
#[instrument]
- Add metric collection points (counters, histograms, gauges)
- Create proc-macro crate if needed (chaotic_semantic_memory_derive)
- Enhance error types with
#[source] and context
- Test with
tracing-subscriber fmt or json output
Tracing Setup
use tracing::{instrument, info, debug};
#[instrument(skip(self))]
pub async fn inject_concept(&self, id: String, vector: HVec10240) -> Result<()> {
debug!(concept_id = %id, "injecting concept");
info!(concept_id = %id, "concept injected");
Ok(())
}
Metrics Collection
use metrics::{counter, histogram, gauge};
pub async fn probe(&self, query: HVec10240, top_k: usize) -> Result<Vec<(String, f32)>> {
let start = Instant::now();
counter!("probe_requests_total").increment(1);
let results =
histogram!("probe_latency_ms").record(start.elapsed().as_millis() as f64);
gauge!("concept_count").set(self.singularity.len() as f64);
Ok(results)
}
Derive Macros (DEPRECATED)
Derive macros were removed after discovery of zero usage. Use ConceptBuilder directly:
let concept = ConceptBuilder::new("id")
.with_vector(HVec10240::random())
.build()?;
Error Context
#[derive(Error, Debug)]
pub enum MemoryError {
#[error("Concept '{concept_id}' not found")]
ConceptNotFound { concept_id: String },
#[error("Database error: {message}")]
Database {
message: String,
#[source]
source: Option<Box<dyn Error>>,
},
}
LOC Constraint
All files must remain ≤ 500 lines. Proc-macro crate counts separately.