fix maintain older usage of logfire

This commit is contained in:
Ishaan Jaff 2024-06-17 19:42:39 -07:00
parent 61ff712a08
commit c93463b535
2 changed files with 48 additions and 8 deletions

View file

@ -667,6 +667,33 @@ class Logging:
print_verbose=print_verbose, 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": if callback == "lunary":
print_verbose("reaches lunary for logging!") print_verbose("reaches lunary for logging!")
model = self.model model = self.model
@ -1446,6 +1473,25 @@ class Logging:
end_time=end_time, end_time=end_time,
print_verbose=print_verbose, 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": if callback == "sentry":
print_verbose("sending exception to sentry") print_verbose("sending exception to sentry")
if capture_exception: if capture_exception:
@ -1712,6 +1758,8 @@ def set_callbacks(callback_list, function_id=None):
weightsBiasesLogger = WeightsBiasesLogger() weightsBiasesLogger = WeightsBiasesLogger()
elif callback == "langsmith": elif callback == "langsmith":
langsmithLogger = LangsmithLogger() langsmithLogger = LangsmithLogger()
elif callback == "logfire":
logfireLogger = LogfireLogger()
elif callback == "aispend": elif callback == "aispend":
aispendLogger = AISpendLogger() aispendLogger = AISpendLogger()
elif callback == "berrispend": elif callback == "berrispend":

View file

@ -341,14 +341,6 @@ def function_setup(
global callback_list, add_breadcrumb, user_logger_fn, Logging global callback_list, add_breadcrumb, user_logger_fn, Logging
function_id = kwargs["id"] if "id" in kwargs else None 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: if len(litellm.callbacks) > 0:
for callback in litellm.callbacks: for callback in litellm.callbacks:
# check if callback is a string - e.g. "lago", "openmeter" # check if callback is a string - e.g. "lago", "openmeter"