Skip to content

API Reference parrot.observability.bootstrap

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.observability.bootstrap

View source

ensure_observability_bootstrapped — env-driven, idempotent auto-boot.

Invoked on every EventEmitterMixin._init_events() — i.e. on each bot/client/ tool construction — through the injectable bootstrap hook that parrot.core.events.lifecycle installs via navigator_eventbus.lifecycle.mixin.set_bootstrap_hook (FEAT-725). This function is idempotent, which that hook contract requires: the first call does the work, every later call returns on the _BOOTSTRAPPED check.

Idempotent in the failure case too (FEAT-725 / issue:bd94e0afa8e6): a durable fan-out misconfiguration keeps raising on every call — it is a startup error, not a warning — but setup_event_fanout() is attempted exactly once and the local observability layer is still brought up. The cached exception is re-raised from the fast path.

When OBSERVABILITY_ENABLED=true, it activates the usage-recording layer selected by OBSERVABILITY_BACKEND WITHOUT the user writing any code:

  • logging (default when enabled and backend unset): structured per-call cost logs — zero infra, no OTel SDK import.
  • prometheus: lazy prometheus_client exposition.
  • otel: delegates to setup_telemetry (full OTLP traces + metrics).

FEAT-462: OBSERVABILITY_OPENLIT_RECORDER=true additively enables OpenLitUsageRecorder on top of the logging/prometheus path (via build_recorders_from_config) — pushing usage as GenAI SemConv OTel spans to an OpenLIT endpoint without requiring the otel backend.

Idempotent and near-zero cost when disabled: the very first line is a boolean check; after the first construction the env is never re-read.

Function ensure_observability_bootstrapped

Activate env-driven observability exactly once. Safe to call repeatedly.

No-op (after recording the decision) when OBSERVABILITY_ENABLED is not truthy. A failure of the local observability layer is logged at ERROR and swallowed, so it can never break bot/client construction.

ensure_observability_bootstrapped() -> None

Raises:

  • Exception — whatever setup_event_fanout() raises. Invalid durable fan-out configuration is deliberately a startup error, so it is logged at ERROR and re-raised on this and every later call. The diagnosis happens once (FEAT-725 / issue:bd94e0afa8e6): the exception is cached, setup_event_fanout() is never retried, _do_bootstrap() still runs so local observability is not collateral damage, and _BOOTSTRAPPED is set. The ERROR record matters because the EventEmitterMixin hook site that calls this swallows a raising hook at DEBUG.

Attribute logger

Function reset_bootstrap_for_tests

Test-only: reset module state so a fresh bootstrap can run.

reset_bootstrap_for_tests() -> None

Function shutdown_observability

Flush and tear down every active observability path. Idempotent + defensive.

Aggregates every shutdown surface so callers need not know which backend is active: the OTel path (shutdown_telemetry) and the lightweight logging/prometheus/openlit-recorder path (shutdown_usage_recording). Safe to call when observability was never started; never raises.

shutdown_observability() -> None

Function shutdown_usage_recording

Unsubscribe the usage subscriber and close recorders. Idempotent.

Only affects the lightweight (logging/prometheus) path. The OTel path is torn down via shutdown_telemetry.

shutdown_usage_recording() -> None

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally