diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index aceb834f8..ee3e4bfbb 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -667,6 +667,33 @@ class Logging: print_verbose=print_verbose, ) + if callback == "logfire": + global logfireLogger + verbose_logger.debug("reaches logfire for success logging!") + kwargs = {} + for k, v in self.model_call_details.items(): + if ( + k != "original_response" + ): # copy.deepcopy raises errors as this could be a coroutine + kwargs[k] = v + + # this only logs streaming once, complete_streaming_response exists i.e when stream ends + if self.stream: + if "complete_streaming_response" not in kwargs: + continue + else: + print_verbose("reaches logfire for streaming logging!") + result = kwargs["complete_streaming_response"] + + logfireLogger.log_event( + kwargs=self.model_call_details, + response_obj=result, + start_time=start_time, + end_time=end_time, + print_verbose=print_verbose, + level=LogfireLevel.INFO.value, + ) + if callback == "lunary": print_verbose("reaches lunary for logging!") model = self.model @@ -1446,6 +1473,25 @@ class Logging: end_time=end_time, print_verbose=print_verbose, ) + + if callback == "logfire": + verbose_logger.debug("reaches logfire for failure logging!") + kwargs = {} + for k, v in self.model_call_details.items(): + if ( + k != "original_response" + ): # copy.deepcopy raises errors as this could be a coroutine + kwargs[k] = v + kwargs["exception"] = exception + + logfireLogger.log_event( + kwargs=kwargs, + response_obj=result, + start_time=start_time, + end_time=end_time, + level=LogfireLevel.ERROR.value, + print_verbose=print_verbose, + ) if callback == "sentry": print_verbose("sending exception to sentry") if capture_exception: @@ -1712,6 +1758,8 @@ def set_callbacks(callback_list, function_id=None): weightsBiasesLogger = WeightsBiasesLogger() elif callback == "langsmith": langsmithLogger = LangsmithLogger() + elif callback == "logfire": + logfireLogger = LogfireLogger() elif callback == "aispend": aispendLogger = AISpendLogger() elif callback == "berrispend": diff --git a/litellm/utils.py b/litellm/utils.py index e84a262af..2c953b93e 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -341,14 +341,6 @@ def function_setup( global callback_list, add_breadcrumb, user_logger_fn, Logging function_id = kwargs["id"] if "id" in kwargs else None - # Note: maintain backwards compatibility with logfire. some users use litellm.success_callback=["logfire"] - if ( - litellm.success_callback is not None - and "logfire" in litellm.success_callback - ): - litellm.success_callback.remove("logfire") - litellm.callbacks.append("logfire") - if len(litellm.callbacks) > 0: for callback in litellm.callbacks: # check if callback is a string - e.g. "lago", "openmeter"