Skip to content

Observability

Current State

Structured Logging

  • setup_logging() from loryth-fastapi configures JSON-formatted structured logs
  • RequestIdMiddleware adds a unique request_id to each request context
  • Request/response logging middleware logs method, URL, and status code for every request

Health Check

  • GET /health returns {"status": "healthy", "service": "loryth-ai"}
  • Used by Docker Compose for container dependency ordering and health monitoring

Planned Metrics (Prometheus)

Run Metrics

Metric Type Labels Description
ai_run_duration_seconds Histogram space_id, status Total run wall time
ai_run_model_calls_total Counter space_id, model_id Model calls per run
ai_run_tool_calls_total Counter space_id, tool_id Tool calls per run
ai_run_token_usage Counter space_id, model_id, type Token consumption (prompt/completion)
ai_run_status_total Counter space_id, status Run completions by final status

Tool Registry Metrics

Metric Type Labels Description
ai_tool_catalog_revision_current Gauge — Current catalog revision number
ai_tool_refresh_duration_seconds Histogram source_id Time to refresh a tool source
ai_tool_refresh_errors_total Counter source_id Failed refresh attempts

Embedding Metrics

Metric Type Labels Description
ai_embedding_generation_latency_seconds Histogram model_ref Time to generate embeddings
ai_embedding_search_latency_seconds Histogram space_id Time to execute similarity search
ai_embedding_vectors_total Gauge space_id Total stored vectors per space

Ingestion Metrics

Metric Type Labels Description
ai_ingestion_fetch_duration_seconds Histogram document_type URL fetch + extraction time
ai_ingestion_bytes_total Counter space_id Total bytes ingested

Planned Tracing (OpenTelemetry)

Span Hierarchy

request (from RequestIdMiddleware)
├── run.orchestrate
│   ├── run.model_call
│   │   └── provider.complete / provider.stream
│   └── run.tool_call
│       └── tool.execute
├── ingestion.fetch
│   ├── ingestion.download
│   └── ingestion.extract
├── embedding.generate
│   └── provider.embed
└── embedding.search
    └── pgvector.query

Key Span Attributes

Attribute Description
ai.space_id Space UUID for the operation
ai.conversation_id Conversation UUID
ai.run_id Run UUID
ai.model_id Model identifier from binding
ai.tool_id Tool identifier for tool calls
ai.token_count.prompt Prompt tokens consumed
ai.token_count.completion Completion tokens consumed

Logging Conventions

  • logger.debug() — detailed flow information (embedding generation, tool resolution)
  • logger.info() — significant operations (run started, run completed, catalog revision bumped)
  • logger.warning() — recoverable issues (tool source sync failed, safety limit approached)
  • logger.error() — failures at system boundaries with exc_info=True