Skip to content

API Reference parrot.observability.recorders.subscriber

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

parrot.observability.recorders.subscriber

View source

UsageRecordingSubscriber — turns LLM-call events into UsageRecords + fan-out.

This is the bridge between the FEAT-176 lifecycle event system and the pluggable recorder backends. It subscribes to AfterClientCallEvent on the global registry (the same surface the OTel MetricsSubscriber uses), computes cost via the shared CostCalculator, builds a normalized UsageRecord, and fans it out to every configured AbstractLogger.

It implements the EventProvider protocol (synchronous register).

Alias AbstractLogger

Re-exported from parrot.observability.recorders.base.AbstractLogger.

Alias AfterClientCallEvent

Re-exported from parrot.core.events.lifecycle.events.AfterClientCallEvent.

Alias ClientCallFailedEvent

Re-exported from parrot.core.events.lifecycle.events.ClientCallFailedEvent.

Alias CostCalculator

Re-exported from parrot.observability.cost.calculator.CostCalculator.

Alias EventRegistry

Re-exported from parrot.core.events.lifecycle.EventRegistry.

Alias UsageRecord

Re-exported from parrot.observability.recorders.models.UsageRecord.

Class UsageRecordingSubscriber

Build UsageRecords from LLM-call events and fan out to recorders.

Parameter Type Default Description
recorders 'list[AbstractLogger]' The pluggable backends to forward each record to.
cost_calculator 'Optional[CostCalculator]' None Optional CostCalculator; when provided, the per-call and cumulative USD cost are computed.
service_name str 'ai-parrot' service.name stamped on each record.

Attributes:

Attribute Type Description
recorders 'list[AbstractLogger]' The configured recorder backends.

Method UsageRecordingSubscriber.register

Subscribe the usage handler to registry.

register(registry: 'EventRegistry') -> None

Parameter Type Default Description
registry 'EventRegistry' The EventRegistry (typically the global registry) to attach to.

Method UsageRecordingSubscriber.aclose

Close all recorders (flush stateful backends).

aclose() -> None

Alias current_component

Re-exported from parrot.observability.context.current_component.

Alias current_run_id

Re-exported from parrot.observability.context.current_run_id.

Alias current_seat

Re-exported from parrot.observability.context.current_seat.

Alias current_usage_attribution

Re-exported from parrot.observability.context.current_usage_attribution.

Attribute logger

Alias resolve_gen_ai_system

Re-exported from parrot.observability.attributes.resolve_gen_ai_system.

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