converge.observability¶
Logging, tracing, metrics, and replay. Logging: JsonFormatter for structured logs, configure_logging, get_logger, log_struct. Tracing: trace context manager and get_current_trace_id for span tracking; optional SpanExporter (register via register_span_exporter) is invoked when a trace() context exits with (span, duration_sec). MetricsCollector: counters and gauges with snapshot(); format_prometheus() returns Prometheus text exposition format for scrape endpoints. ReplayLog records directional message events (record_inbound, record_outbound; record_message compatibility alias), and ReplayRunner replays filtered events into inbox/callback targets in deterministic timestamp order. CoordinationMetrics provides stable task/pool metric helpers.
Operations: AgentRuntime supports optional health_check and ready_check callables (is_healthy(), is_ready()), and RuntimeOpsServer exposes /health, /ready, and /metrics over stdlib HTTP.
- class converge.observability.logging.JsonFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]¶
Bases:
FormatterFormatter that outputs JSON strings for structured logging.
- format(record: LogRecord) str[source]¶
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- converge.observability.logging.configure_logging(level: int = 20, *, json_format: bool = False) None[source]¶
Configure the root logger with stream handlers and formatting.
Removes existing handlers to avoid duplication.
- converge.observability.logging.get_logger(name: str) Logger[source]¶
Retrieve a named logger instance.
- Parameters:
name (str) – The name of the logger (typically __name__).
- Returns:
The configured logger instance.
- Return type:
- converge.observability.logging.log_struct(logger: Logger, level: int, message: str, **kwargs: Any) None[source]¶
Log a message with structured data as extra fields.
This ensures that when JSON formatting is enabled, the kwargs appear as top-level keys in the JSON output.
- Parameters:
logger (logging.Logger) – The logger instance to use.
level (int) – The severity level of the log message.
message (str) – The primary log message.
**kwargs – Arbitrary key-value pairs to attach to the log context.
- class converge.observability.tracing.SpanExporter(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for exporting spans when a trace() context exits.
- converge.observability.tracing.get_current_trace_id() str | None[source]¶
Get the current trace ID from context.
- converge.observability.tracing.set_trace_id(trace_id: str | None = None) None[source]¶
Set the current trace ID in context. Pass None to clear.
- converge.observability.tracing.register_span_exporter(exporter: SpanExporter | None) None[source]¶
Register a span exporter for the current context. When trace() exits, export(span, duration_sec) is called.
- class converge.observability.tracing.Span(trace_id: str, span_id: str = <factory>, parent_id: str | None = None, name: str = 'operation')[source]¶
Bases:
objectRepresents a unit of work within a trace.
- converge.observability.tracing.trace(operation_name: str) Span[source]¶
Start a new trace span.
If a trace context already exists, the new span uses the existing trace ID. Otherwise, a new trace ID is generated.
- class converge.observability.metrics.MetricsCollector[source]¶
Bases:
objectCollects and aggegrates operational metrics.
- class converge.observability.replay.ReplayLog[source]¶
Bases:
objectManages the recording and playback of system events for debugging and analysis.
- record_inbound(message: Message, *, agent_id: str | None = None, transport: str | None = None) None[source]¶
Record an inbound message event.
- class converge.observability.replay.ReplayRunner(replay_log: ReplayLog)[source]¶
Bases:
objectReplays message events from ReplayLog into an inbox or callback.
- class converge.observability.coordination_metrics.CoordinationMetrics(collector: MetricsCollector)[source]¶
Bases:
object