praisonai.observability.hooks.init_observability(framework_tag, *, tags=None) and finalize_observability(_framework_tag, *, status=...) are public hooks. The orchestrator calls both automatically; custom framework adapters should use observability_session() as the recommended pattern.
Quick Start
Pair init with finalize in custom adapters
observability_session calls init_observability on entry and finalize_observability on exit. Status is derived from sys.exc_info() automatically, so success/failure is tagged correctly with no boilerplate.Alternative: manual try/except pattern
Alternative: manual try/except pattern
How It Works
init_observability(framework_tag, *, tags=None) centralizes observability initialization:
- Auto-call site: orchestrator calls
init_observability(adapter.name)immediately afterassert_framework_available(...)and beforeadapter.setup(...) - AgentOps init guard:
agentops.init(...)only fires if both (a)is_agentops_available()returns true, and (b)AGENTOPS_API_KEYis set in the env. Init is centralised here —agents_generatorno longer double-inits AgentOps (PR #2062). - Failure mode:
ImportError(no agentops) is logged atDEBUG; any other exception is logged atWARNINGand never propagated is_agentops_available()lazy function — prefer over the removed eagerAGENTOPS_AVAILABLEconstant in this module
finalize_observability(_framework_tag, *, status=...) closes observability sessions symmetrically:
- Auto-call site: built-in adapters (
praisonai_adapter,crewai_adapter, AutoGen v0.4, AG2) now wraprun()/arun()in atry: ... finally:block.finalize_observability(self.name, status=status)is called from thatfinally, withstatusderived fromsys.exc_info(). AgentOps sessions are tagged"Success"on the happy path and"Failure"whenever an exception is propagating (includingKeyboardInterrupt, LLM errors, rate limits, cancellation). - AgentOps end guard:
agentops.end_session(...)only fires ifagentopsis importable - Failure mode:
ImportErrorreturns silently; any other exception is logged atWARNINGand never propagated - Why symmetric calls matter: without
finalize_observability, AgentOps dashboard sessions stay stuck “in progress”
_init_langfuse and _init_wandb), so users may want to know the surface area.
Configuration
init_observability
| Parameter | Type | Default | Description |
|---|---|---|---|
framework_tag | str | required | Primary tag (e.g. "crewai", "autogen_v4"). Becomes the first entry in default_tags passed to agentops.init. |
tags | list[str] | None | None | Extra tags appended after framework_tag. |
finalize_observability
| Parameter | Type | Default | Description |
|---|---|---|---|
_framework_tag | str | required | Framework name for context (reserved for future observability providers — currently unused, but pass framework_tag for forward-compat). |
status | str (keyword-only) | "Success" | Session status passed to agentops.end_session(...). Conventional values: "Success", "Failure". |
observability_session
| Parameter | Type | Default | Description |
|---|---|---|---|
framework_tag | str | required | Framework tag passed to init_observability and finalize_observability. |
tags | list[str] | None | None | Extra tags forwarded to init_observability. |
ContextManager[None]). Status is auto-derived from sys.exc_info() — no status kwarg needed.
discover_observability_sinks
| Signature | Returns | Description |
|---|---|---|
() -> list[Callable] | List of factory callables | Returns entry-point-registered sink factories. Lazy + best-effort: broken plugins are logged at DEBUG and never break a run. |
Third-party sink plugins
Third-party packages can register an observability sink factory under thepraisonai.observability_sinks entry-point group. PraisonAI discovers them lazily via discover_observability_sinks() — broken plugins are logged at DEBUG and never break a run.
Register a sink (plugin authors)
TraceSinkProtocol.
Discover registered sinks
Best Practices
Use observability_session for custom adapters
Use observability_session for custom adapters
observability_session is the recommended pattern for custom adapters. It guarantees finalize_observability always runs — on success and on any failure — with the correct status derived from sys.exc_info(). This prevents AgentOps/other sessions from being orphaned in an “in progress” state on error, KeyboardInterrupt, or rate-limit paths.Status convention
Status convention
Use
status="Success" for the happy path and status="Failure" in exception cases. The string is passed verbatim to agentops.end_session(...); future providers may map other values. When using observability_session, status is derived automatically.Don't import agentops directly
Don't import agentops directly
Don’t import
agentops at the top of your adapter — gate it behind is_agentops_available() or rely on the hook to no-op silently:Future-proof for new providers
Future-proof for new providers
New providers (Langfuse, W&B, etc.) will be added inside
_init_<provider> helpers in praisonai/observability/hooks.py — calling init_observability(...) will automatically pick them up; you don’t need to update adapter code:Related
AgentOps
AgentOps integration documentation
Framework Adapter Plugins
How to create custom framework adapters
Custom Tracing
ContextTraceSink protocol and third-party sink plugins
Gateway Tracing Hook
Emit OpenTelemetry spans across each gateway pipeline stage

