Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:BerriAI Litellm Logging Callback Manager

From Leeroopedia
Knowledge Sources Domains Last Updated
[[1]] Observability, Callback Management 2026-02-15

Overview

Concrete tool for registering and managing observability callbacks provided by the LoggingCallbackManager class in LiteLLM.

Description

The LoggingCallbackManager is a centralized class that controls the addition and removal of callbacks across all of LiteLLM's callback lists (litellm.success_callback, litellm.failure_callback, litellm._async_success_callback, litellm._async_failure_callback, litellm.callbacks, litellm.input_callback, and litellm.service_callback).

Its primary goals are:

  • Prevent adding duplicate callbacks to any list.
  • Enforce a MAX_CALLBACKS limit to protect against unbounded growth.
  • Handle three callback types uniformly: string identifiers, CustomLogger instances, and plain callables.
  • Provide cleanup methods for removing callbacks by object identity or by type.

Usage

Use the LoggingCallbackManager when:

  • Setting litellm.success_callback = ["langfuse", "datadog"] programmatically.
  • Adding custom logger objects to the callback pipeline.
  • Cleaning up callbacks when a router instance is destroyed.
  • Resetting all callbacks during testing or reconfiguration.

Code Reference

Source Location

litellm/litellm_core_utils/logging_callback_manager.py (lines 1-478)

Signature

class LoggingCallbackManager:
    def add_litellm_input_callback(self, callback: Union[CustomLogger, str]) -> None: ...
    def add_litellm_service_callback(self, callback: Union[CustomLogger, str, Callable]) -> None: ...
    def add_litellm_callback(self, callback: Union[CustomLogger, str, Callable]) -> None: ...
    def add_litellm_success_callback(self, callback: Union[CustomLogger, str, Callable]) -> None: ...
    def add_litellm_failure_callback(self, callback: Union[CustomLogger, str, Callable]) -> None: ...
    def add_litellm_async_success_callback(self, callback: Union[CustomLogger, Callable, str]) -> None: ...
    def add_litellm_async_failure_callback(self, callback: Union[CustomLogger, Callable, str]) -> None: ...
    def remove_callback_from_list_by_object(self, callback_list, obj, require_self=True) -> None: ...
    def remove_callbacks_by_type(self, callback_list, callback_type) -> None: ...
    def _safe_add_callback_to_list(self, callback, parent_list) -> None: ...
    def _reset_all_callbacks(self) -> None: ...
    def _get_all_callbacks(self) -> List[Union[CustomLogger, Callable, str]]: ...

Import

from litellm.litellm_core_utils.logging_callback_manager import LoggingCallbackManager
# Typically accessed via the singleton:
import litellm
litellm.logging_callback_manager  # LoggingCallbackManager instance

I/O Contract

Inputs

Parameter Type Required Description
callback Union[CustomLogger, str, Callable] Yes The callback to register. Strings are resolved to built-in integration names; CustomLogger subclasses are compared by computed key; callables are compared by identity.
parent_list List[Union[CustomLogger, Callable, str]] Yes (internal) The target callback list (e.g., litellm.success_callback).

Outputs

Output Type Description
(side effect) mutation of litellm.*_callback lists The callback is appended to the appropriate list if not already present and the list has not reached MAX_CALLBACKS.

Usage Examples

Registering String-Based Callbacks

import litellm

# Register success callbacks by name
litellm.logging_callback_manager.add_litellm_success_callback("langfuse")
litellm.logging_callback_manager.add_litellm_success_callback("datadog")

# Duplicate is silently ignored
litellm.logging_callback_manager.add_litellm_success_callback("langfuse")

# litellm.success_callback == ["langfuse", "datadog"]

Registering a CustomLogger Instance

import litellm
from litellm.integrations.langsmith import LangsmithLogger

logger = LangsmithLogger(langsmith_api_key="sk-...", langsmith_project="my-project")
litellm.logging_callback_manager.add_litellm_success_callback(logger)

Removing Callbacks by Object

import litellm

# Remove all callbacks that are bound methods of a specific router instance
litellm.logging_callback_manager.remove_callback_from_list_by_object(
    callback_list=litellm.success_callback,
    obj=my_router_instance,
    require_self=True,
)

Removing Callbacks by Type

import litellm
from litellm.integrations.opentelemetry import OpenTelemetry

# Remove all OpenTelemetry callbacks
litellm.logging_callback_manager.remove_callbacks_by_type(
    litellm.callbacks, OpenTelemetry
)

Resetting All Callbacks

import litellm

# Clear all callback lists (useful in tests)
litellm.logging_callback_manager._reset_all_callbacks()

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment