Skip to main content

Observability

Constellations components can be wrapped with OpenTelemetry tracing, log4cats logging, and metrics.

ToolDispatcher​

ToolDispatcher.observed returns F[ToolDispatcher[F]]. Required givens: Tracer, LoggerFactory, Meter, MonadCancelThrow.

import cats.effect.kernel.MonadCancelThrow
import org.typelevel.log4cats.LoggerFactory
import org.typelevel.otel4s.metrics.Meter
import org.typelevel.otel4s.trace.Tracer
import io.github.serhiip.constellations.ToolDispatcher

def withObservability[F[_]: Tracer: LoggerFactory: Meter: MonadCancelThrow](
raw: ToolDispatcher[F]
): F[ToolDispatcher[F]] =
ToolDispatcher.observed(raw)
KindName
Spanconstellations-tool-dispatcher-dispatch
Spanconstellations-tool-dispatcher-dispatch-all
Spanconstellations-tool-dispatcher-get-function-declarations
Counterconstellations/tool_dispatcher_dispatch_success_count
Counterconstellations/tool_dispatcher_dispatch_error_count
Counterconstellations/tool_dispatcher_dispatch_all_success_count
Counterconstellations/tool_dispatcher_dispatch_all_error_count

Logs are enriched with trace/span IDs when a span is active.

Stateful agent-error retries​

Stateful.apply (observed) adds agent-error attributes to the current span and logs. Use Stateful.pure in tests.

Attributes on the active span for a failed batch: retries_left, error (comma-separated kinds: argument-decoding-failed / unknown-function), agent_error_count. Retry attempts are logged at warn; exhaustion at error.

Similarity metrics​

Similarity.observed (in core) records success/error counters and a latency histogram for findClosest:

  • constellations/similarity_find_closest_success_count
  • constellations/similarity_find_closest_error_count
  • constellations/similarity_find_closest_duration (unit s)

Example: Similarity.observed(RagEngine.Similarity.simple(...)) for metered RAG search.

Logging​

Use log4cats StructuredLogger / LoggerFactory. Observed wrappers attach trace context to loggers automatically.